CMakeLists.txt 35 KB

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