CMakeLists.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) Kitware Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0.txt
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. ###########################################################################
  20. cmake_minimum_required(VERSION 2.8.4)
  21. #-----------------------------------------------------------------------------
  22. # See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
  23. #
  24. set(project_policies
  25. CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
  26. CMP0002 # NEW: Logical target names must be globally unique.
  27. CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths.
  28. CMP0004 # NEW: Libraries linked may NOT have leading or trailing whitespace.
  29. CMP0005 # NEW: Preprocessor definition values are now escaped automatically.
  30. CMP0006 # NEW: Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
  31. CMP0007 # NEW: List command no longer ignores empty elements.
  32. CMP0008 # NEW: Libraries linked by full-path must have a valid library file name.
  33. CMP0009 # NEW: FILE GLOB_RECURSE calls should not follow symlinks by default.
  34. CMP0010 # NEW: Bad variable reference syntax is an error.
  35. CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
  36. CMP0012 # NEW: if() recognizes numbers and boolean constants.
  37. CMP0013 # NEW: Duplicate binary directories are not allowed.
  38. CMP0014 # NEW: Input directories must have CMakeLists.txt
  39. )
  40. foreach(policy ${project_policies})
  41. if(POLICY ${policy})
  42. cmake_policy(SET ${policy} NEW)
  43. endif()
  44. endforeach()
  45. #-----------------------------------------------------------------------------
  46. if(APPLE)
  47. # Note: By setting CMAKE_OSX_* variables before any enable_language() or project() calls,
  48. # we ensure that the bitness will be properly detected.
  49. include(${CMAKE_SOURCE_DIR}/CMake/ctkBlockSetCMakeOSXVariables.cmake)
  50. endif()
  51. #-----------------------------------------------------------------------------
  52. project(CTK)
  53. #-----------------------------------------------------------------------------
  54. #-----------------------------------------------------------------------------
  55. # Library mode: SHARED (default) or STATIC
  56. #
  57. set(CTK_LIBRARY_MODE "SHARED")
  58. option(CTK_BUILD_SHARED_LIBS "Build CTK libraries as shared module." ON)
  59. mark_as_advanced(CTK_BUILD_SHARED_LIBS)
  60. if(NOT CTK_BUILD_SHARED_LIBS)
  61. set(CTK_LIBRARY_MODE "STATIC")
  62. endif()
  63. #-----------------------------------------------------------------------------
  64. # Set a default build type if none was specified
  65. #
  66. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  67. message(STATUS "Setting build type to 'Debug' as none was specified.")
  68. set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  69. # Set the possible values of build type for cmake-gui
  70. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
  71. "MinSizeRel" "RelWithDebInfo")
  72. endif()
  73. #-----------------------------------------------------------------------------
  74. # Superbuild Option - Enabled by default
  75. #
  76. option(CTK_SUPERBUILD "Build CTK and the projects it depends on via SuperBuild.cmake." ON)
  77. mark_as_advanced(CTK_SUPERBUILD)
  78. #-----------------------------------------------------------------------------
  79. # Output directories.
  80. #
  81. foreach(type LIBRARY RUNTIME ARCHIVE)
  82. # Make sure the directory exists
  83. if(DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY
  84. AND NOT EXISTS ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  85. message(FATAL_ERROR "CTK_CMAKE_${type}_OUTPUT_DIRECTORY is set to a non-existing directory [${CTK_CMAKE_${type}_OUTPUT_DIRECTORY}]")
  86. endif()
  87. if(CTK_SUPERBUILD)
  88. set(output_dir ${CTK_BINARY_DIR}/bin)
  89. if(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  90. set(CTK_CMAKE_${type}_OUTPUT_DIRECTORY ${CTK_BINARY_DIR}/CTK-build/bin)
  91. endif()
  92. else()
  93. if(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  94. set(output_dir ${CTK_BINARY_DIR}/bin)
  95. else()
  96. set(output_dir ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  97. endif()
  98. endif()
  99. set(CMAKE_${type}_OUTPUT_DIRECTORY ${output_dir} CACHE INTERNAL "Single output directory for building all libraries.")
  100. if(NOT DEFINED CTK_PLUGIN_${type}_OUTPUT_DIRECTORY)
  101. set(CTK_PLUGIN_${type}_OUTPUT_DIRECTORY ${CMAKE_${type}_OUTPUT_DIRECTORY})
  102. endif()
  103. endforeach()
  104. #-----------------------------------------------------------------------------
  105. # CTK version number. An even minor number corresponds to releases.
  106. #
  107. set(CTK_MAJOR_VERSION 0)
  108. set(CTK_MINOR_VERSION 1)
  109. set(CTK_PATCH_VERSION 0)
  110. set(CTK_VERSION
  111. "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}")
  112. # Append the library version information to the library target
  113. # properties. A parent project may set its own properties and/or may
  114. # block this.
  115. if(NOT CTK_NO_LIBRARY_VERSION)
  116. set(CTK_LIBRARY_PROPERTIES ${CTK_LIBRARY_PROPERTIES}
  117. VERSION "${CTK_VERSION}"
  118. SOVERSION "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}"
  119. )
  120. endif()
  121. #-----------------------------------------------------------------------------
  122. # Install directories, used for install rules.
  123. #
  124. if(NOT CTK_INSTALL_BIN_DIR)
  125. set(CTK_INSTALL_BIN_DIR "bin")
  126. endif()
  127. if(NOT CTK_INSTALL_LIB_DIR)
  128. set(CTK_INSTALL_LIB_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
  129. endif()
  130. if(NOT CTK_INSTALL_INCLUDE_DIR)
  131. set(CTK_INSTALL_INCLUDE_DIR "include/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
  132. endif()
  133. if(NOT CTK_INSTALL_DOC_DIR)
  134. set(CTK_INSTALL_DOC_DIR "doc")
  135. endif()
  136. #-----------------------------------------------------------------------------
  137. # Update CMake module path
  138. # Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
  139. #
  140. set(CMAKE_MODULE_PATH
  141. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
  142. "${CMAKE_CURRENT_SOURCE_DIR}/CMake"
  143. ${CMAKE_MODULE_PATH})
  144. #-----------------------------------------------------------------------------
  145. # Clear CTK_BASE_INCLUDE_DIRS, CTK_BASE_LIBRARIES and CTK_WRAPPED_LIBRARIES_PYTHONQT
  146. #
  147. set(CTK_BASE_LIBRARIES CACHE INTERNAL "CTK base libraries" FORCE)
  148. set(CTK_BASE_INCLUDE_DIRS CACHE INTERNAL "CTK includes" FORCE)
  149. set(CTK_WRAPPED_LIBRARIES_PYTHONQT CACHE INTERNAL "CTK libraries wrapped using PythonQt" FORCE)
  150. # Variable use in CTKConfig.cmake.in
  151. set(CTK_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
  152. set(${PROJECT_NAME}_PLUGIN_LIBRARIES CACHE INTERNAL "CTK plugins" FORCE)
  153. # Used by CTKGenerateCTKConfig.cmake and also used to reference script from other scripts
  154. set(CTK_CMAKE_DIR ${CTK_SOURCE_DIR}/CMake)
  155. set(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
  156. #-----------------------------------------------------------------------------
  157. # CMake function(s) and macro(s)
  158. #
  159. include(CMake/ctkMacroParseArguments.cmake)
  160. include(CMake/ctkMacroSetPaths.cmake)
  161. include(CMake/ctkMacroListFilter.cmake)
  162. include(CMake/ctkMacroBuildLib.cmake)
  163. include(CMake/ctkMacroBuildLibWrapper.cmake)
  164. include(CMake/ctkMacroBuildPlugin.cmake)
  165. include(CMake/ctkMacroBuildApp.cmake)
  166. include(CMake/ctkMacroCompilePythonScript.cmake)
  167. include(CMake/ctkMacroWrapPythonQt.cmake)
  168. include(CMake/ctkMacroSetupQt.cmake)
  169. include(CMake/ctkMacroTargetLibraries.cmake) # Import multiple macros
  170. include(CMake/ctkFunctionExtractOptionNameAndValue.cmake)
  171. include(CMake/ctkMacroValidateBuildOptions.cmake)
  172. include(CMake/ctkMacroAddCtkLibraryOptions.cmake)
  173. include(CMake/ctkFunctionGenerateDGraphInput.cmake)
  174. include(CMake/ctkFunctionGenerateProjectXml.cmake)
  175. include(CMake/ctkFunctionGeneratePluginManifest.cmake)
  176. include(CMake/ctkMacroGeneratePluginResourceFile.cmake)
  177. include(CMake/ctkFunctionCheckCompilerFlags.cmake)
  178. include(CMake/ctkFunctionGetIncludeDirs.cmake)
  179. include(CMake/ctkFunctionGetLibraryDirs.cmake)
  180. include(CMake/ctkFunctionGetGccVersion.cmake)
  181. #-----------------------------------------------------------------------------
  182. # Qt Designer Plugins
  183. option(BUILD_QTDESIGNER_PLUGINS "Build Qt Designer plugins" ON)
  184. if(BUILD_QTDESIGNER_PLUGINS)
  185. include(CMake/ctkMacroBuildQtDesignerPlugin.cmake)
  186. endif()
  187. #-----------------------------------------------------------------------------
  188. # Testing
  189. #
  190. option(BUILD_TESTING "Test the project" ON)
  191. if(BUILD_TESTING)
  192. enable_testing()
  193. include(CTest)
  194. set(CPP_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  195. mark_as_advanced(TCL_TCLSH DART_ROOT)
  196. include(CMake/ctkMacroSimpleTest.cmake)
  197. include(CMake/ctkMacroSimpleTestWithData.cmake)
  198. # Setup file for setting custom ctest vars
  199. configure_file(
  200. CMake/CTestCustom.cmake.in
  201. ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
  202. @ONLY
  203. )
  204. # Configuration for the CMake-generated test driver
  205. set(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include <stdexcept>")
  206. set(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
  207. try
  208. {")
  209. set(CMAKE_TESTDRIVER_AFTER_TESTMAIN " }
  210. catch( std::exception & excp )
  211. {
  212. fprintf(stderr,\"%s\\n\",excp.what());
  213. return EXIT_FAILURE;
  214. }
  215. catch( ... )
  216. {
  217. printf(\"Exception caught in the test driver\\n\");
  218. return EXIT_FAILURE;
  219. }
  220. ")
  221. endif()
  222. #-----------------------------------------------------------------------------
  223. # Coverage
  224. #
  225. option(WITH_COVERAGE "Enable/Disable coverage" OFF)
  226. #-----------------------------------------------------------------------------
  227. # Documentation
  228. #
  229. option(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
  230. mark_as_advanced(DOCUMENTATION_TARGET_IN_ALL)
  231. set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  232. CACHE PATH "Where documentation archives should be stored")
  233. mark_as_advanced(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  234. #-----------------------------------------------------------------------------
  235. # Additional CXX/C Flags
  236. #
  237. set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
  238. mark_as_advanced(ADDITIONAL_C_FLAGS)
  239. set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
  240. mark_as_advanced(ADDITIONAL_CXX_FLAGS)
  241. #-----------------------------------------------------------------------------
  242. # Set symbol visibility Flags
  243. #
  244. ctkFunctionGetGccversion(${CMAKE_CXX_COMPILER} GCC_VERSION)
  245. # MinGW does not export all symbols automatically, so no need to set flags.
  246. #
  247. # With gcc < 4.5, RTTI symbols from classes declared in third-party libraries
  248. # which are not "gcc visibility aware" are marked with hidden visibility in
  249. # DSOs which include the class declaration and which are compiled with
  250. # hidden visibility. This leads to dynamic_cast and exception handling problems.
  251. # While this problem could be worked around by sandwiching the include
  252. # directives for the third-party headers between "#pragma visibility push/pop"
  253. # statements, it is generally safer to just use default visibility with
  254. # gcc < 4.5.
  255. if(CMAKE_COMPILER_IS_GNUCXX AND NOT ${GCC_VERSION} VERSION_LESS "4.5" AND NOT MINGW)
  256. set(VISIBILITY_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
  257. endif()
  258. #-----------------------------------------------------------------------------
  259. # Set coverage Flags
  260. #
  261. if(WITH_COVERAGE)
  262. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  263. set(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
  264. set(COVERAGE_CXX_FLAGS ${coverage_flags})
  265. set(COVERAGE_C_FLAGS ${coverage_flags})
  266. endif()
  267. endif()
  268. #-----------------------------------------------------------------------------
  269. # CTK C/CXX Flags
  270. #
  271. set(CTK_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
  272. set(CTK_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
  273. if(CMAKE_COMPILER_IS_GNUCXX)
  274. set(cflags "-Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -D_FORTIFY_SOURCE=2")
  275. ctkFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
  276. ctkFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
  277. # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
  278. # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
  279. # Doing so should allow to build package made for distribution using older linux distro.
  280. if(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0"))
  281. ctkFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
  282. endif()
  283. if(MINGW)
  284. # suppress warnings about auto imported symbols
  285. set(CTK_CXX_FLAGS "-Wl,--enable-auto-import ${CTK_CXX_FLAGS}")
  286. endif()
  287. set(CTK_C_FLAGS "${cflags} ${CTK_C_FLAGS}")
  288. set(CTK_CXX_FLAGS "${cflags} -Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${CTK_CXX_FLAGS}")
  289. endif()
  290. if(MSVC)
  291. set(msvc_suppressed_warnings
  292. "/wd4290" # C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  293. )
  294. set(CTK_CXX_FLAGS "${CTK_CXX_FLAGS} ${msvc_suppressed_warnings}")
  295. endif()
  296. #-----------------------------------------------------------------------------
  297. # QT
  298. #
  299. ctkMacroSetupQt()
  300. # Update CTK_BASE_LIBRARIES with QT libraries
  301. if(QT4_FOUND)
  302. set(CTK_BASE_LIBRARIES ${CTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "CTK base libraries" FORCE)
  303. endif()
  304. #-----------------------------------------------------------------------------
  305. # CTK Libraries - Use ON or OFF to indicate if the library should be built by default
  306. #
  307. set(CTK_LIBS
  308. Core:ON
  309. PluginFramework:ON
  310. Widgets:OFF
  311. DICOM/Core:OFF
  312. DICOM/Widgets:OFF
  313. ImageProcessing/ITK/Core:OFF
  314. #Messaging/Core:OFF # MessagingCore library need some love :) - Let's disable it for now :(
  315. #ModuleDescription:OFF # ModuleDescription library need some love :) - Let's disable it for now :(
  316. Scripting/Python/Core:OFF
  317. Scripting/Python/Widgets:OFF
  318. Visualization/VTK/Core:OFF
  319. Visualization/VTK/Widgets:OFF
  320. #Visualization/XIP:OFF # XIP library need some love :) - Let's disable it for now :(
  321. )
  322. #-----------------------------------------------------------------------------
  323. # CTK Plugins - Use ON or OFF to indicate if the plugin should be built by default
  324. #
  325. set(CTK_PLUGINS
  326. # Optional plug-ins implementings interfaces in PluginFramework/service/
  327. org.commontk.eventbus:OFF
  328. org.commontk.configadmin:OFF
  329. org.commontk.eventadmin:OFF
  330. org.commontk.log:OFF
  331. org.commontk.log4qt:OFF
  332. org.commontk.metatype:OFF
  333. # Plug-ins related to DICOM WG23 (Application Hosting)
  334. org.commontk.dah.core:OFF
  335. org.commontk.dah.app:OFF
  336. org.commontk.dah.host:OFF
  337. org.commontk.dah.exampleapp:OFF
  338. org.commontk.dah.examplehost:OFF
  339. # Misc
  340. org.commontk.plugingenerator.core:OFF
  341. org.commontk.plugingenerator.ui:OFF
  342. org.commontk.slicermodule:OFF
  343. )
  344. #-----------------------------------------------------------------------------
  345. # CTK Applications - Use ON or OFF to indicate if the application should be built by default
  346. #
  347. set(CTK_APPLICATIONS
  348. ctkCLIPluginExplorer:OFF
  349. ctkDICOM:OFF
  350. ctkDICOMIndexer:OFF
  351. ctkDICOMDemoSCU:OFF
  352. ctkDICOMQuery:OFF
  353. ctkDICOMRetrieve:OFF
  354. ctkDICOMQueryRetrieve:OFF
  355. ctkExampleHost:OFF
  356. ctkExampleHostedApp:OFF
  357. ctkEventBusDemo:OFF
  358. ctkPluginBrowser:OFF
  359. ctkPluginGenerator:OFF
  360. ctkDICOMObjectViewer:OFF
  361. ctkSimplePythonShell:OFF
  362. )
  363. #-----------------------------------------------------------------------------
  364. # To make options show up in both CTK-SuperBuild and CTK regular build, let's add them
  365. # before the SuperBuild script is included
  366. #
  367. # Let's mark as advanced some default properties
  368. mark_as_advanced(CMAKE_INSTALL_PREFIX)
  369. mark_as_advanced(DART_TESTING_TIMEOUT)
  370. # KWStyle
  371. option(CTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
  372. #mark_as_advanced(CTK_USE_KWSTYLE)
  373. #---------------------------------------------------------------------------
  374. # Will contain a list of sub-directory without option ON or OFF
  375. #
  376. set(CTK_LIBS_SUBDIRS )
  377. set(CTK_PLUGINS_SUBDIRS )
  378. set(CTK_APPLICATIONS_SUBDIRS )
  379. #-----------------------------------------------------------------------------
  380. # Build options associated with CTK libraries
  381. #
  382. # The following FOREACH loops are used to:
  383. # 1) Add build options associated with either libraries, plugins and applications
  384. # 2) Update either CTK_LIBS_SUBDIRS, CTK_PLUGINS_SUBDIRS or CTK_APPS_SUBDIRS variables
  385. #
  386. # For CTK libraries, if the file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake exists,
  387. # in addition to 'CTK_LIB_<DIR>/<LIBNAME>' option, the following ones
  388. # will also be available in CMake configure menu:
  389. # CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
  390. # CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)
  391. #
  392. # The file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake should look like:
  393. #
  394. # set(ctk_library_options
  395. # OPT1:OFF
  396. # OPT2:ON
  397. # )
  398. # Build options associated with CTK libraries
  399. set(ctk_lib_options_list) # This list will be updated in ctkFunctionExtractOptionNameAndValue
  400. foreach(lib ${CTK_LIBS})
  401. ctkFunctionExtractOptionNameAndValue(${lib} lib_name lib_value)
  402. option(CTK_LIB_${lib_name} "Enable ${lib_name} Library." ${lib_value})
  403. if(CTK_LIB_${lib_name})
  404. ctkMacroAddCtkLibraryOptions(${lib_name})
  405. endif()
  406. list(APPEND CTK_LIBS_SUBDIRS "${lib_name}")
  407. endforeach()
  408. # Build options associated with CTK plugins
  409. foreach(plugin ${CTK_PLUGINS})
  410. ctkFunctionExtractOptionNameAndValue(${plugin} plugin_name plugin_value)
  411. option(CTK_PLUGIN_${plugin_name} "Build ${plugin_name} Plugin." ${plugin_value})
  412. list(APPEND CTK_PLUGINS_SUBDIRS "${plugin_name}")
  413. endforeach()
  414. # Build options associated with CTK applications
  415. foreach(app ${CTK_APPLICATIONS})
  416. ctkFunctionExtractOptionNameAndValue(${app} app_name app_value)
  417. option(CTK_APP_${app_name} "Build ${app_name} Application." ${app_value})
  418. list(APPEND CTK_APPLICATIONS_SUBDIRS "${app_name}")
  419. endforeach()
  420. #-----------------------------------------------------------------------------
  421. # Generate target_directories list - List of directory corresponding to the different
  422. # libraries, plugins and applications associated with the corresponding option name.
  423. #
  424. # Create list of directories corresponding to the enabled targets
  425. set(target_directories)
  426. foreach(lib ${CTK_LIBS_SUBDIRS})
  427. set(option_name CTK_LIB_${lib})
  428. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}^^${option_name}")
  429. endforeach()
  430. foreach(plugin ${CTK_PLUGINS_SUBDIRS})
  431. set(option_name CTK_PLUGIN_${plugin})
  432. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/${plugin}^^${option_name}")
  433. endforeach()
  434. foreach(app ${CTK_APPLICATIONS_SUBDIRS})
  435. set(option_name CTK_APP_${app})
  436. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${app}^^${option_name}")
  437. endforeach()
  438. #message(STATUS target_directories:${target_directories})
  439. #-----------------------------------------------------------------------------
  440. # Compile DGraph - An application allowing to check for cycle in DAG and also obtain the
  441. # topological order.
  442. try_compile(RESULT_VAR ${CTK_BINARY_DIR}/Utilities/DGraph ${CTK_SOURCE_DIR}/Utilities/DGraph
  443. DGraph
  444. CMAKE_FLAGS
  445. -DQT_QMAKE_EXECUTABLE:FILE=${QT_QMAKE_EXECUTABLE}
  446. -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
  447. -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
  448. -DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT}
  449. -DCMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
  450. OUTPUT_VARIABLE output)
  451. if(NOT RESULT_VAR)
  452. message(FATAL_ERROR "Failed to compile DGraph application.\n${output}")
  453. endif()
  454. find_program(DGraph_EXECUTABLE DGraph
  455. "${CTK_BINARY_DIR}/Utilities/DGraph/"
  456. "${CTK_BINARY_DIR}/Utilities/DGraph/bin/"
  457. "${CTK_BINARY_DIR}/Utilities/DGraph/Debug/"
  458. "${CTK_BINARY_DIR}/Utilities/DGraph/Release/")
  459. mark_as_advanced(DGraph_EXECUTABLE)
  460. #-----------------------------------------------------------------------------
  461. # Let's make sure the enabled/disabled libraries, plugins or applications are coherent
  462. #
  463. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}")
  464. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_EXTERNALS)
  465. ctkMacroValidateBuildOptions("${CTK_BINARY_DIR}" "${DGraph_EXECUTABLE}" "${target_directories}")
  466. #-----------------------------------------------------------------------------
  467. # CTK Python wrapping - Propose the option only if CTK_LIB_Scriping/Python/Core is ON
  468. if(CTK_LIB_Scripting/Python/Core)
  469. find_package(PythonInterp)
  470. if(NOT PYTHONINTERP_FOUND)
  471. message(SEND_ERROR "PYTHON_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
  472. endif()
  473. find_package(PythonLibs)
  474. if(NOT PYTHONLIBS_FOUND)
  475. message(FATAL_ERROR "PYTHON_LIBRARIES and PYTHON_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
  476. endif()
  477. option(CTK_WRAP_PYTHONQT_FULL "Experimental - Wrap CTK classes using Qt meta-object system into Python language" OFF)
  478. mark_as_advanced(CTK_WRAP_PYTHONQT_FULL)
  479. option(CTK_WRAP_PYTHONQT_LIGHT "Wrap CTK classes using Qt meta-object system into Python language" OFF)
  480. if(CTK_WRAP_PYTHONQT_FULL AND CTK_WRAP_PYTHONQT_LIGHT)
  481. message(SEND_ERROR "CTK_WRAP_PYTHONQT_{LIGHT,FULL} options are mutually exclusive. Please enable only one !")
  482. endif()
  483. else()
  484. # Note that an unset boolean variable is considered to be False
  485. unset(CTK_WRAP_PYTHONQT_FULL CACHE)
  486. unset(CTK_WRAP_PYTHONQT_LIGHT CACHE)
  487. endif()
  488. #-----------------------------------------------------------------------------
  489. # DGraph
  490. #
  491. # Generate DGraph input file expected by DGraph
  492. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_OPTION)
  493. # Obtain list of target ordered topologically
  494. ctkMacroSetPaths("${QT_INSTALLED_LIBRARY_DIR}")
  495. execute_process(
  496. COMMAND "${DGraph_EXECUTABLE}" "${CTK_BINARY_DIR}/DGraphInput.txt"
  497. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  498. RESULT_VARIABLE RESULT_VAR
  499. OUTPUT_VARIABLE CTEST_PROJECT_SUBPROJECTS_OUTPUT
  500. ERROR_VARIABLE error
  501. OUTPUT_STRIP_TRAILING_WHITESPACE
  502. )
  503. if(RESULT_VAR)
  504. message(FATAL_ERROR "Failed to obtain list of target ordered topologically.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  505. endif()
  506. # Convert 'CTEST_PROJECT_SUBPROJECTS_OUTPUT' to a list
  507. string(REPLACE " " "\\;" CTEST_PROJECT_SUBPROJECTS "${CTEST_PROJECT_SUBPROJECTS_OUTPUT}")
  508. set(CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS})
  509. # If the list of subproject is empty, let's at least build CTKCore
  510. list(LENGTH CTEST_PROJECT_SUBPROJECTS subproject_count)
  511. IF (subproject_count EQUAL 0)
  512. set(CTEST_PROJECT_SUBPROJECTS CTKCore)
  513. endif()
  514. # Configure CTestConfigSubProject.cmake used that could be used by CTest scripts
  515. configure_file(${CTK_SOURCE_DIR}/CTestConfigSubProject.cmake.in
  516. ${CTK_BINARY_DIR}/CTestConfigSubProject.cmake)
  517. #-----------------------------------------------------------------------------
  518. # Project.xml
  519. #
  520. # Generate Project.xml file expected by the CTest driver script
  521. ctkFunctionGenerateProjectXml(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_directories}" ${CTK_SUPERBUILD})
  522. #-----------------------------------------------------------------------------
  523. # CTK dependencies - Projects should be TOPOLOGICALLY ordered
  524. #-----------------------------------------------------------------------------
  525. set(CTK_POSSIBLE_DEPENDENCIES
  526. CTKData
  527. Log4Qt
  528. KWStyle
  529. VTK
  530. PythonQt
  531. PythonQtGenerator # Should be added after PythonQt - See comment in CMakeExternals/PythonQtGenerator.cmake
  532. DCMTK
  533. ZMQ
  534. QtSOAP
  535. qxmlrpc
  536. OpenIGTLink
  537. XIP
  538. ITK
  539. )
  540. set(CTK_DEPENDENCIES) # This variable will contain the list of required CTK dependencies
  541. include(CMake/ctkBlockCheckDependencies.cmake)
  542. #-----------------------------------------------------------------------------
  543. # Superbuild script
  544. #
  545. if(CTK_SUPERBUILD)
  546. include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  547. return()
  548. endif()
  549. #-----------------------------------------------------------------------------
  550. # Expand variables containing include and library directories for external projects
  551. # This relies on the variable EXTERNAL_TARGETS set in ctkMacroValidateBuildOptions
  552. foreach(_external_target ${EXTERNAL_TARGETS})
  553. if(${_external_target}_FIND_PACKAGE_CMD)
  554. #message("Calling find_package(${${_external_target}_FIND_PACKAGE_CMD})")
  555. find_package(${${_external_target}_FIND_PACKAGE_CMD} REQUIRED)
  556. endif()
  557. endforeach()
  558. foreach(_external_target ${EXTERNAL_TARGETS})
  559. if(${_external_target}_INCLUDE_DIRS)
  560. #message("[${_external_target}] Resolving include variables: ${${_external_target}_INCLUDE_DIRS}")
  561. foreach(_include_variable ${${_external_target}_INCLUDE_DIRS})
  562. #message("[${_external_target}] Appending ${${_include_variable}}")
  563. if(${_include_variable})
  564. list(APPEND ${_external_target}_INCLUDE_DIRS ${${_include_variable}})
  565. else()
  566. list(APPEND ${_external_target}_INCLUDE_DIRS ${_include_variable})
  567. endif()
  568. #message("[${_external_target}] New dirs: ${${_external_target}_INCLUDE_DIRS}")
  569. endforeach()
  570. #message("[${_external_target}] Appended dirs: ${${_external_target}_INCLUDE_DIRS}")
  571. endif()
  572. if(${_external_target}_LIBRARY_DIRS)
  573. #message("[${_external_target}] Resolving library variables: ${${_external_target}_LIBRARY_DIRS}")
  574. foreach(_library_variable ${${_external_target}_LIBRARY_DIRS})
  575. #message("[${_external_target}] Appending ${${_library_variable}}")
  576. if(${_library_variable})
  577. list(APPEND ${_external_target}_LIBRARY_DIRS ${${_library_variable}})
  578. else()
  579. list(APPEND ${_external_target}_LIBRARY_DIRS ${_library_variable})
  580. endif()
  581. #message("[${_external_target}] New dirs: ${${_external_target}_LIBRARY_DIRS}")
  582. endforeach()
  583. #message("[${_external_target}] Appended dirs: ${${_external_target}_LIBRARY_DIRS}")
  584. endif()
  585. endforeach()
  586. # Since PYTHONQT_USE_VTK library option can be enabled independently of
  587. # Visualization/VTK/Core, let's make sure VTK has been properly discovered
  588. if(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
  589. find_package(VTK REQUIRED)
  590. endif()
  591. set(CTK_WRAP_PYTHONQT_USE_VTK ${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK})
  592. #-----------------------------------------------------------------------------
  593. # CTK_SUPERBUILD_BINARY_DIR
  594. # If CTK_SUPERBUILD_BINARY_DIR isn't defined, it means CTK is *NOT* build using Superbuild.
  595. # In that specific case, CTK_SUPERBUILD_BINARY_DIR should default to CTK_BINARY_DIR
  596. if(NOT DEFINED CTK_SUPERBUILD_BINARY_DIR)
  597. set(CTK_SUPERBUILD_BINARY_DIR ${CTK_BINARY_DIR})
  598. endif()
  599. #-----------------------------------------------------------------------------
  600. # Configure files with settings
  601. #
  602. configure_file(${CTK_SOURCE_DIR}/UseCTK.cmake.in
  603. ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY IMMEDIATE)
  604. set(CTK_CONFIG_H_INCLUDE_DIR ${CTK_BINARY_DIR})
  605. #-----------------------------------------------------------------------------
  606. # Set C/CXX Flags
  607. #
  608. set(CMAKE_CXX_FLAGS ${CTK_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE)
  609. set(CMAKE_C_FLAGS ${CTK_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE)
  610. #-----------------------------------------------------------------------------
  611. # Set the header template which defines custom export/import macros
  612. # for shared libraries
  613. #
  614. set(CTK_EXPORT_HEADER_TEMPLATE "${CTK_SOURCE_DIR}/Libs/ctkExport.h.in")
  615. #-----------------------------------------------------------------------------
  616. # Setup testing environment before Libs are added
  617. #
  618. if(BUILD_TESTING)
  619. add_subdirectory(Libs/Testing)
  620. endif()
  621. #-----------------------------------------------------------------------------
  622. # Add CTK library subdirectories
  623. #
  624. foreach(lib ${CTK_LIBS_SUBDIRS})
  625. IF (CTK_LIB_${lib})
  626. add_subdirectory(Libs/${lib})
  627. endif()
  628. endforeach()
  629. #-----------------------------------------------------------------------------
  630. # Add CTK plugin subdirectories
  631. #
  632. foreach(plugin ${CTK_PLUGINS_SUBDIRS})
  633. if(CTK_PLUGIN_${plugin})
  634. add_subdirectory(Plugins/${plugin})
  635. endif()
  636. endforeach()
  637. #-----------------------------------------------------------------------------
  638. # Add CTK application subdirectories
  639. #
  640. foreach(app ${CTK_APPLICATIONS_SUBDIRS})
  641. IF (CTK_APP_${app})
  642. add_subdirectory(Applications/${app})
  643. endif()
  644. endforeach()
  645. if(BUILD_TESTING)
  646. add_subdirectory(Applications/Testing)
  647. endif()
  648. #-----------------------------------------------------------------------------
  649. # Add general purpose subdirectories
  650. #
  651. #add_subdirectory(Testing)
  652. #add_subdirectory(Examples)
  653. #-----------------------------------------------------------------------------
  654. # Style Checking configuration
  655. #
  656. include(Utilities/KWStyle/KWStyle.cmake)
  657. #---------------------------------------------------------------------------
  658. # Documentation
  659. #
  660. add_subdirectory( Documentation )
  661. #-----------------------------------------------------------------------------
  662. # The commands in this directory are intended to be executed as
  663. # the end of the whole configuration process, as a "last step".
  664. # This directory is typically the last SUBDIRS in the main CMakeLists.txt.
  665. add_subdirectory(Utilities/LastConfigureStep)