forked from MSV-Project/MSVTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
476 lines (409 loc) · 17.4 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
###########################################################################
#
# Library: MSVTK
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
cmake_minimum_required(VERSION 2.8.2)
#-----------------------------------------------------------------------------
# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
#-----------------------------------------------------------------------------
if(POLICY CMP0016)
cmake_policy(SET CMP0016 NEW)
endif()
if(POLICY CMP0017)
cmake_policy(SET CMP0017 OLD)
endif()
#-----------------------------------------------------------------------------
project(MSVTK)
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Library mode: SHARED (default) or STATIC
#
set(MSVTK_LIBRARY_MODE "SHARED")
option(BUILD_SHARED_LIBS "Build MSVTK with shared libraries." ON)
set(MSVTK_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
mark_as_advanced(BUILD_SHARED_LIBS)
#-----------------------------------------------------------------------------
# Set a default build type if none was specified
#
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
#-----------------------------------------------------------------------------
# Superbuild Option - Enabled by default
#
option(MSVTK_SUPERBUILD "Build MSVTK and the projects it depends on via SuperBuild.cmake." ON)
mark_as_advanced(MSVTK_SUPERBUILD)
#-----------------------------------------------------------------------------
# Output directories.
#
foreach(type LIBRARY RUNTIME ARCHIVE)
# Make sure the directory exists
if(DEFINED MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY
AND NOT EXISTS ${MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY})
message(FATAL_ERROR "MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY is set to a non-existing directory [${MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY}]")
endif()
if(MSVTK_SUPERBUILD)
set(output_dir ${MSVTK_BINARY_DIR}/bin)
if(NOT DEFINED MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY)
set(MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY ${MSVTK_BINARY_DIR}/MSVTK-build/bin)
endif()
else()
if(NOT DEFINED MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY)
set(output_dir ${MSVTK_BINARY_DIR}/bin)
else()
set(output_dir ${MSVTK_CMAKE_${type}_OUTPUT_DIRECTORY})
endif()
endif()
set(CMAKE_${type}_OUTPUT_DIRECTORY ${output_dir} CACHE INTERNAL "Single output directory for building all libraries.")
endforeach()
#-----------------------------------------------------------------------------
# MSVTK version number. An even minor number corresponds to releases.
#
set(MSVTK_MAJOR_VERSION 0)
set(MSVTK_MINOR_VERSION 1)
set(MSVTK_BUILD_VERSION 0)
set(MSVTK_VERSION
"${MSVTK_MAJOR_VERSION}.${MSVTK_MINOR_VERSION}.${MSVTK_BUILD_VERSION}")
# TODO Rename MSVTK_VERSION into MSVTK_VERSION_STR - MSVTK_VERSION should be hexadecimal one
# Append the library version information to the library target
# properties. A parent project may set its own properties and/or may
# block this.
if(NOT MSVTK_NO_LIBRARY_VERSION)
set(MSVTK_LIBRARY_PROPERTIES ${MSVTK_LIBRARY_PROPERTIES}
VERSION "${MSVTK_VERSION}"
SOVERSION "${MSVTK_MAJOR_VERSION}.${MSVTK_MINOR_VERSION}"
)
endif()
#-----------------------------------------------------------------------------
# Install directories, used for install rules.
#
# TODO Rename with SUBDIR suffix
if(NOT MSVTK_INSTALL_BIN_DIR)
set(MSVTK_INSTALL_BIN_DIR "bin")
endif()
if(NOT MSVTK_INSTALL_LIB_DIR)
set(MSVTK_INSTALL_LIB_DIR "lib/MSVTK-${MSVTK_MAJOR_VERSION}.${MSVTK_MINOR_VERSION}")
endif()
if(NOT MSVTK_INSTALL_INCLUDE_DIR)
set(MSVTK_INSTALL_INCLUDE_DIR "include/MSVTK-${MSVTK_MAJOR_VERSION}.${MSVTK_MINOR_VERSION}")
endif()
if(NOT MSVTK_INSTALL_DOC_DIR)
set(MSVTK_INSTALL_DOC_DIR "doc")
endif()
#-----------------------------------------------------------------------------
# Update CMake module path
# Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
#
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
"${CMAKE_CURRENT_SOURCE_DIR}/CMake"
${CMAKE_MODULE_PATH})
#-----------------------------------------------------------------------------
# Clear MSVTK_BASE_INCLUDE_DIRS, MSVTK_BASE_LIBRARIES and MSVTK_WRAPPED_LIBRARIES_PYTHONQT
#
#set(MSVTK_BASE_LIBRARIES CACHE INTERNAL "MSVTK base libraries" FORCE)
#set(MSVTK_BASE_INCLUDE_DIRS CACHE INTERNAL "MSVTK includes" FORCE)
# TODO Shouldn't be required .. was added to CTK before we rely on exported target
# Variable use in MSVTKConfig.cmake.in
set(MSVTK_LIBRARIES CACHE INTERNAL "MSVTK libraries" FORCE)
set(MSVTK_PLUGIN_LIBRARIES CACHE INTERNAL "MSVTK plugins" FORCE)
# Used by MSVTKGenerateMSVTKConfig.cmake and also used to reference script from other scripts
set(MSVTK_CMAKE_DIR ${MSVTK_SOURCE_DIR}/CMake)
set(MSVTK_CMAKE_UTILITIES_DIR ${MSVTK_SOURCE_DIR}/Utilities/CMake)
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#
#include(CMake/MSVTKMacroParseArguments.cmake)
#include(CMake/MSVTKMacroSetPaths.cmake)
#include(CMake/MSVTKMacroListFilter.cmake)
#include(CMake/MSVTKMacroBuildLib.cmake)
#include(CMake/MSVTKMacroBuildLibWrapper.cmake)
#include(CMake/MSVTKMacroBuildPlugin.cmake)
#include(CMake/MSVTKMacroBuildApp.cmake)
#include(CMake/MSVTKMacroCompilePythonScript.cmake)
#include(CMake/MSVTKMacroWrapPythonQt.cmake)
#include(CMake/MSVTKMacroSetupQt.cmake)
#include(CMake/MSVTKMacroTargetLibraries.cmake) # Import multiple macros
#include(CMake/MSVTKFunctionExtractOptionNameAndValue.cmake)
#include(CMake/MSVTKMacroValidateBuildOptions.cmake)
#include(CMake/MSVTKMacroAddMSVTKLibraryOptions.cmake)
#include(CMake/MSVTKFunctionGenerateDGraphInput.cmake)
#include(CMake/MSVTKFunctionGenerateProjectXml.cmake)
#include(CMake/MSVTKFunctionGeneratePluginManifest.cmake)
#include(CMake/MSVTKMacroGeneratePluginResourceFile.cmake)
#include(CMake/MSVTKFunctionCheckCompilerFlags.cmake)
#include(CMake/MSVTKFunctionGetIncludeDirs.cmake)
#include(CMake/MSVTKFunctionGetLibraryDirs.cmake)
#include(CMake/MSVTKFunctionGetGccVersion.cmake)
#-----------------------------------------------------------------------------
# Qt Designer Plugins
option(BUILD_QTDESIGNER_PLUGINS "Build Qt Designer plugins" OFF)
if(BUILD_QTDESIGNER_PLUGINS)
include(CMake/MSVTKMacroBuildQtDesignerPlugin.cmake)
endif()
#-----------------------------------------------------------------------------
# Testing
#
option(BUILD_TESTING "Test the project" ON)
if(BUILD_TESTING)
enable_testing()
include(CTest)
set(CPP_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
# DashBoard
configure_file(
${MSVTK_SOURCE_DIR}/CTestConfig.cmake
${MSVTK_BINARY_DIR}/CTestConfig.cmake
COPYONLY)
# Setup file for setting custom ctest vars
CONFIGURE_FILE(
CMake/CTestCustom.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
@ONLY
)
# Configuration for the CMake-generated test driver
set(CMAKE_TESTDRIVER_EXTRA_INCLUDES "
#include <stdexcept>
#if defined(WIN32)
# pragma warning(disable : 4996)
#endif")
set(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
try
{")
set(CMAKE_TESTDRIVER_AFTER_TESTMAIN "
}
catch( std::exception & excp )
{
fprintf(stderr, \"Test driver caught exception: [%s]\\n\", excp.what());
return EXIT_FAILURE;
}
catch( ... )
{
printf(\"Exception caught by the test driver\\n\");
return EXIT_FAILURE;
}")
endif()
#-----------------------------------------------------------------------------
# Documentation
#
option(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
mark_as_advanced(DOCUMENTATION_TARGET_IN_ALL)
set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
CACHE PATH "Where documentation archives should be stored")
mark_as_advanced(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
#-----------------------------------------------------------------------------
# Attempt to discover Doxygen so that DOXYGEN_EXECUTABLE is set to an appropriate default value
#
FIND_PACKAGE(Doxygen QUIET)
#-----------------------------------------------------------------------------
# Coverage
#
option(WITH_COVERAGE "Enable/Disable coverage" OFF)
#-----------------------------------------------------------------------------
# Set coverage Flags
#
if(WITH_COVERAGE)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
set(COVERAGE_CXX_FLAGS ${coverage_flags})
set(COVERAGE_C_FLAGS ${coverage_flags})
endif()
endif()
#-----------------------------------------------------------------------------
# Additional CXX/C Flags
#
set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
mark_as_advanced(ADDITIONAL_C_FLAGS)
set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
mark_as_advanced(ADDITIONAL_CXX_FLAGS)
#-----------------------------------------------------------------------------
# Set symbol visibility Flags
#
# MinGW does not export all symbols automatically, so no need to set flags
#if(CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
# set(VISIBILITY_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
#endif()
#-----------------------------------------------------------------------------
# MSVTK C/CXX Flags
#
set(MSVTK_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
set(MSVTK_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
if(CMAKE_COMPILER_IS_GNUCXX)
set(cflags "-Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -D_FORTIFY_SOURCE=2")
#MSVTKFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
#MSVTKFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
#MSVTKFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
# With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
# is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
# Doing so should allow to build package made for distribution using older linux distro.
#if(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0"))
# MSVTKFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
#endif()
if(MINGW)
# suppress warnings about auto imported symbols
set(MSVTK_CXX_FLAGS "-Wl,--enable-auto-import ${MSVTK_CXX_FLAGS}")
endif()
set(MSVTK_C_FLAGS "${cflags} ${MSVTK_C_FLAGS}")
set(MSVTK_CXX_FLAGS "${cflags} -Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${MSVTK_CXX_FLAGS}")
endif()
if(MSVC)
set(msvc_suppressed_warnings
"/wd4290" # C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
)
set(MSVTK_CXX_FLAGS "${MSVTK_CXX_FLAGS} ${msvc_suppressed_warnings}")
endif()
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
#-----------------------------------------------------------------------------
# QT
#
include(CMake/msvMacroSetupQt.cmake)
msvMacroSetupQt()
# Update MSVTK_BASE_LIBRARIES with QT libraries
#if(QT4_FOUND)
# set(MSVTK_BASE_LIBRARIES ${MSVTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "MSVTK base libraries" FORCE)
#endif()
#-----------------------------------------------------------------------------
# MSVTK Libraries - Use ON or OFF to indicate if the library should be built by default
#
#set(MSVTK_LIBS
# Core:ON
# Widgets:ON
# )
#-----------------------------------------------------------------------------
# MSVTK Plugins - Use ON or OFF to indicate if the plugin should be built by default
#
#set(MSVTK_PLUGINS
# )
#-----------------------------------------------------------------------------
# MSVTK Applications - Use ON or OFF to indicate if the application should be built by default
#
#set(MSVTK_APPLICATIONS
# )
#-----------------------------------------------------------------------------
# To make options show up in both MSVTK-SuperBuild and MSVTK regular build, let's add them
# before the SuperBuild script is included
#
# Let's mark as advanced some default properties
mark_as_advanced(CMAKE_INSTALL_PREFIX)
mark_as_advanced(DART_TESTING_TIMEOUT)
# KWStyle
option(MSVTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
#mark_as_advanced(MSVTK_USE_KWSTYLE)
#---------------------------------------------------------------------------
# Will contain a list of sub-directory without option ON or OFF
#
set(MSVTK_PLUGINS_SUBDIRS )
set(MSVTK_APPLICATIONS_SUBDIRS )
option(MSVTK_APP_ECG "ECG application to demonstrate vtkButtons" ON)
option(MSVTK_APP_VTKBUTTONS "vtkButtons application to demonstrate vtkButtons" ON)
list(APPEND MSVTK_APPLICATIONS_SUBDIRS ECG)
list(APPEND MSVTK_APPLICATIONS_SUBDIRS VTKBUTTONS)
#-----------------------------------------------------------------------------
# Prerequisites
#-----------------------------------------------------------------------------
find_package(Git)
if(NOT GIT_FOUND)
message(FATAL_ERROR "error: Install Git and try to re-configure")
endif()
#-----------------------------------------------------------------------------
# Superbuild script
#
if(MSVTK_SUPERBUILD)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/CMake/SuperBuild")
return()
endif()
#-----------------------------------------------------------------------------
# VTK
#-----------------------------------------------------------------------------
find_package(VTK REQUIRED)
#if(NOT VTK_USE_QVTK)
# message(FATAL_ERROR "error: VTK was not configured to use QT, you probably need "
# "to recompile it with VTK_USE_GUISUPPORT ON, VTK_USE_QVTK ON, "
# "DESIRED_QT_VERSION 4 and QT_QMAKE_EXECUTABLE set appropriatly. "
# "Note that Qt >= ${Slicer_REQUIRED_QT_VERSION} is *required*")
#endif()
include(${VTK_USE_FILE})
#-----------------------------------------------------------------------------
# CTK
#-----------------------------------------------------------------------------
find_package(CTK REQUIRED)
include(${CTK_USE_FILE})
#-----------------------------------------------------------------------------
# MSVTK_SUPERBUILD_BINARY_DIR
# If MSVTK_SUPERBUILD_BINARY_DIR isn't defined, it means MSVTK is *NOT* build using Superbuild.
# In that specific case, MSVTK_SUPERBUILD_BINARY_DIR should default to MSVTK_BINARY_DIR
if(NOT DEFINED MSVTK_SUPERBUILD_BINARY_DIR)
set(MSVTK_SUPERBUILD_BINARY_DIR ${MSVTK_BINARY_DIR})
endif()
#-----------------------------------------------------------------------------
# Configure files with settings
#
#CONFIGURE_FILE(${MSVTK_SOURCE_DIR}/UseMSVTK.cmake.in
# ${MSVTK_SUPERBUILD_BINARY_DIR}/UseMSVTK.cmake COPYONLY IMMEDIATE)
#-----------------------------------------------------------------------------
# Set C/CXX Flags
#
set(CMAKE_CXX_FLAGS ${MSVTK_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE)
set(CMAKE_C_FLAGS ${MSVTK_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE)
#-----------------------------------------------------------------------------
# Set the header template which defines custom export/import macros
# for shared libraries
#
set(MSVTK_EXPORT_HEADER_TEMPLATE "${MSVTK_SOURCE_DIR}/Libs/msvExport.h.in")
#-----------------------------------------------------------------------------
# Add MSVTK library subdirectories
#
add_subdirectory(Libs)
#-----------------------------------------------------------------------------
# Add MSVTK plugin subdirectories
#
foreach(plugin ${MSVTK_PLUGINS_SUBDIRS})
if(MSVTK_PLUGIN_${plugin})
add_subdirectory(Plugins/${plugin})
endif()
endforeach()
#-----------------------------------------------------------------------------
# Add MSVTK application subdirectories
#
foreach(app ${MSVTK_APPLICATIONS_SUBDIRS})
if(MSVTK_APP_${app})
add_subdirectory(Applications/${app})
endif()
endforeach()
#-----------------------------------------------------------------------------
# Add MSVTK examples subdirectories
#
add_subdirectory(Examples)
#-----------------------------------------------------------------------------
# Style Checking configuration
#
if(MSVTK_USE_KWSTYLE)
include(Utilities/KWStyle/KWStyle.cmake)
endif()
#---------------------------------------------------------------------------
# Documentation
#
add_subdirectory( Utilities/Documentation )
#-----------------------------------------------------------------------------
# The commands in this directory are intended to be executed as
# the end of the whole configuration process, as a "last step".
# This directory is typically the last SUBDIRS in the main CMakeLists.txt.
ADD_SUBDIRECTORY(Utilities/LastConfigureStep)