summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 3021c43a17138da195dd2d09fabf2919ca9bc620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
cmake_minimum_required(VERSION 2.8.12.2)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

project(ouroboros C)

include(GitVersionGen)
git_version_gen()

include(GNUInstallDirs)

set(PACKAGE_NAME        "${CMAKE_PROJECT_NAME}")
set(PACKAGE_DESCRIPTION "The Ouroboros prototype")
set(PACKAGE_URL         "http://ouroboros.ilabt.imec.be")
set(PACKAGE_BUGREPORT   "http://ouroboros.ilabt.imec.be/bugzilla/")
set(PACKAGE_VERSION     "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")

if (NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release" CACHE STRING
    "Build type (Release, Debug, DebugASan, DebugTSan, DebugLSan)" FORCE)
endif()

if (NOT APPLE AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX "/" CACHE STRING "Installation Prefix" FORCE)
endif ()

if (APPLE)
  set(CMAKE_MACOSX_RPATH 1)
endif()

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
  "${CMAKE_INSTALL_PREFIX}/usr/lib" isSystemDir)
IF ("${isSystemDir}" STREQUAL "-1")
  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/usr/lib")
ENDIF ("${isSystemDir}" STREQUAL "-1")

message(STATUS "Package name is:            ${PACKAGE_NAME}")
message(STATUS "Package description is:     ${PACKAGE_DESCRIPTION}")
message(STATUS "Package version is:         ${PACKAGE_VERSION}")
message(STATUS "Package URL is:             ${PACKAGE_URL}")
message(STATUS "Package bug-report address: ${PACKAGE_BUGREPORT}")
message(STATUS "Package install prefix:     ${CMAKE_INSTALL_PREFIX}")

include(FindPkgConfig)

include(CompilerUtils)
test_and_set_c_compiler_flag_global(-std=c89)
test_and_set_c_compiler_flag_global(-Wall)
# -Wextra may fail on clobbered warning due to pthread_cleanup
# test_and_set_c_compiler_flag_global(-Wextra)
# explicitly add other flags in -Wextra
test_and_set_c_compiler_flag_global(-Wempty-body)
test_and_set_c_compiler_flag_global(-Wignored-qualifiers)
test_and_set_c_compiler_flag_global(-Wimplicit-fallthrough)
test_and_set_c_compiler_flag_global(-Wmissing-field-initializers)
test_and_set_c_compiler_flag_global(-Wmissing-parameter-type)
test_and_set_c_compiler_flag_global(-Wold-style-declaration)
test_and_set_c_compiler_flag_global(-Woverride-init)
test_and_set_c_compiler_flag_global(-Wsign-compare)
test_and_set_c_compiler_flag_global(-Wtype-limits)
test_and_set_c_compiler_flag_global(-Wuninitialized)
test_and_set_c_compiler_flag_global(-Wshift-negative-value)
test_and_set_c_compiler_flag_global(-Wunused-parameter)
test_and_set_c_compiler_flag_global(-Wunused-but-set-parameter)
# -Wextra parameters
test_and_set_c_compiler_flag_global(-Werror)
test_and_set_c_compiler_flag_global(-Wundef)
test_and_set_c_compiler_flag_global(-Wpointer-arith)
test_and_set_c_compiler_flag_global(-Wstrict-prototypes)
#Wswitch-default check fails on the swig-generated code
#test_and_set_c_compiler_flag_global(-Wswitch-default)
test_and_set_c_compiler_flag_global(-Wunreachable-code)
test_and_set_c_compiler_flag_global(-Wdeclaration-after-statement)
test_and_set_c_compiler_flag_global(-fmax-errors=5)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
  test_and_set_c_compiler_flag_global(-O3)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "DebugASan")
  test_and_set_c_compiler_flag_global(-fsanitize=address)
elseif (CMAKE_BUILD_TYPE STREQUAL "DebugTSan")
  test_and_set_c_compiler_flag_global(-fsanitize=thread)
elseif (CMAKE_BUILD_TYPE STREQUAL "DebugLSan")
  test_and_set_c_compiler_flag_global(-fsanitize=leak)
endif ()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ouroboros-dev.pc.in"
  "${CMAKE_CURRENT_BINARY_DIR}/ouroboros-dev.pc" @ONLY)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ouroboros-irm.pc.in"
  "${CMAKE_CURRENT_BINARY_DIR}/ouroboros-irm.pc" @ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros-dev.pc"
  DESTINATION "usr/lib/pkgconfig")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros-irm.pc"
  DESTINATION "usr/lib/pkgconfig")

if (IS_DIRECTORY "/usr/lib/systemd")
  configure_file("${CMAKE_CURRENT_SOURCE_DIR}/irmd.service.in"
    "${CMAKE_CURRENT_BINARY_DIR}/irmd.service" @ONLY)

  install(FILES "${CMAKE_CURRENT_BINARY_DIR}/irmd.service"
    DESTINATION "usr/lib/systemd/system")
endif ()

enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})

find_package(ProtobufC QUIET)
if (NOT (PROTOBUF_C_INCLUDE_DIRS AND PROTOBUF_C_LIBRARY
         AND PROTOBUF_PROTOC_C_EXECUTABLE))
  message(FATAL_ERROR "Protobuf C compiler required but not found. "
                      "Please install Google Protocol Buffers.")
endif ()
include_directories(${PROTOBUF_C_INCLUDE_DIRS})

add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(doc)

# Uninstall target
configure_file("${CMAKE_SOURCE_DIR}/cmake/CmakeUninstall.cmake.in"
  "${CMAKE_BINARY_DIR}/cmake/CmakeUninstall.cmake" IMMEDIATE @ONLY)

add_custom_target(uninstall
  COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake/CmakeUninstall.cmake)

set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE_DESCRIPTION}")
set(CPACK_PACKAGE_DESCRIPTION_FILE    "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_PACKAGE_VERSION_MAJOR       "${PACKAGE_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR       "${PACKAGE_VERSION_MINOR}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY
  "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
set(CPACK_GENERATOR                   "TGZ")
set(CPACK_SOURCE_GENERATOR            "TGZ")

include(CPack)

#include(FeatureSummary)
#print_enabled_features()