-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
320 lines (256 loc) · 13.3 KB
/
CMakeLists.txt
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#-----------------------------------------------------------------------------
# This is the root RTToolbox CMakeList file.
#-----------------------------------------------------------------------------
PROJECT(RTToolbox)
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
# RTToolbox version number.
SET(RTToolbox_VERSION_MAJOR "5")
SET(RTToolbox_VERSION_MINOR "1")
SET(RTToolbox_VERSION_PATCH "0")
# Version string should not include patch level. The major.minor is
# enough to distinguish available features of the toolbox.
SET(RTToolbox_VERSION_STRING "${RTToolbox_VERSION_MAJOR}.${RTToolbox_VERSION_MINOR}")
SET(RTToolbox_FULL_VERSION_STRING "${RTToolbox_VERSION_MAJOR}.${RTToolbox_VERSION_MINOR}.${RTToolbox_VERSION_PATCH}")
SET(RTToolbox_PREFIX "RTTB")
# default build type
SET(CMAKE_BUILD_TYPE Release)
MARK_AS_ADVANCED(BUILD_SHARED_LIBS)
IF (WIN32)
IF (MSVC_VERSION LESS 1800)
MESSAGE(FATAL_ERROR "RTToolbox requires at least Visual Studio 2013.")
ELSEIF (MSVC_VERSION GREATER_EQUAL 1910)
IF (${CMAKE_VERSION} VERSION_LESS "3.10.3")
MESSAGE(AUTHOR_WARNING "Please use CMake version 3.10.3 or newer for Visual Studio 2017 as new boost versions are not recognized using old CMake versions.")
ENDIF()
ENDIF()
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
ELSE (WIN32)
IF (CMAKE_COMPILER_IS_GNUCC)
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.3)
MESSAGE(AUTHOR_WARNING "RTToolbox was tested with GCC 5 and GCC 7 only. You are using GCC " ${CMAKE_CXX_COMPILER_VERSION} ". You might need to change some code in order to compile RT Toolbox.")
ENDIF()
ELSE()
MESSAGE(AUTHOR_WARNING "RTToolbox was only tested with GCC. This compiler might not work.")
ENDIF()
ENDIF(WIN32)
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#-----------------------------------------------------------------------------
include(cmake/rttbMacroCreateModuleConf.cmake)
include(cmake/rttbMacroCreateApplication.cmake)
include(cmake/rttbFunctionCreateModule.cmake)
include(cmake/rttbFunctionCheckModuleDependencies.cmake)
include(cmake/rttbFunctionUseModules.cmake)
include(cmake/rttbFunctionOrganizeSources.cmake)
include(cmake/rttbMacroCreateTestModule.cmake)
include(cmake/rttbMacroCreateApplicationTests.cmake)
#-----------------------------------------------------------------------------
# Basis config RTTB module infrastructure
#-----------------------------------------------------------------------------
set(RTTB_MODULES_CONF_DIR ${RTToolbox_BINARY_DIR}/modulesConf CACHE INTERNAL "Modules Conf")
set(RTTB_MODULES_PACKAGE_DEPENDS_DIR ${RTToolbox_SOURCE_DIR}/cmake/PackageDepends)
set(MODULES_PACKAGE_DEPENDS_DIRS ${RTTB_MODULES_PACKAGE_DEPENDS_DIR})
#-----------------------------------------------------------------------------
# Testing setup
# Configure Dart testing support. This should be done before any
# MESSAGE(FATAL_ERROR ...) commands are invoked.
#-----------------------------------------------------------------------------
#build no tests as default
OPTION(BUILD_TESTING "build tests" OFF)
IF(BUILD_TESTING)
SET(CTEST_NEW_FORMAT 1)
INCLUDE(CTest)
ENABLE_TESTING()
CONFIGURE_FILE(${RTToolbox_SOURCE_DIR}/cmake/RemoveTemporaryFiles.cmake.in
${RTToolbox_BINARY_DIR}/cmake/RemoveTemporaryFiles.cmake @ONLY IMMEDIATE)
CONFIGURE_FILE(${RTToolbox_SOURCE_DIR}/cmake/rttbSampleBuildTest.cmake.in
${RTToolbox_BINARY_DIR}/cmake/rttbSampleBuildTest.cmake @ONLY)
CONFIGURE_FILE(${RTToolbox_SOURCE_DIR}/cmake/CTestCustom.ctest.in
${RTToolbox_BINARY_DIR}/cmake/CTestCustom.ctest @ONLY)
FILE(WRITE ${RTToolbox_BINARY_DIR}/CTestCustom.cmake
"INCLUDE(\"${RTToolbox_BINARY_DIR}/cmake/CTestCustom.ctest\")\n")
SET(BUILDNAME "${BUILDNAME}" CACHE STRING "Name of build on the dashboard")
MARK_AS_ADVANCED(BUILDNAME)
ENDIF(BUILD_TESTING)
#-----------------------------------------------------------------------------
# Output directories.
#-----------------------------------------------------------------------------
IF(NOT LIBRARY_OUTPUT_PATH)
SET (LIBRARY_OUTPUT_PATH ${RTToolbox_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
ENDIF(NOT LIBRARY_OUTPUT_PATH)
IF(NOT EXECUTABLE_OUTPUT_PATH)
SET (EXECUTABLE_OUTPUT_PATH ${RTToolbox_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
ENDIF(NOT EXECUTABLE_OUTPUT_PATH)
MARK_AS_ADVANCED(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
SET(RTToolbox_LIBRARY_PATH "${LIBRARY_OUTPUT_PATH}")
SET(RTToolbox_EXECUTABLE_PATH "${EXECUTABLE_OUTPUT_PATH}")
#-----------------------------------------------------------------------------
# Find Doxygen.
#-----------------------------------------------------------------------------
FIND_PROGRAM(DOXYGEN_EXECUTABLE "doxygen")
#-----------------------------------------------------------------------------
# Installation vars.
# RTToolbox_INSTALL_BIN_DIR - binary dir (executables)
# RTToolbox_INSTALL_LIB_DIR - library dir (libs)
# RTToolbox_INSTALL_INCLUDE_DIR - include dir (headers)
# RTToolbox_INSTALL_NO_DEVELOPMENT - do not install development files
# RTToolbox_INSTALL_NO_RUNTIME - do not install runtime files
# RTToolbox_INSTALL_NO_DOCUMENTATION - do not install documentation files
#-----------------------------------------------------------------------------
SET(RTTOOLBOX_INSTALL_VERSION_PATH "RTTB-${RTToolbox_VERSION_MAJOR}.${RTToolbox_VERSION_MINOR}")
IF(NOT RTTOOLBOX_INSTALL_BIN_DIR)
SET(RTTOOLBOX_INSTALL_BIN_DIR "bin")
ENDIF(NOT RTTOOLBOX_INSTALL_BIN_DIR)
IF(NOT RTTOOLBOX_INSTALL_LIB_DIR)
SET(RTTOOLBOX_INSTALL_LIB_DIR "lib")
ENDIF(NOT RTTOOLBOX_INSTALL_LIB_DIR)
IF(NOT RTTOOLBOX_INSTALL_INCLUDE_DIR)
SET(RTTOOLBOX_INSTALL_INCLUDE_DIR "include/${RTTOOLBOX_INSTALL_VERSION_PATH}")
ENDIF(NOT RTTOOLBOX_INSTALL_INCLUDE_DIR)
IF(NOT RTTOOLBOX_INSTALL_PACKAGE_DIR)
SET(RTTOOLBOX_INSTALL_PACKAGE_DIR "${RTTOOLBOX_INSTALL_LIB_DIR}/cmake/${RTTOOLBOX_INSTALL_VERSION_PATH}")
ENDIF(NOT RTTOOLBOX_INSTALL_PACKAGE_DIR)
IF(NOT RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
SET(RTTOOLBOX_INSTALL_NO_DEVELOPMENT 0)
ENDIF(NOT RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
IF(NOT RTTOOLBOX_INSTALL_NO_RUNTIME)
SET(RTTOOLBOX_INSTALL_NO_RUNTIME 0)
ENDIF(NOT RTTOOLBOX_INSTALL_NO_RUNTIME)
IF(NOT RTTOOLBOX_INSTALL_NO_DOCUMENTATION)
SET(RTTOOLBOX_INSTALL_NO_DOCUMENTATION 0)
ENDIF(NOT RTTOOLBOX_INSTALL_NO_DOCUMENTATION)
SET(RTTOOLBOX_INSTALL_NO_LIBRARIES)
IF(RTTOOLBOX_BUILD_SHARED_LIBS)
IF(RTTOOLBOX_INSTALL_NO_RUNTIME AND RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
SET(RTTOOLBOX_INSTALL_NO_LIBRARIES 1)
ENDIF(RTTOOLBOX_INSTALL_NO_RUNTIME AND RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
ELSE(RTTOOLBOX_BUILD_SHARED_LIBS)
IF(RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
SET(RTTOOLBOX_INSTALL_NO_LIBRARIES 1)
ENDIF(RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
ENDIF(RTTOOLBOX_BUILD_SHARED_LIBS)
# set RTToolbox_DIR so it can be used by subprojects
SET(RTToolbox_DIR "${CMAKE_BINARY_DIR}" CACHE INTERNAL "RTToolbox dir to be used by subprojects")
#-----------------------------------------------------------------------------
# DCMTK MT-Flag treat
#-----------------------------------------------------------------------------
option(RTTB_DCMTK_COMPLIANCE_ENFORCE_MT "This enforces the whole RTToolbox to be compiled with /MT,/MTd to be compliant with DCMTK" OFF)
string(FIND ${CMAKE_GENERATOR} "Visual Studio" RTTB_VS_USED)
if(RTTB_DCMTK_COMPLIANCE_ENFORCE_MT AND RTTB_VS_USED EQUAL 0)
message(STATUS "Enforce DCMTK compliance: /MT and /MTd flags are used")
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
message(STATUS "CMAKE_C_FLAGS_DEBUG set to: ${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
message(STATUS "CMAKE_C_FLAGS_RELEASE set to: ${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_C_FLAGS_MINSIZEREL set to: ${CMAKE_C_FLAGS_MINSIZEREL}")
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO})
message(STATUS "CMAKE_C_FLAGS_RELWITHDEBINFO set to: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
message(STATUS "CMAKE_CXX_FLAGS_DEBUG set to: ${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
message(STATUS "CMAKE_CXX_FLAGS_RELEASE set to: ${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
message(STATUS "CMAKE_CXX_FLAGS_MINSIZEREL set to: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO set to: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()
#-----------------------------------------------------------------------------
# Advanced RTToolbox configuration
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# RTToolbox build configuration options.
IF (NOT RTTB_CXX_STANDARD)
set(RTTB_CXX_STANDARD 11)
ENDIF (NOT RTTB_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${RTTB_CXX_STANDARD} CACHE STRING "")
set(CMAKE_CXX_STANDARD_REQUIRED 1)
OPTION(CMAKE_CXX_EXTENSIONS "" ON)
MARK_AS_ADVANCED(CMAKE_CXX_STANDARD CMAKE_CXX_STANDARD_REQUIRED CMAKE_CXX_EXTENSIONS)
IF (WIN32)
OPTION(BUILD_SHARED_LIBS "Build RTToolbox with shared libraries." OFF)
ELSE (WIN32)
OPTION(BUILD_SHARED_LIBS "Build RTToolbox with shared libraries." ON)
ENDIF (WIN32)
IF(NOT BUILD_SHARED_LIBS)
IF(UNIX)
MESSAGE(FATAL_ERROR "RTToolbox currently does not support a static build on unix like systems. We are working on that...")
ENDIF(UNIX)
ENDIF(NOT BUILD_SHARED_LIBS)
SET(RTTB_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
#Raise warning level (MSVC has W3 default warning level)
IF (WIN32)
IF(NOT BUILD_SHARED_LIBS)
set(CMAKE_CXX_FLAGS "/W4 /EHsc")
ENDIF()
ELSE()
IF (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "-Wall")
ENDIF()
ENDIF()
IF (MSVC_VERSION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
ENDIF()
IF(NOT RTToolbox_NO_LIBRARY_VERSION)
# This setting of SOVERSION assumes that any API change
# will increment either the minor or major version number of RTToolbox.
SET(RTToolbox_LIBRARY_PROPERTIES
VERSION "${RTToolbox_VERSION_MAJOR}.${RTToolbox_VERSION_MINOR}.${RTToolbox_VERSION_PATCH}"
SOVERSION "${RTToolbox_VERSION_MAJOR}.${RTToolbox_VERSION_MINOR}"
)
ENDIF(NOT RTToolbox_NO_LIBRARY_VERSION)
#-----------------------------------------------------------------------------
# Configure files with settings for use by the build.
#
#-----------------------------------------------------------------------------
CONFIGURE_FILE(${RTToolbox_SOURCE_DIR}/RTToolboxConfigure.h.in
${RTToolbox_BINARY_DIR}/RTToolboxConfigure.h)
IF(NOT RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
INSTALL(FILES ${RTToolbox_BINARY_DIR}/RTToolboxConfigure.h
DESTINATION ${RTTOOLBOX_INSTALL_INCLUDE_DIR}
COMPONENT Development)
ENDIF(NOT RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
#-----------------------------------------------------------------------------
# The entire RTToolbox tree should use the same include path
#-----------------------------------------------------------------------------
#Default include dir. Others dirs will be defined by activated subprojects
INCLUDE_DIRECTORIES(${RTToolbox_BINARY_DIR})
LINK_DIRECTORIES(${LIBARY_OUTPUT_PATH})
#-----------------------------------------------------------------------------
# Dispatch the build into the proper subdirectories.
#-----------------------------------------------------------------------------
OPTION(BUILD_All_Modules "All modules will be built" OFF)
OPTION(BUILD_Apps "Determine if the CLI applications will be generated." OFF)
MESSAGE (STATUS "generating Project RTToolbox")
ADD_SUBDIRECTORY (code)
IF (BUILD_Apps)
ADD_SUBDIRECTORY (apps)
ENDIF()
IF (BUILD_TESTING)
ADD_SUBDIRECTORY (testing)
ENDIF (BUILD_TESTING)
ADD_SUBDIRECTORY (documentation)
#-----------------------------------------------------------------------------
# Help other projects use RTToolbox.
#-----------------------------------------------------------------------------
EXPORT(PACKAGE RTToolbox)
# ---------------- Export targets -----------------
SET(RTToolbox_TARGETS_FILE "${RTToolbox_BINARY_DIR}/RTToolboxTargets.cmake")
FILE(WRITE ${RTToolbox_TARGETS_FILE} "# Generated by CMake, do not edit!")
set(targets_to_export)
get_property(module_targets GLOBAL PROPERTY RTTB_MODULE_TARGETS)
if(module_targets)
list(APPEND targets_to_export ${module_targets})
endif()
export(TARGETS ${targets_to_export} APPEND
FILE ${RTToolbox_TARGETS_FILE})
# Create the RTToolboxConfig.cmake file containing the RTToolbox configuration.
INCLUDE (${RTToolbox_SOURCE_DIR}/rttbGenerateRTToolboxConfig.cmake)
IF(NOT RTTOOLBOX_INSTALL_NO_DEVELOPMENT)
INSTALL(FILES
${RTToolbox_BINARY_DIR}/RTToolboxConfig.cmake
DESTINATION ${RTTOOLBOX_INSTALL_PACKAGE_DIR}
COMPONENT Development
)
ENDIF(NOT RTTOOLBOX_INSTALL_NO_DEVELOPMENT)