CMakeLists.txt 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  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. mark_as_advanced(CMAKE_BUILD_TYPE)
  70. # Set the possible values of build type for cmake-gui
  71. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
  72. "MinSizeRel" "RelWithDebInfo")
  73. endif()
  74. #-----------------------------------------------------------------------------
  75. # Superbuild Option - Enabled by default
  76. #
  77. option(CTK_SUPERBUILD "Build CTK and the projects it depends on via SuperBuild.cmake." ON)
  78. mark_as_advanced(CTK_SUPERBUILD)
  79. #-----------------------------------------------------------------------------
  80. # Output directories.
  81. #
  82. foreach(type LIBRARY RUNTIME ARCHIVE)
  83. # Make sure the directory exists
  84. if(DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY
  85. AND NOT EXISTS ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  86. message(FATAL_ERROR "CTK_CMAKE_${type}_OUTPUT_DIRECTORY is set to a non-existing directory [${CTK_CMAKE_${type}_OUTPUT_DIRECTORY}]")
  87. endif()
  88. if(CTK_SUPERBUILD)
  89. set(output_dir ${CTK_BINARY_DIR}/bin)
  90. if(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  91. set(CTK_CMAKE_${type}_OUTPUT_DIRECTORY ${CTK_BINARY_DIR}/CTK-build/bin)
  92. endif()
  93. else()
  94. if(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  95. set(output_dir ${CTK_BINARY_DIR}/bin)
  96. else()
  97. set(output_dir ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  98. endif()
  99. endif()
  100. set(CMAKE_${type}_OUTPUT_DIRECTORY ${output_dir} CACHE INTERNAL "Single output directory for building all libraries.")
  101. if(NOT DEFINED CTK_PLUGIN_${type}_OUTPUT_DIRECTORY)
  102. set(CTK_PLUGIN_${type}_OUTPUT_DIRECTORY ${CMAKE_${type}_OUTPUT_DIRECTORY})
  103. endif()
  104. endforeach()
  105. #-----------------------------------------------------------------------------
  106. # CTK version number. An even minor number corresponds to releases.
  107. #
  108. set(CTK_MAJOR_VERSION 0)
  109. set(CTK_MINOR_VERSION 1)
  110. set(CTK_PATCH_VERSION 0)
  111. set(CTK_VERSION
  112. "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}")
  113. # Append the library version information to the library target
  114. # properties. A parent project may set its own properties and/or may
  115. # block this.
  116. if(NOT CTK_NO_LIBRARY_VERSION)
  117. set(CTK_LIBRARY_PROPERTIES ${CTK_LIBRARY_PROPERTIES}
  118. VERSION "${CTK_VERSION}"
  119. SOVERSION "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}"
  120. )
  121. endif()
  122. #-----------------------------------------------------------------------------
  123. # Install directories, used for install rules.
  124. #
  125. if(NOT CTK_INSTALL_BIN_DIR)
  126. set(CTK_INSTALL_BIN_DIR "bin")
  127. endif()
  128. if(NOT CTK_INSTALL_LIB_DIR)
  129. set(CTK_INSTALL_LIB_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
  130. endif()
  131. if(NOT CTK_INSTALL_INCLUDE_DIR)
  132. set(CTK_INSTALL_INCLUDE_DIR "include/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
  133. endif()
  134. if(NOT CTK_INSTALL_DOC_DIR)
  135. set(CTK_INSTALL_DOC_DIR "doc")
  136. endif()
  137. #-----------------------------------------------------------------------------
  138. # Update CMake module path
  139. # Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
  140. #
  141. set(CMAKE_MODULE_PATH
  142. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
  143. "${CMAKE_CURRENT_SOURCE_DIR}/CMake"
  144. ${CMAKE_MODULE_PATH})
  145. #-----------------------------------------------------------------------------
  146. # Clear CTK_BASE_INCLUDE_DIRS, CTK_BASE_LIBRARIES and CTK_WRAPPED_LIBRARIES_PYTHONQT
  147. #
  148. set(CTK_BASE_LIBRARIES CACHE INTERNAL "CTK base libraries" FORCE)
  149. set(CTK_BASE_INCLUDE_DIRS CACHE INTERNAL "CTK includes" FORCE)
  150. set(CTK_WRAPPED_LIBRARIES_PYTHONQT CACHE INTERNAL "CTK libraries wrapped using PythonQt" FORCE)
  151. # Variable use in CTKConfig.cmake.in
  152. set(CTK_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
  153. set(${PROJECT_NAME}_PLUGIN_LIBRARIES CACHE INTERNAL "CTK plugins" FORCE)
  154. # Used by CTKGenerateCTKConfig.cmake and also used to reference script from other scripts
  155. set(CTK_CMAKE_DIR ${CTK_SOURCE_DIR}/CMake)
  156. set(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
  157. #-----------------------------------------------------------------------------
  158. # CMake function(s) and macro(s)
  159. #
  160. include(CMake/ctkMacroParseArguments.cmake)
  161. include(CMake/ctkMacroSetPaths.cmake)
  162. include(CMake/ctkMacroListFilter.cmake)
  163. include(CMake/ctkMacroOptionUtils.cmake)
  164. include(CMake/ctkMacroBuildLib.cmake)
  165. include(CMake/ctkMacroBuildLibWrapper.cmake)
  166. include(CMake/ctkMacroBuildPlugin.cmake)
  167. include(CMake/ctkMacroBuildApp.cmake)
  168. include(CMake/ctkMacroBuildQtPlugin.cmake)
  169. include(CMake/ctkMacroCompilePythonScript.cmake)
  170. include(CMake/ctkMacroWrapPythonQt.cmake)
  171. include(CMake/ctkMacroSetupQt.cmake)
  172. include(CMake/ctkMacroTargetLibraries.cmake) # Import multiple macros
  173. include(CMake/ctkFunctionExtractOptionNameAndValue.cmake)
  174. include(CMake/ctkMacroValidateBuildOptions.cmake)
  175. include(CMake/ctkMacroAddCtkLibraryOptions.cmake)
  176. include(CMake/ctkFunctionGenerateDGraphInput.cmake)
  177. include(CMake/ctkFunctionGenerateProjectXml.cmake)
  178. include(CMake/ctkFunctionGeneratePluginManifest.cmake)
  179. include(CMake/ctkMacroGeneratePluginResourceFile.cmake)
  180. include(CMake/ctkFunctionCheckCompilerFlags.cmake)
  181. include(CMake/ctkFunctionGetIncludeDirs.cmake)
  182. include(CMake/ctkFunctionGetLibraryDirs.cmake)
  183. include(CMake/ctkFunctionGetGccVersion.cmake)
  184. include(CMake/ctkFunctionGetCompilerVisibilityFlags.cmake)
  185. include(CMake/ctkFunctionCompileSnippets.cmake)
  186. #-----------------------------------------------------------------------------
  187. # Testing
  188. #
  189. include(CTest)
  190. mark_as_advanced(BUILD_TESTING)
  191. if(BUILD_TESTING)
  192. set(CPP_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  193. mark_as_advanced(TCL_TCLSH DART_ROOT)
  194. include(CMake/ctkMacroSimpleTest.cmake)
  195. include(CMake/ctkMacroSimpleTestWithData.cmake)
  196. # Setup file for setting custom ctest vars
  197. configure_file(
  198. CMake/CTestCustom.cmake.in
  199. ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
  200. @ONLY
  201. )
  202. # Configuration for the CMake-generated test driver
  203. set(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include <stdexcept>")
  204. set(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
  205. try
  206. {")
  207. set(CMAKE_TESTDRIVER_AFTER_TESTMAIN " }
  208. catch( std::exception & excp )
  209. {
  210. fprintf(stderr,\"%s\\n\",excp.what());
  211. return EXIT_FAILURE;
  212. }
  213. catch( ... )
  214. {
  215. printf(\"Exception caught in the test driver\\n\");
  216. return EXIT_FAILURE;
  217. }
  218. ")
  219. endif()
  220. #-----------------------------------------------------------------------------
  221. # QtTesting
  222. #
  223. option(CTK_USE_QTTESTING "Enable/Disable QtTesting" OFF)
  224. mark_as_advanced(CTK_USE_QTTESTING)
  225. #-----------------------------------------------------------------------------
  226. # Coverage
  227. #
  228. option(WITH_COVERAGE "Enable/Disable coverage" OFF)
  229. mark_as_advanced(WITH_COVERAGE)
  230. #-----------------------------------------------------------------------------
  231. # Documentation
  232. #
  233. option(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
  234. mark_as_advanced(DOCUMENTATION_TARGET_IN_ALL)
  235. set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  236. CACHE PATH "Where documentation archives should be stored")
  237. mark_as_advanced(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  238. #-----------------------------------------------------------------------------
  239. # Additional CXX/C Flags
  240. #
  241. set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
  242. mark_as_advanced(ADDITIONAL_C_FLAGS)
  243. set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
  244. mark_as_advanced(ADDITIONAL_CXX_FLAGS)
  245. #-----------------------------------------------------------------------------
  246. # Set symbol visibility Flags
  247. #
  248. ctkFunctionGetCompilerVisibilityFlags(VISIBILITY_CXX_FLAGS)
  249. #-----------------------------------------------------------------------------
  250. # Set coverage Flags
  251. #
  252. if(WITH_COVERAGE)
  253. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  254. set(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
  255. set(COVERAGE_CXX_FLAGS ${coverage_flags})
  256. set(COVERAGE_C_FLAGS ${coverage_flags})
  257. endif()
  258. endif()
  259. #-----------------------------------------------------------------------------
  260. # CTK C/CXX Flags
  261. #
  262. set(CTK_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
  263. set(CTK_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
  264. if(CMAKE_COMPILER_IS_GNUCXX)
  265. set(cflags "-Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -D_FORTIFY_SOURCE=2")
  266. ctkFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
  267. ctkFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
  268. ctkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
  269. # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
  270. # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
  271. # Doing so should allow to build package made for distribution using older linux distro.
  272. if(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0"))
  273. ctkFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
  274. endif()
  275. if(MINGW)
  276. # suppress warnings about auto imported symbols
  277. set(CTK_CXX_FLAGS "-Wl,--enable-auto-import ${CTK_CXX_FLAGS}")
  278. endif()
  279. set(CTK_C_FLAGS "${cflags} ${CTK_C_FLAGS}")
  280. set(CTK_CXX_FLAGS "${cflags} -Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${CTK_CXX_FLAGS}")
  281. endif()
  282. if(MSVC)
  283. set(msvc_suppressed_warnings
  284. "/wd4290" # C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  285. )
  286. set(CTK_CXX_FLAGS "${CTK_CXX_FLAGS} ${msvc_suppressed_warnings}")
  287. endif()
  288. #-----------------------------------------------------------------------------
  289. # QT
  290. #
  291. ctkMacroSetupQt()
  292. # Update CTK_BASE_LIBRARIES with QT libraries
  293. if(QT4_FOUND)
  294. set(CTK_BASE_LIBRARIES ${CTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "CTK base libraries" FORCE)
  295. endif()
  296. #-----------------------------------------------------------------------------
  297. # To make options show up in both CTK-SuperBuild and CTK regular build, let's add them
  298. # before the SuperBuild script is included
  299. #
  300. #-----------------------------------------------------------------------------
  301. # High-Level CTK options
  302. # The ctk_enable_option macro expects a logical expression after the first
  303. # three arguments. This expression should only contain build option names
  304. # which belong to leafs in the required dependency tree.
  305. # The CTK infrastructure for high-level DICOM support. This includes
  306. # DICOM indexing, networking, and GUI widgets.
  307. ctk_enable_option(DICOM "Enable default DICOM support" OFF
  308. CTK_LIB_DICOM/Widgets)
  309. # The CTK infrastructure for building a DICOM Part 19 compliant application
  310. # host and/or hosted application. This will not enable any example plugins
  311. # or executables (enable CTK_ENABLE_EXAMPLES for that).
  312. ctk_enable_option(DICOMApplicationHosting "Enable DICOM Part 19 Application Hosting support" OFF
  313. CTK_PLUGIN_org.commontk.dah.host AND CTK_PLUGIN_org.commontk.dah.app)
  314. # The CTK Qt Widgets. This will enable the Qt Widget library only.
  315. # It might trigger the enabling of other widget libraries in combination
  316. # with other enabled options.
  317. ctk_enable_option(Widgets "Enable Qt Widget libraries" OFF
  318. CTK_LIB_Widgets)
  319. # The CTK Plugin Framework, a dynamic component system based on OSGi.
  320. # This will enable only the framework itself.
  321. ctk_enable_option(PluginFramework "Enable Plugin Framework" OFF
  322. CTK_LIB_PluginFramework)
  323. #-----------------------------------------------------------------------------
  324. # Other options
  325. # The CTK Python Wrapping
  326. ctk_enable_option(Python_Wrapping "Wrap CTK classes using Qt meta-object system into Python language" OFF
  327. CTK_LIB_Scripting/Python/Core)
  328. # Build examples
  329. # Create the logical expression containing the minium set of required options
  330. # for the CTK_BUILD_EXAMPLES option to be ON
  331. set(_build_examples_logical_expr)
  332. foreach(_app ${CTK_ENABLED_APPS})
  333. list(APPEND _build_examples_logical_expr CTK_APP_${_app} AND)
  334. endforeach()
  335. if(_build_examples_logical_expr)
  336. list(REMOVE_AT _build_examples_logical_expr -1)
  337. endif()
  338. ctk_enable_option_raw(CTK_BUILD_EXAMPLES "Build examples for CTK components" OFF
  339. ${_build_examples_logical_expr})
  340. # Git protocol option
  341. option(CTK_USE_GIT_PROTOCOL "If behind a firewall turn this OFF to use http instead." ON)
  342. mark_as_advanced(CTK_USE_GIT_PROTOCOL)
  343. set(git_protocol "git")
  344. if(NOT CTK_USE_GIT_PROTOCOL)
  345. set(git_protocol "http")
  346. endif()
  347. # Let's mark as advanced some default properties
  348. mark_as_advanced(CMAKE_INSTALL_PREFIX)
  349. mark_as_advanced(DART_TESTING_TIMEOUT)
  350. # KWStyle
  351. option(CTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
  352. mark_as_advanced(CTK_USE_KWSTYLE)
  353. # Qt Designer Plugins
  354. option(CTK_BUILD_QTDESIGNER_PLUGINS "Build Qt Designer plugins" ON)
  355. mark_as_advanced(CTK_BUILD_QTDESIGNER_PLUGINS)
  356. #-----------------------------------------------------------------------------
  357. # CTK Libraries
  358. #
  359. ctk_lib_option(Core
  360. "Build the Core library" ON)
  361. ctk_lib_option(PluginFramework
  362. "Build the Plugin Framework" OFF
  363. CTK_ENABLE_PluginFramework)
  364. ctk_lib_option(Widgets
  365. "Build the Widgets library" OFF
  366. CTK_ENABLE_Widgets OR (CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES) OR CTK_USE_QTTESTING)
  367. ctk_lib_option(DICOM/Core
  368. "Build the DICOM Core library" OFF
  369. CTK_ENABLE_DICOM OR (CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES))
  370. ctk_lib_option(DICOM/Widgets
  371. "Build the DICOM Widgets library" OFF
  372. CTK_ENABLE_DICOM AND CTK_ENABLE_Widgets OR (CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES))
  373. ctk_lib_option(ImageProcessing/ITK/Core
  374. "Build the ITK Core library" OFF)
  375. ctk_lib_option(Scripting/Python/Core
  376. "Build the Python Core library" OFF)
  377. ctk_lib_option(Scripting/Python/Widgets
  378. "Build the Python Widgets library" OFF
  379. CTK_LIB_Widgets AND CTK_ENABLE_Python_Wrapping)
  380. ctk_lib_option(Visualization/VTK/Core
  381. "Build the VTK Core library" OFF)
  382. ctk_lib_option(Visualization/VTK/Widgets
  383. "Build the VTK Widgets library" OFF)
  384. ctk_lib_option(CommandLineModules/Core
  385. "Build the Command Line Module core library" OFF)
  386. ctk_lib_option(CommandLineModules/QtGui
  387. "Build the QtGui based Command Line Module library" OFF)
  388. #ctk_lib_option(Visualization/XIP
  389. # "Build the XIP library" OFF)
  390. # Save the set of enabled libs in a cache file
  391. set(_enabled_libs)
  392. foreach(_lib ${CTK_LIBS})
  393. if(CTK_LIB_${_lib})
  394. list(APPEND _enabled_libs ${_lib})
  395. endif()
  396. endforeach()
  397. set(CTK_ENABLED_LIBS ${_enabled_libs} CACHE INTERNAL "" FORCE)
  398. #-----------------------------------------------------------------------------
  399. # CTK Applications - Use ON or OFF to indicate if the application should be built by default
  400. #
  401. ctk_app_option(ctkDICOM
  402. "Build the DICOM example application" OFF
  403. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  404. ctk_app_option(ctkDICOMIndexer
  405. "Build the DICOM example application" OFF
  406. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  407. ctk_app_option(ctkDICOMDemoSCU
  408. "Build the DICOM example application" OFF
  409. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  410. ctk_app_option(ctkDICOMQuery
  411. "Build the DICOM example application" OFF
  412. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  413. ctk_app_option(ctkDICOMRetrieve
  414. "Build the DICOM example application" OFF
  415. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  416. ctk_app_option(ctkDICOMQueryRetrieve
  417. "Build the DICOM example application" OFF
  418. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  419. ctk_app_option(ctkExampleHost
  420. "Build the DICOM example application" OFF
  421. CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
  422. ctk_app_option(ctkExampleHostedApp
  423. "Build the DICOM example application" OFF
  424. CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
  425. ctk_app_option(ctkEventBusDemo
  426. "Build the DICOM example application" OFF
  427. CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
  428. ctk_app_option(ctkCommandLineModuleExplorer
  429. "Build the Command Line Module Explorer" OFF
  430. CTK_BUILD_EXAMPLES)
  431. # We use the CTKWidgets library together with the Qt Designer plug-in
  432. # in ctkCommandLineModuleExplorer, so enabling the options here.
  433. # (We do not need to link them into the executable, hence no entries
  434. # in target_libraries.cmake)
  435. if(CTK_APP_ctkCommandLineModuleExplorer)
  436. foreach(_option CTK_LIB_Widgets CTK_BUILD_QTDESIGNER_PLUGINS)
  437. if(NOT ${_option})
  438. get_property(_docstring CACHE ${_option} PROPERTY HELPSTRING)
  439. set(${_option} ON CACHE BOOL "${_docstring}" FORCE)
  440. message("Enabling option [${_option}] required by [ctkCommandLineModuleExplorer]")
  441. endif()
  442. endforeach()
  443. endif()
  444. ctk_app_option(ctkPluginBrowser
  445. "Build the DICOM example application" OFF
  446. CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
  447. ctk_app_option(ctkPluginGenerator
  448. "Build the DICOM example application" OFF
  449. CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
  450. ctk_app_option(ctkDICOMObjectViewer
  451. "Build the DICOM example application" OFF
  452. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  453. ctk_app_option(ctkSimplePythonShell
  454. "Build the DICOM example application" OFF
  455. CTK_ENABLE_Python_Wrapping AND CTK_BUILD_EXAMPLES)
  456. if(CTK_USE_QTTESTING)
  457. ctk_app_option(ctkQtTesting
  458. "Build the ctkQtTesting example application" OFF
  459. CTK_BUILD_EXAMPLES)
  460. endif()
  461. # Save the set of enabled apps in a cache file
  462. set(_enabled_apps)
  463. foreach(_app ${CTK_APPS})
  464. if(CTK_APP_${_app})
  465. list(APPEND _enabled_apps ${_app})
  466. endif()
  467. endforeach()
  468. set(CTK_ENABLED_APPS ${_enabled_apps} CACHE INTERNAL "" FORCE)
  469. #-----------------------------------------------------------------------------
  470. # CTK Plugins - none of them is build by default
  471. #
  472. # Plugins in the list below are not build by default
  473. set(plugin_list
  474. # Optional plug-ins implementings interfaces in PluginFramework/service/
  475. org.commontk.configadmin
  476. org.commontk.eventadmin
  477. org.commontk.log
  478. org.commontk.log4qt
  479. org.commontk.metatype
  480. # Misc
  481. #org.commontk.slicermodule
  482. )
  483. foreach(_plugin ${plugin_list})
  484. ctk_plugin_option(${_plugin} "Build the ${_plugin} plugin." OFF)
  485. endforeach()
  486. # Plug-ins related to the PluginGenerator application
  487. ctk_plugin_option(org.commontk.plugingenerator.core "Build the org.commontk.plugingenerator.core plugin." OFF)
  488. ctk_plugin_option(org.commontk.plugingenerator.ui
  489. "Build the org.commontk.plugingenerator.ui plugin." OFF
  490. CTK_APP_ctkPluginGenerator)
  491. # Plug-ins related to DICOM WG23 (Application Hosting)
  492. ctk_plugin_option(org.commontk.dah.core "Build the org.commontk.dah.core plugin." OFF)
  493. ctk_plugin_option(org.commontk.dah.app "Build the org.commontk.dah.app plugin." OFF
  494. CTK_ENABLE_DICOMApplicationHosting)
  495. ctk_plugin_option(org.commontk.dah.host "Build the org.commontk.dah.host plugin." OFF
  496. CTK_ENABLE_DICOMApplicationHosting)
  497. ctk_plugin_option(org.commontk.dah.exampleapp
  498. "Build the org.commontk.dah.exampleapp plugin." OFF
  499. CTK_APP_ctkExampleHostedApp)
  500. ctk_plugin_option(org.commontk.dah.examplehost
  501. "Build the org.commontk.dah.examplehost plugin." OFF
  502. CTK_APP_ctkExampleHost)
  503. # Plug-ins related to the EventBus demo application
  504. ctk_plugin_option(org.commontk.eventbus
  505. "Build the org.commontk.eventbus plugin." OFF
  506. CTK_APP_ctkEventBusDemo)
  507. #-----------------------------------------------------------------------------
  508. # Generate target_directories list - List of directory corresponding to the different
  509. # libraries, plugins and applications associated with the corresponding option name.
  510. #
  511. # The following FOREACH loops are used to:
  512. # 1) Update either CTK_LIBS_SUBDIRS, CTK_PLUGINS_SUBDIRS or CTK_APPS_SUBDIRS variables
  513. #
  514. # For CTK libraries, if the file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake exists,
  515. # in addition to 'CTK_LIB_<DIR>/<LIBNAME>' option, the following ones
  516. # will also be available in CMake configure menu:
  517. # CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
  518. # CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)
  519. #
  520. # The file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake should look like:
  521. #
  522. # set(ctk_library_options
  523. # OPT1:OFF
  524. # OPT2:ON
  525. # )
  526. # Create list of directories corresponding to the enabled targets
  527. set(target_directories)
  528. set(ctk_lib_options_list) # This list will be updated in ctkMacroAddCtkLibraryOptions
  529. foreach(lib ${CTK_LIBS})
  530. if(CTK_LIB_${lib})
  531. ctkMacroAddCtkLibraryOptions(${lib})
  532. endif()
  533. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}^^CTK_LIB_${lib}")
  534. endforeach()
  535. foreach(plugin ${CTK_PLUGINS})
  536. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/${plugin}^^CTK_PLUGIN_${plugin}")
  537. endforeach()
  538. foreach(app ${CTK_APPS})
  539. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${app}^^CTK_APP_${app}")
  540. endforeach()
  541. #message(STATUS target_directories:${target_directories})
  542. #-----------------------------------------------------------------------------
  543. # Compile DGraph - An application allowing to check for cycle in DAG and also obtain the
  544. # topological order.
  545. try_compile(RESULT_VAR ${CTK_BINARY_DIR}/Utilities/DGraph ${CTK_SOURCE_DIR}/Utilities/DGraph
  546. DGraph
  547. CMAKE_FLAGS
  548. -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
  549. -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
  550. -DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT}
  551. -DCMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
  552. OUTPUT_VARIABLE output)
  553. if(NOT RESULT_VAR)
  554. message(FATAL_ERROR "Failed to compile DGraph application.\n${output}")
  555. endif()
  556. find_program(DGraph_EXECUTABLE DGraph
  557. "${CTK_BINARY_DIR}/Utilities/DGraph/"
  558. "${CTK_BINARY_DIR}/Utilities/DGraph/bin/"
  559. "${CTK_BINARY_DIR}/Utilities/DGraph/Debug/"
  560. "${CTK_BINARY_DIR}/Utilities/DGraph/Release/")
  561. mark_as_advanced(DGraph_EXECUTABLE)
  562. #-----------------------------------------------------------------------------
  563. # Let's make sure the enabled/disabled libraries, plugins or applications are coherent
  564. #
  565. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}")
  566. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_EXTERNALS)
  567. ctkMacroValidateBuildOptions("${CTK_BINARY_DIR}" "${DGraph_EXECUTABLE}" "${target_directories}")
  568. #-----------------------------------------------------------------------------
  569. # CTK Python wrapping
  570. # Enable CTK_LIB_Scripting/Python/Core if either CTK_ENABLE_Python_Wrapping OR CTK_WRAP_PYTHONQT_FULL
  571. #
  572. set(CTK_WRAP_PYTHONQT_LIGHT ${CTK_ENABLE_Python_Wrapping})
  573. option(CTK_WRAP_PYTHONQT_FULL "Experimental - Wrap CTK classes using Qt meta-object system into Python language" OFF)
  574. mark_as_advanced(CTK_WRAP_PYTHONQT_FULL)
  575. if(CTK_WRAP_PYTHONQT_FULL AND CTK_WRAP_PYTHONQT_LIGHT)
  576. message(FATAL_ERROR "CTK_ENABLE_Python_Wrapping AND CTK_WRAP_PYTHONQT_FULL options are mutually exclusive. Please enable only one !")
  577. endif()
  578. set(logical_expr CTK_WRAP_PYTHONQT_LIGHT OR CTK_WRAP_PYTHONQT_FULL)
  579. if((${logical_expr}) AND NOT CTK_LIB_Scripting/Python/Core)
  580. set(CTK_LIB_Scripting/Python/Core ON CACHE BOOL "Build the Python Core library" FORCE)
  581. set(enabling_msg)
  582. ctk_option_logical_expression_to_message(enabling_msg "${logical_expr}")
  583. message("Enabling [CTK_LIB_Scripting/Python/Core] because of [${enabling_msg}] evaluates to True")
  584. endif()
  585. set(logical_expr CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
  586. if(${logical_expr} AND NOT CTK_LIB_Visualization/VTK/Core)
  587. set(CTK_LIB_Visualization/VTK/Core ON CACHE BOOL "Build the VTK Core library" FORCE)
  588. set(enabling_msg)
  589. ctk_option_logical_expression_to_message(enabling_msg "${logical_expr}")
  590. message("Enabling [CTK_LIB_Visualization/VTK/Core] because of [${enabling_msg}] evaluates to True")
  591. endif()
  592. # Check if dependencies are satisfied
  593. if(CTK_LIB_Scripting/Python/Core)
  594. find_package(PythonInterp)
  595. if(NOT PYTHONINTERP_FOUND)
  596. message(FATAL_ERROR "PYTHON_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
  597. endif()
  598. find_package(PythonLibs)
  599. if(NOT PYTHONLIBS_FOUND)
  600. message(FATAL_ERROR "PYTHON_LIBRARIES and PYTHON_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
  601. endif()
  602. endif()
  603. #-----------------------------------------------------------------------------
  604. # DGraph
  605. #
  606. # Generate DGraph input file expected by DGraph
  607. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_OPTION)
  608. # Obtain list of target ordered topologically
  609. ctkMacroSetPaths("${QT_INSTALLED_LIBRARY_DIR}")
  610. execute_process(
  611. COMMAND "${DGraph_EXECUTABLE}" "${CTK_BINARY_DIR}/DGraphInput.txt"
  612. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  613. RESULT_VARIABLE RESULT_VAR
  614. OUTPUT_VARIABLE CTEST_PROJECT_SUBPROJECTS_OUTPUT
  615. ERROR_VARIABLE error
  616. OUTPUT_STRIP_TRAILING_WHITESPACE
  617. )
  618. if(RESULT_VAR)
  619. message(FATAL_ERROR "Failed to obtain list of target ordered topologically.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  620. endif()
  621. # Convert 'CTEST_PROJECT_SUBPROJECTS_OUTPUT' to a list
  622. string(REPLACE " " "\\;" CTEST_PROJECT_SUBPROJECTS "${CTEST_PROJECT_SUBPROJECTS_OUTPUT}")
  623. set(CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS})
  624. # If the list of subproject is empty, let's at least build CTKCore
  625. list(LENGTH CTEST_PROJECT_SUBPROJECTS subproject_count)
  626. IF (subproject_count EQUAL 0)
  627. set(CTEST_PROJECT_SUBPROJECTS CTKCore)
  628. endif()
  629. # Configure CTestConfigSubProject.cmake that could be used by CTest scripts
  630. configure_file(${CTK_SOURCE_DIR}/CMake/CTestConfigSubProject.cmake.in
  631. ${CTK_BINARY_DIR}/CTestConfigSubProject.cmake)
  632. #-----------------------------------------------------------------------------
  633. # Project.xml
  634. #
  635. # Generate Project.xml file expected by the CTest driver script
  636. ctkFunctionGenerateProjectXml(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_directories}" ${CTK_SUPERBUILD})
  637. #-----------------------------------------------------------------------------
  638. # CTK dependencies - Projects should be TOPOLOGICALLY ordered
  639. #-----------------------------------------------------------------------------
  640. set(CTK_POSSIBLE_DEPENDENCIES
  641. CTKData
  642. QtTesting
  643. Log4Qt
  644. KWStyle
  645. VTK
  646. PythonQt
  647. PythonQtGenerator # Should be added after PythonQt - See comment in CMakeExternals/PythonQtGenerator.cmake
  648. DCMTK
  649. ZMQ
  650. QtSOAP
  651. qxmlrpc
  652. OpenIGTLink
  653. XIP
  654. ITK
  655. )
  656. set(CTK_DEPENDENCIES) # This variable will contain the list of required CTK dependencies
  657. include(CMake/ctkBlockCheckDependencies.cmake)
  658. #-----------------------------------------------------------------------------
  659. # Superbuild script
  660. #
  661. if(CTK_SUPERBUILD)
  662. include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  663. return()
  664. endif()
  665. #-----------------------------------------------------------------------------
  666. # Expand variables containing include and library directories for external projects
  667. # This relies on the variable EXTERNAL_TARGETS set in ctkMacroValidateBuildOptions
  668. foreach(_external_target ${EXTERNAL_TARGETS})
  669. if(${_external_target}_FIND_PACKAGE_CMD)
  670. #message("Calling find_package(${${_external_target}_FIND_PACKAGE_CMD})")
  671. find_package(${${_external_target}_FIND_PACKAGE_CMD} REQUIRED)
  672. endif()
  673. endforeach()
  674. foreach(_external_target ${EXTERNAL_TARGETS})
  675. if(${_external_target}_INCLUDE_DIRS)
  676. #message("[${_external_target}] Resolving include variables: ${${_external_target}_INCLUDE_DIRS}")
  677. foreach(_include_variable ${${_external_target}_INCLUDE_DIRS})
  678. #message("[${_external_target}] Appending ${${_include_variable}}")
  679. if(${_include_variable})
  680. list(APPEND ${_external_target}_INCLUDE_DIRS ${${_include_variable}})
  681. else()
  682. list(APPEND ${_external_target}_INCLUDE_DIRS ${_include_variable})
  683. endif()
  684. #message("[${_external_target}] New dirs: ${${_external_target}_INCLUDE_DIRS}")
  685. endforeach()
  686. #message("[${_external_target}] Appended dirs: ${${_external_target}_INCLUDE_DIRS}")
  687. endif()
  688. if(${_external_target}_LIBRARY_DIRS)
  689. #message("[${_external_target}] Resolving library variables: ${${_external_target}_LIBRARY_DIRS}")
  690. foreach(_library_variable ${${_external_target}_LIBRARY_DIRS})
  691. #message("[${_external_target}] Appending ${${_library_variable}}")
  692. if(${_library_variable})
  693. list(APPEND ${_external_target}_LIBRARY_DIRS ${${_library_variable}})
  694. else()
  695. list(APPEND ${_external_target}_LIBRARY_DIRS ${_library_variable})
  696. endif()
  697. #message("[${_external_target}] New dirs: ${${_external_target}_LIBRARY_DIRS}")
  698. endforeach()
  699. #message("[${_external_target}] Appended dirs: ${${_external_target}_LIBRARY_DIRS}")
  700. endif()
  701. endforeach()
  702. set(CTK_WRAP_PYTHONQT_USE_VTK ${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK})
  703. #-----------------------------------------------------------------------------
  704. # CTK_SUPERBUILD_BINARY_DIR
  705. # If CTK_SUPERBUILD_BINARY_DIR isn't defined, it means CTK is *NOT* build using Superbuild.
  706. # In that specific case, CTK_SUPERBUILD_BINARY_DIR should default to CTK_BINARY_DIR
  707. if(NOT DEFINED CTK_SUPERBUILD_BINARY_DIR)
  708. set(CTK_SUPERBUILD_BINARY_DIR ${CTK_BINARY_DIR})
  709. endif()
  710. #-----------------------------------------------------------------------------
  711. # Configure files with settings
  712. #
  713. configure_file(${CTK_SOURCE_DIR}/CMake/UseCTK.cmake.in
  714. ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY IMMEDIATE)
  715. set(CTK_CONFIG_H_INCLUDE_DIR ${CTK_BINARY_DIR})
  716. #-----------------------------------------------------------------------------
  717. # Set C/CXX Flags
  718. #
  719. set(CMAKE_CXX_FLAGS ${CTK_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE)
  720. set(CMAKE_C_FLAGS ${CTK_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE)
  721. #-----------------------------------------------------------------------------
  722. # Set the header template which defines custom export/import macros
  723. # for shared libraries
  724. #
  725. set(CTK_EXPORT_HEADER_TEMPLATE "${CTK_SOURCE_DIR}/Libs/ctkExport.h.in")
  726. #-----------------------------------------------------------------------------
  727. # Setup testing environment before Libs are added
  728. #
  729. add_subdirectory(Libs/Testing)
  730. #-----------------------------------------------------------------------------
  731. # Add CTK library subdirectories
  732. #
  733. foreach(lib ${CTK_LIBS})
  734. IF (CTK_LIB_${lib})
  735. add_subdirectory(Libs/${lib})
  736. endif()
  737. endforeach()
  738. #-----------------------------------------------------------------------------
  739. if(CTK_USE_QTTESTING)
  740. add_subdirectory(Libs/QtTesting)
  741. endif()
  742. #-----------------------------------------------------------------------------
  743. # Add CTK plugin subdirectories
  744. #
  745. foreach(plugin ${CTK_PLUGINS})
  746. if(CTK_PLUGIN_${plugin})
  747. add_subdirectory(Plugins/${plugin})
  748. endif()
  749. endforeach()
  750. #-----------------------------------------------------------------------------
  751. # Add CTK application subdirectories
  752. #
  753. foreach(app ${CTK_APPS})
  754. IF (CTK_APP_${app})
  755. add_subdirectory(Applications/${app})
  756. endif()
  757. endforeach()
  758. if(BUILD_TESTING)
  759. add_subdirectory(Applications/Testing)
  760. endif()
  761. #-----------------------------------------------------------------------------
  762. # Add general purpose subdirectories
  763. #
  764. #add_subdirectory(Testing)
  765. #add_subdirectory(Examples)
  766. #-----------------------------------------------------------------------------
  767. # Style Checking configuration
  768. #
  769. include(Utilities/KWStyle/KWStyle.cmake)
  770. #---------------------------------------------------------------------------
  771. # Documentation
  772. #
  773. add_subdirectory( Documentation )
  774. #-----------------------------------------------------------------------------
  775. # The commands in this directory are intended to be executed as
  776. # the end of the whole configuration process, as a "last step".
  777. # This directory is typically the last SUBDIRS in the main CMakeLists.txt.
  778. add_subdirectory(CMake/LastConfigureStep)