CMakeLists.txt 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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. # Superbuild
  23. #
  24. set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
  25. set(EXTERNAL_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/CMakeExternals)
  26. set(EXTERNAL_PROJECT_FILE_PREFIX "")
  27. include(ExternalProject)
  28. include(ctkMacroCheckExternalProjectDependency)
  29. #-----------------------------------------------------------------------------
  30. if(APPLE)
  31. # Note: By setting CMAKE_OSX_* variables before any enable_language() or project() calls,
  32. # we ensure that the bitness will be properly detected.
  33. include(ctkBlockSetCMakeOSXVariables)
  34. mark_as_superbuild(
  35. VARS CMAKE_OSX_ARCHITECTURES:STRING CMAKE_OSX_SYSROOT:PATH CMAKE_OSX_DEPLOYMENT_TARGET:STRING
  36. ALL_PROJECTS
  37. )
  38. endif()
  39. #-----------------------------------------------------------------------------
  40. project(CTK)
  41. #-----------------------------------------------------------------------------
  42. #-----------------------------------------------------------------------------
  43. # Library mode: SHARED (default) or STATIC
  44. #
  45. set(CTK_LIBRARY_MODE "SHARED")
  46. option(CTK_BUILD_SHARED_LIBS "Build CTK libraries as shared module." ON)
  47. mark_as_advanced(CTK_BUILD_SHARED_LIBS)
  48. mark_as_superbuild(CTK_BUILD_SHARED_LIBS)
  49. if(NOT CTK_BUILD_SHARED_LIBS)
  50. set(CTK_LIBRARY_MODE "STATIC")
  51. endif()
  52. #-----------------------------------------------------------------------------
  53. # Set a default build type if none was specified
  54. #
  55. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  56. message(STATUS "Setting build type to 'Debug' as none was specified.")
  57. set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  58. mark_as_advanced(CMAKE_BUILD_TYPE)
  59. # Set the possible values of build type for cmake-gui
  60. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
  61. "MinSizeRel" "RelWithDebInfo")
  62. endif()
  63. if(NOT CMAKE_CONFIGURATION_TYPES)
  64. mark_as_superbuild(VARS CMAKE_BUILD_TYPE ALL_PROJECTS)
  65. endif()
  66. #-----------------------------------------------------------------------------
  67. # Superbuild Option - Enabled by default
  68. #
  69. option(CTK_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
  70. mark_as_advanced(CTK_SUPERBUILD)
  71. #-----------------------------------------------------------------------------
  72. # Output directories.
  73. #
  74. foreach(type LIBRARY RUNTIME ARCHIVE)
  75. # Make sure the directory exists
  76. if(DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY
  77. AND NOT EXISTS ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  78. message(FATAL_ERROR "CTK_CMAKE_${type}_OUTPUT_DIRECTORY is set to a non-existing directory [${CTK_CMAKE_${type}_OUTPUT_DIRECTORY}]")
  79. endif()
  80. if(CTK_SUPERBUILD)
  81. set(output_dir ${CTK_BINARY_DIR}/bin)
  82. if(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  83. set(CTK_CMAKE_${type}_OUTPUT_DIRECTORY ${CTK_BINARY_DIR}/CTK-build/bin)
  84. endif()
  85. mark_as_superbuild(CTK_CMAKE_${type}_OUTPUT_DIRECTORY:PATH)
  86. else()
  87. if(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  88. set(output_dir ${CTK_BINARY_DIR}/bin)
  89. else()
  90. set(output_dir ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  91. endif()
  92. endif()
  93. set(CMAKE_${type}_OUTPUT_DIRECTORY ${output_dir} CACHE INTERNAL "Single output directory for building all libraries.")
  94. if(NOT DEFINED CTK_PLUGIN_${type}_OUTPUT_DIRECTORY)
  95. set(CTK_PLUGIN_${type}_OUTPUT_DIRECTORY ${CMAKE_${type}_OUTPUT_DIRECTORY})
  96. endif()
  97. endforeach()
  98. #-----------------------------------------------------------------------------
  99. # CTK version number. An even minor number corresponds to releases.
  100. #
  101. set(CTK_MAJOR_VERSION 0)
  102. set(CTK_MINOR_VERSION 1)
  103. set(CTK_PATCH_VERSION 0)
  104. set(CTK_VERSION
  105. "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}")
  106. # Append the library version information to the library target
  107. # properties. A parent project may set its own properties and/or may
  108. # block this.
  109. if(NOT CTK_NO_LIBRARY_VERSION)
  110. set(CTK_LIBRARY_PROPERTIES ${CTK_LIBRARY_PROPERTIES}
  111. VERSION "${CTK_VERSION}"
  112. SOVERSION "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}"
  113. )
  114. endif()
  115. #-----------------------------------------------------------------------------
  116. # Install directories, used for install rules.
  117. #
  118. if(NOT CTK_INSTALL_BIN_DIR)
  119. set(CTK_INSTALL_BIN_DIR "bin")
  120. endif()
  121. if(NOT CTK_INSTALL_LIB_DIR)
  122. set(CTK_INSTALL_LIB_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
  123. endif()
  124. if(NOT CTK_INSTALL_PLUGIN_DIR)
  125. set(CTK_INSTALL_PLUGIN_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}/plugins")
  126. endif()
  127. if(NOT CTK_INSTALL_CMAKE_DIR)
  128. set(CTK_INSTALL_CMAKE_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}/CMake")
  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_PLUGIN_INCLUDE_DIR)
  134. set(CTK_INSTALL_PLUGIN_INCLUDE_DIR ${CTK_INSTALL_INCLUDE_DIR})
  135. endif()
  136. if(NOT CTK_INSTALL_QTPLUGIN_DIR)
  137. set(CTK_INSTALL_QTPLUGIN_DIR ${CTK_INSTALL_LIB_DIR})
  138. endif()
  139. if(NOT CTK_INSTALL_DOC_DIR)
  140. set(CTK_INSTALL_DOC_DIR "doc")
  141. endif()
  142. mark_as_superbuild(
  143. CTK_INSTALL_BIN_DIR:STRING
  144. CTK_INSTALL_LIB_DIR:STRING
  145. CTK_INSTALL_PLUGIN_DIR:STRING
  146. CTK_INSTALL_CMAKE_DIR:STRING
  147. CTK_INSTALL_INCLUDE_DIR:STRING
  148. CTK_INSTALL_PLUGIN_INCLUDE_DIR:STRING
  149. CTK_INSTALL_QTPLUGIN_DIR:STRING
  150. CTK_INSTALL_DOC_DIR:STRING
  151. )
  152. #-----------------------------------------------------------------------------
  153. # Update CMake module path
  154. # Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
  155. #
  156. set(CMAKE_MODULE_PATH
  157. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
  158. ${CMAKE_MODULE_PATH})
  159. #-----------------------------------------------------------------------------
  160. # Clear CTK_BASE_INCLUDE_DIRS, CTK_BASE_LIBRARIES and CTK_WRAPPED_LIBRARIES_PYTHONQT
  161. #
  162. set(CTK_BASE_LIBRARIES CACHE INTERNAL "CTK base libraries" FORCE)
  163. set(CTK_BASE_INCLUDE_DIRS CACHE INTERNAL "CTK includes" FORCE)
  164. set(CTK_WRAPPED_LIBRARIES_PYTHONQT CACHE INTERNAL "CTK libraries wrapped using PythonQt" FORCE)
  165. # Variable use in CTKConfig.cmake.in
  166. set(CTK_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
  167. set(${PROJECT_NAME}_PLUGIN_LIBRARIES CACHE INTERNAL "CTK plugins" FORCE)
  168. # Used by CTKGenerateCTKConfig.cmake and also used to reference script from other scripts
  169. set(CTK_CMAKE_DIR ${CTK_SOURCE_DIR}/CMake)
  170. set(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
  171. #-----------------------------------------------------------------------------
  172. # CMake function(s) and macro(s)
  173. #
  174. foreach(file
  175. CMake/ctkListToString.cmake
  176. CMake/ctkMacroParseArguments.cmake
  177. CMake/ctkMacroSetPaths.cmake
  178. CMake/ctkMacroListFilter.cmake
  179. CMake/ctkMacroOptionUtils.cmake
  180. CMake/ctkMacroBuildLib.cmake
  181. CMake/ctkMacroBuildLibWrapper.cmake
  182. CMake/ctkMacroBuildPlugin.cmake
  183. CMake/ctkMacroBuildApp.cmake
  184. CMake/ctkMacroBuildQtPlugin.cmake
  185. CMake/ctkMacroCompilePythonScript.cmake
  186. CMake/ctkMacroGenerateMocs.cmake
  187. CMake/ctkMacroWrapPythonQt.cmake
  188. CMake/ctkMacroSetupQt.cmake
  189. CMake/ctkMacroTargetLibraries.cmake # Import multiple macros
  190. CMake/ctkFunctionExtractOptionNameAndValue.cmake
  191. CMake/ctkMacroValidateBuildOptions.cmake
  192. CMake/ctkMacroAddCtkLibraryOptions.cmake
  193. CMake/ctkFunctionGenerateDGraphInput.cmake
  194. CMake/ctkFunctionGenerateProjectXml.cmake
  195. CMake/ctkFunctionGeneratePluginManifest.cmake
  196. CMake/ctkMacroGeneratePluginResourceFile.cmake
  197. CMake/ctkFunctionAddPluginRepo.cmake
  198. CMake/ctkFunctionCheckCompilerFlags.cmake
  199. CMake/ctkFunctionCheckoutRepo.cmake
  200. CMake/ctkFunctionGetIncludeDirs.cmake
  201. CMake/ctkFunctionGetLibraryDirs.cmake
  202. CMake/ctkFunctionGetGccVersion.cmake
  203. CMake/ctkFunctionGetCompilerVisibilityFlags.cmake
  204. CMake/ctkFunctionCompileSnippets.cmake
  205. )
  206. include(${file})
  207. install(FILES ${file} DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development)
  208. endforeach()
  209. foreach(file
  210. Libs/ctkExport.h.in
  211. CMake/ctkLinkerAsNeededFlagCheck.cmake
  212. CMake/ctk_compile_python_scripts.cmake.in
  213. )
  214. install(FILES ${file} DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development)
  215. endforeach()
  216. install(FILES
  217. CMake/ctkLinkerAsNeededFlagCheck/CMakeLists.txt
  218. CMake/ctkLinkerAsNeededFlagCheck/A.cpp
  219. CMake/ctkLinkerAsNeededFlagCheck/B.cpp
  220. CMake/ctkLinkerAsNeededFlagCheck/C.cpp
  221. DESTINATION ${CTK_INSTALL_CMAKE_DIR}/ctkLinkerAsNeededFlagCheck
  222. COMPONENT Development
  223. )
  224. #-----------------------------------------------------------------------------
  225. # Testing
  226. #
  227. include(CTest)
  228. mark_as_advanced(BUILD_TESTING)
  229. mark_as_superbuild(BUILD_TESTING)
  230. if(BUILD_TESTING)
  231. set(CPP_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  232. mark_as_advanced(TCL_TCLSH DART_ROOT)
  233. include(CMake/ctkMacroSimpleTest.cmake)
  234. include(CMake/ctkMacroSimpleTestWithData.cmake)
  235. # Setup file for setting custom ctest vars
  236. configure_file(
  237. CMake/CTestCustom.cmake.in
  238. ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
  239. @ONLY
  240. )
  241. # Configuration for the CMake-generated test driver
  242. set(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include <stdexcept>")
  243. set(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
  244. try
  245. {")
  246. set(CMAKE_TESTDRIVER_AFTER_TESTMAIN " }
  247. catch( std::exception & excp )
  248. {
  249. fprintf(stderr,\"%s\\n\",excp.what());
  250. return EXIT_FAILURE;
  251. }
  252. catch( ... )
  253. {
  254. printf(\"Exception caught in the test driver\\n\");
  255. return EXIT_FAILURE;
  256. }
  257. ")
  258. endif()
  259. #-----------------------------------------------------------------------------
  260. # QtTesting
  261. #
  262. option(CTK_USE_QTTESTING "Enable/Disable QtTesting" OFF)
  263. mark_as_advanced(CTK_USE_QTTESTING)
  264. mark_as_superbuild(CTK_USE_QTTESTING)
  265. #-----------------------------------------------------------------------------
  266. # Coverage
  267. #
  268. option(WITH_COVERAGE "Enable/Disable coverage" OFF)
  269. mark_as_advanced(WITH_COVERAGE)
  270. mark_as_superbuild(WITH_COVERAGE)
  271. #-----------------------------------------------------------------------------
  272. # Documentation
  273. #
  274. option(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
  275. mark_as_advanced(DOCUMENTATION_TARGET_IN_ALL)
  276. mark_as_superbuild(DOCUMENTATION_TARGET_IN_ALL)
  277. set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  278. CACHE PATH "Where documentation archives should be stored")
  279. mark_as_advanced(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  280. mark_as_superbuild(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  281. # Attempt to discover Doxygen so that DOXYGEN_EXECUTABLE is set to an appropriate default value
  282. find_package(Doxygen QUIET)
  283. mark_as_superbuild(DOXYGEN_EXECUTABLE)
  284. #-----------------------------------------------------------------------------
  285. # Additional CXX/C Flags
  286. #
  287. set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
  288. mark_as_advanced(ADDITIONAL_C_FLAGS)
  289. mark_as_superbuild(ADDITIONAL_C_FLAGS)
  290. set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
  291. mark_as_advanced(ADDITIONAL_CXX_FLAGS)
  292. mark_as_superbuild(ADDITIONAL_CXX_FLAGS)
  293. #-----------------------------------------------------------------------------
  294. # Set symbol visibility Flags
  295. #
  296. ctkFunctionGetCompilerVisibilityFlags(VISIBILITY_CXX_FLAGS)
  297. #-----------------------------------------------------------------------------
  298. # Set coverage Flags
  299. #
  300. if(WITH_COVERAGE)
  301. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  302. set(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
  303. set(COVERAGE_CXX_FLAGS ${coverage_flags})
  304. set(COVERAGE_C_FLAGS ${coverage_flags})
  305. endif()
  306. endif()
  307. #-----------------------------------------------------------------------------
  308. # CTK C/CXX Flags
  309. #
  310. set(CTK_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
  311. set(CTK_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
  312. if(CMAKE_COMPILER_IS_GNUCXX)
  313. set(cflags "-Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings")
  314. if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  315. set(cflags "${cflags} -D_FORTIFY_SOURCE=2")
  316. endif()
  317. ctkFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
  318. ctkFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
  319. ctkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
  320. # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
  321. # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
  322. # Doing so should allow to build package made for distribution using older linux distro.
  323. if(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0"))
  324. ctkFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
  325. endif()
  326. if(MINGW)
  327. # suppress warnings about auto imported symbols
  328. set(CTK_CXX_FLAGS "-Wl,--enable-auto-import ${CTK_CXX_FLAGS}")
  329. endif()
  330. set(CTK_C_FLAGS "${cflags} ${CTK_C_FLAGS}")
  331. set(CTK_CXX_FLAGS "${cflags} -Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${CTK_CXX_FLAGS}")
  332. endif()
  333. if(MSVC)
  334. set(msvc_suppressed_warnings
  335. "/wd4290" # C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  336. )
  337. set(CTK_CXX_FLAGS "${CTK_CXX_FLAGS} ${msvc_suppressed_warnings}")
  338. endif()
  339. #-----------------------------------------------------------------------------
  340. # Check if the linker will resolve symbols of underlinked libraries
  341. #
  342. if(UNIX AND NOT APPLE)
  343. include(ctkLinkerAsNeededFlagCheck)
  344. if(CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED)
  345. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed"
  346. CACHE STRING "Flags used by the linker"
  347. FORCE)
  348. endif()
  349. endif()
  350. #-----------------------------------------------------------------------------
  351. # QT
  352. #
  353. ctkMacroSetupQt()
  354. # Update CTK_BASE_LIBRARIES with QT libraries
  355. if(QT4_FOUND)
  356. set(CTK_BASE_LIBRARIES ${CTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "CTK base libraries" FORCE)
  357. endif()
  358. #-----------------------------------------------------------------------------
  359. # To make options show up in both CTK-SuperBuild and CTK regular build, let's add them
  360. # before the SuperBuild script is included
  361. #
  362. #-----------------------------------------------------------------------------
  363. # Special "BUILD ALL" options
  364. # Build all CTK plug-ins
  365. option(CTK_BUILD_ALL_PLUGINS "Build all CTK plug-ins" OFF)
  366. mark_as_superbuild(CTK_BUILD_ALL_PLUGINS)
  367. # Build all CTK libraries
  368. option(CTK_BUILD_ALL_LIBRARIES "Build all CTK libraries" OFF)
  369. mark_as_superbuild(CTK_BUILD_ALL_LIBRARIES)
  370. # Build all CTK applications
  371. option(CTK_BUILD_ALL_APPS "Build all CTK applications" OFF)
  372. mark_as_superbuild(CTK_BUILD_ALL_APPS)
  373. # Build everything
  374. option(CTK_BUILD_ALL "Build everything in CTK" OFF)
  375. mark_as_superbuild(CTK_BUILD_ALL)
  376. if(CTK_BUILD_ALL)
  377. set(CTK_BUILD_ALL_PLUGINS 1)
  378. set(CTK_BUILD_ALL_LIBRARIES 1)
  379. set(CTK_BUILD_ALL_APPS 1)
  380. endif()
  381. #-----------------------------------------------------------------------------
  382. # Other options
  383. # Git protocol option
  384. option(CTK_USE_GIT_PROTOCOL "If behind a firewall turn this OFF to use http instead." ON)
  385. mark_as_advanced(CTK_USE_GIT_PROTOCOL)
  386. set(git_protocol "git")
  387. if(NOT CTK_USE_GIT_PROTOCOL)
  388. set(git_protocol "http")
  389. endif()
  390. # Let's mark as advanced some default properties
  391. mark_as_advanced(CMAKE_INSTALL_PREFIX)
  392. mark_as_advanced(DART_TESTING_TIMEOUT)
  393. # KWStyle
  394. option(CTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
  395. mark_as_advanced(CTK_USE_KWSTYLE)
  396. mark_as_superbuild(CTK_USE_KWSTYLE)
  397. # Qt Designer Plugins
  398. option(CTK_BUILD_QTDESIGNER_PLUGINS "Build Qt Designer plugins" ON)
  399. mark_as_advanced(CTK_BUILD_QTDESIGNER_PLUGINS)
  400. mark_as_superbuild(CTK_BUILD_QTDESIGNER_PLUGINS)
  401. #-----------------------------------------------------------------------------
  402. # CTK Libraries
  403. #
  404. ctk_lib_option(Core
  405. "Build the Core library" ON)
  406. ctk_lib_option(PluginFramework
  407. "Build the Plugin Framework" OFF
  408. CTK_ENABLE_PluginFramework)
  409. ctk_lib_option(Widgets
  410. "Build the Widgets library" OFF
  411. CTK_ENABLE_Widgets OR (CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES) OR CTK_USE_QTTESTING)
  412. ctk_lib_option(DICOM/Core
  413. "Build the DICOM Core library" OFF
  414. CTK_ENABLE_DICOM OR (CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES))
  415. ctk_lib_option(DICOM/Widgets
  416. "Build the DICOM Widgets library" OFF
  417. CTK_ENABLE_DICOM AND CTK_ENABLE_Widgets OR (CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES))
  418. ctk_lib_option(ImageProcessing/ITK/Core
  419. "Build the ITK Core library" OFF)
  420. ctk_lib_option(Scripting/Python/Core
  421. "Build the Python Core library" OFF
  422. CTK_ENABLE_Python_Wrapping)
  423. ctk_lib_option(Scripting/Python/Widgets
  424. "Build the Python Widgets library" OFF)
  425. ctk_lib_option(Visualization/VTK/Core
  426. "Build the VTK Core library" OFF)
  427. ctk_lib_option(Visualization/VTK/Widgets
  428. "Build the VTK Widgets library" OFF)
  429. ctk_lib_option(CommandLineModules/Core
  430. "Build the Command Line Module core library" OFF)
  431. ctk_lib_option(CommandLineModules/Frontend/QtWebKit
  432. "Build the QtWebKit based Command Line Module front-end" OFF)
  433. ctk_lib_option(CommandLineModules/Frontend/QtGui
  434. "Build the QtGui based Command Line Module front-end" OFF)
  435. ctk_lib_option(CommandLineModules/Backend/XMLChecker
  436. "Build the Command Line Module back-end for checking XML" OFF)
  437. ctk_lib_option(CommandLineModules/Backend/LocalProcess
  438. "Build the Command Line Module back-end for local processes" OFF)
  439. ctk_lib_option(CommandLineModules/Backend/FunctionPointer
  440. "Build the Command Line Module back-end for function pointers" OFF)
  441. ctk_lib_option(XNAT/Core
  442. "Build the XNAT Core library" OFF)
  443. ctk_lib_option(XNAT/Widgets
  444. "Build the XNAT Widgets library" OFF)
  445. #ctk_lib_option(Visualization/XIP
  446. # "Build the XIP library" OFF)
  447. # Save the set of enabled libs in a cache file
  448. set(_enabled_libs)
  449. foreach(_lib ${CTK_LIBS})
  450. if(CTK_LIB_${_lib})
  451. list(APPEND _enabled_libs ${_lib})
  452. endif()
  453. endforeach()
  454. set(CTK_ENABLED_LIBS ${_enabled_libs} CACHE INTERNAL "" FORCE)
  455. #-----------------------------------------------------------------------------
  456. # CTK Applications - Use ON or OFF to indicate if the application should be built by default
  457. #
  458. ctk_app_option(ctkDICOM
  459. "Build the DICOM example application" OFF
  460. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  461. ctk_app_option(ctkDICOM2
  462. "Build the new DICOM example application (experimental)" OFF
  463. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  464. ctk_app_option(ctkDICOMIndexer
  465. "Build the DICOM example application" OFF
  466. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  467. ctk_app_option(ctkDICOMDemoSCU
  468. "Build the DICOM example application" OFF
  469. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  470. ctk_app_option(ctkDICOMQuery
  471. "Build the DICOM example application" OFF
  472. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  473. ctk_app_option(ctkDICOMRetrieve
  474. "Build the DICOM example application" OFF
  475. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  476. ctk_app_option(ctkDICOMQueryRetrieve
  477. "Build the DICOM example application" OFF
  478. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  479. ctk_app_option(ctkDICOMHost
  480. "Build the DICOM application host example application" OFF
  481. CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
  482. ctk_app_option(ctkExampleHost
  483. "Build the DICOM example application" OFF
  484. CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
  485. ctk_app_option(ctkExampleHostedApp
  486. "Build the DICOM example application" OFF
  487. CTK_ENABLE_DICOMApplicationHosting AND CTK_BUILD_EXAMPLES)
  488. ctk_app_option(ctkEventBusDemo
  489. "Build the DICOM example application" OFF
  490. CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
  491. ctk_app_option(ctkCommandLineModuleExplorer
  492. "Build the Command Line Module Explorer" OFF
  493. CTK_BUILD_EXAMPLES)
  494. # We use the CTKWidgets library together with the Qt Designer plug-in
  495. # in ctkCommandLineModuleExplorer, so enabling the options here.
  496. # (We do not need to link them into the executable, hence no entries
  497. # in target_libraries.cmake)
  498. if(CTK_APP_ctkCommandLineModuleExplorer)
  499. foreach(_option CTK_BUILD_QTDESIGNER_PLUGINS)
  500. if(NOT ${_option})
  501. get_property(_docstring CACHE ${_option} PROPERTY HELPSTRING)
  502. set(${_option} ON CACHE BOOL "${_docstring}" FORCE)
  503. message("Enabling option [${_option}] required by [ctkCommandLineModuleExplorer]")
  504. endif()
  505. endforeach()
  506. endif()
  507. ctk_app_option(ctkPluginBrowser
  508. "Build the DICOM example application" OFF
  509. CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
  510. ctk_app_option(ctkPluginGenerator
  511. "Build the DICOM example application" OFF
  512. CTK_ENABLE_PluginFramework AND CTK_BUILD_EXAMPLES)
  513. ctk_app_option(ctkDICOMObjectViewer
  514. "Build the DICOM example application" OFF
  515. CTK_ENABLE_DICOM AND CTK_BUILD_EXAMPLES)
  516. ctk_app_option(ctkSimplePythonShell
  517. "Build the DICOM example application" OFF
  518. CTK_ENABLE_Python_Wrapping AND CTK_BUILD_EXAMPLES)
  519. if(CTK_USE_QTTESTING)
  520. ctk_app_option(ctkQtTesting
  521. "Build the ctkQtTesting example application" OFF
  522. CTK_BUILD_EXAMPLES)
  523. endif()
  524. ctk_app_option(ctkXnatTreeBrowser
  525. "Build the XNAT Tree Browser application" OFF
  526. CTK_BUILD_EXAMPLES)
  527. # Save the set of enabled apps in a cache file
  528. set(_enabled_apps)
  529. foreach(_app ${CTK_APPS})
  530. if(CTK_APP_${_app})
  531. list(APPEND _enabled_apps ${_app})
  532. endif()
  533. endforeach()
  534. set(CTK_ENABLED_APPS ${_enabled_apps} CACHE INTERNAL "" FORCE)
  535. #-----------------------------------------------------------------------------
  536. # CTK Plugins - none of them is build by default
  537. #
  538. # Plugins in the list below are not build by default
  539. set(plugin_list
  540. # Optional plug-ins implementings interfaces in PluginFramework/service/
  541. org.commontk.configadmin
  542. org.commontk.eventadmin
  543. org.commontk.log
  544. org.commontk.log4qt
  545. org.commontk.metatype
  546. )
  547. foreach(_plugin ${plugin_list})
  548. ctk_plugin_option(${_plugin} "Build the ${_plugin} plugin." OFF)
  549. endforeach()
  550. # Plug-ins related to the PluginGenerator application
  551. ctk_plugin_option(org.commontk.plugingenerator.core "Build the org.commontk.plugingenerator.core plugin." OFF)
  552. ctk_plugin_option(org.commontk.plugingenerator.ui
  553. "Build the org.commontk.plugingenerator.ui plugin." OFF
  554. CTK_APP_ctkPluginGenerator)
  555. # Plug-ins related to DICOM WG23 (Application Hosting)
  556. ctk_plugin_option(org.commontk.dah.core "Build the org.commontk.dah.core plugin." OFF)
  557. ctk_plugin_option(org.commontk.dah.hostedapp "Build the org.commontk.dah.hostedapp plugin." OFF
  558. CTK_ENABLE_DICOMApplicationHosting)
  559. ctk_plugin_option(org.commontk.dah.host "Build the org.commontk.dah.host plugin." OFF
  560. CTK_ENABLE_DICOMApplicationHosting)
  561. ctk_plugin_option(org.commontk.dah.exampleapp
  562. "Build the org.commontk.dah.exampleapp plugin." OFF
  563. CTK_APP_ctkExampleHostedApp)
  564. ctk_plugin_option(org.commontk.dah.cmdlinemoduleapp
  565. "Build the org.commontk.dah.cmdlinemoduleapp plugin." OFF
  566. CTK_APP_ctkCommandLineModuleApp)
  567. ctk_plugin_option(org.commontk.dah.examplehost
  568. "Build the org.commontk.dah.examplehost plugin." OFF
  569. CTK_APP_ctkExampleHost)
  570. # Plug-ins related to the EventBus demo application
  571. ctk_plugin_option(org.commontk.eventbus
  572. "Build the org.commontk.eventbus plugin." OFF
  573. CTK_APP_ctkEventBusDemo)
  574. # Add the PluginsContrib repo to the build system
  575. option(CTK_USE_CONTRIBUTED_PLUGINS OFF "Use CTK plug-ins from the PluginsContrib repository")
  576. mark_as_advanced(CTK_USE_CONTRIBUTED_PLUGINS)
  577. mark_as_superbuild(CTK_USE_CONTRIBUTED_PLUGINS)
  578. if(CTK_USE_CONTRIBUTED_PLUGINS)
  579. ctkFunctionAddPluginRepo(NAME PluginsContrib
  580. GIT_URL github.com/commontk/PluginsContrib.git
  581. GIT_TAG f016d35
  582. )
  583. mark_as_superbuild(PluginsContrib_DIR:PATH)
  584. endif()
  585. #-----------------------------------------------------------------------------
  586. # High-Level CTK options
  587. # The ctk_enable_option macro expects a logical expression after the first
  588. # three arguments. This expression should only contain build option names
  589. # which belong to leafs in the required dependency tree.
  590. # The CTK infrastructure for high-level DICOM support. This includes
  591. # DICOM indexing, networking, and GUI widgets.
  592. ctk_enable_option(DICOM "Enable default DICOM support" OFF
  593. CTK_LIB_DICOM/Widgets)
  594. # The CTK infrastructure for building a DICOM Part 19 compliant application
  595. # host and/or hosted application. This will not enable any example plugins
  596. # or executables (enable CTK_ENABLE_EXAMPLES for that).
  597. ctk_enable_option(DICOMApplicationHosting "Enable DICOM Part 19 Application Hosting support" OFF
  598. CTK_PLUGIN_org.commontk.dah.host AND CTK_PLUGIN_org.commontk.dah.app)
  599. # The CTK Qt Widgets. This will enable the Qt Widget library only.
  600. # It might trigger the enabling of other widget libraries in combination
  601. # with other enabled options.
  602. ctk_enable_option(Widgets "Enable Qt Widget libraries" OFF
  603. CTK_LIB_Widgets)
  604. # The CTK Plugin Framework, a dynamic component system based on OSGi.
  605. # This will enable only the framework itself.
  606. ctk_enable_option(PluginFramework "Enable Plugin Framework" OFF
  607. CTK_LIB_PluginFramework)
  608. # The CTK Python Wrapping
  609. ctk_enable_option(Python_Wrapping "Wrap CTK classes using Qt meta-object system into Python language" OFF
  610. CTK_LIB_Scripting/Python/Core)
  611. mark_as_superbuild(CTK_ENABLE_Python_Wrapping)
  612. # Build examples
  613. # Create the logical expression containing the minium set of required options
  614. # for the CTK_BUILD_EXAMPLES option to be ON
  615. set(_build_examples_logical_expr)
  616. foreach(_app ${CTK_ENABLED_APPS})
  617. list(APPEND _build_examples_logical_expr CTK_APP_${_app} AND)
  618. endforeach()
  619. if(_build_examples_logical_expr)
  620. list(REMOVE_AT _build_examples_logical_expr -1)
  621. endif()
  622. ctk_enable_option_raw(CTK_BUILD_EXAMPLES "Build examples for CTK components" OFF
  623. ${_build_examples_logical_expr})
  624. #-----------------------------------------------------------------------------
  625. # Generate target_directories list - List of directory corresponding to the different
  626. # libraries, plugins and applications associated with the corresponding option name.
  627. #
  628. # The following FOREACH loops are used to:
  629. # 1) Update either CTK_LIBS_SUBDIRS, CTK_PLUGINS_SUBDIRS or CTK_APPS_SUBDIRS variables
  630. #
  631. # For CTK libraries, if the file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake exists,
  632. # in addition to 'CTK_LIB_<DIR>/<LIBNAME>' option, the following ones
  633. # will also be available in CMake configure menu:
  634. # CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
  635. # CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)
  636. #
  637. # The file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake should look like:
  638. #
  639. # set(ctk_library_options
  640. # OPT1:OFF
  641. # OPT2:ON
  642. # )
  643. # Create list of directories corresponding to the enabled targets
  644. set(target_directories)
  645. foreach(lib ${CTK_LIBS})
  646. if(CTK_LIB_${lib})
  647. ctkMacroAddCtkLibraryOptions(${lib})
  648. endif()
  649. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}^^CTK_LIB_${lib}")
  650. endforeach()
  651. foreach(plugin ${CTK_PLUGINS})
  652. if(${plugin}_SOURCE_DIR)
  653. list(APPEND target_directories "${${plugin}_SOURCE_DIR}^^CTK_PLUGIN_${plugin}")
  654. else()
  655. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/${plugin}^^CTK_PLUGIN_${plugin}")
  656. endif()
  657. endforeach()
  658. foreach(app ${CTK_APPS})
  659. list(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${app}^^CTK_APP_${app}")
  660. endforeach()
  661. #message(STATUS target_directories:${target_directories})
  662. #-----------------------------------------------------------------------------
  663. # Compile DGraph - An application allowing to check for cycle in DAG and also obtain the
  664. # topological order.
  665. try_compile(RESULT_VAR ${CTK_BINARY_DIR}/Utilities/DGraph ${CTK_SOURCE_DIR}/Utilities/DGraph
  666. DGraph
  667. CMAKE_FLAGS
  668. -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
  669. -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
  670. -DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT}
  671. -DCMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
  672. OUTPUT_VARIABLE output)
  673. if(NOT RESULT_VAR)
  674. message(FATAL_ERROR "Failed to compile DGraph application.\n${output}")
  675. endif()
  676. find_program(DGraph_EXECUTABLE DGraph
  677. "${CTK_BINARY_DIR}/Utilities/DGraph/"
  678. "${CTK_BINARY_DIR}/Utilities/DGraph/bin/"
  679. "${CTK_BINARY_DIR}/Utilities/DGraph/Debug/"
  680. "${CTK_BINARY_DIR}/Utilities/DGraph/Release/")
  681. mark_as_advanced(DGraph_EXECUTABLE)
  682. #-----------------------------------------------------------------------------
  683. # Let's make sure the enabled/disabled libraries, plugins or applications are coherent
  684. #
  685. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}")
  686. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_EXTERNALS)
  687. ctkMacroValidateBuildOptions("${CTK_BINARY_DIR}" "${DGraph_EXECUTABLE}" "${target_directories}")
  688. #-----------------------------------------------------------------------------
  689. # CTK Python wrapping
  690. # Enable CTK_LIB_Scripting/Python/Core if CTK_ENABLE_Python_Wrapping is ON
  691. #
  692. set(CTK_WRAP_PYTHONQT_LIGHT ${CTK_ENABLE_Python_Wrapping})
  693. set(logical_expr CTK_WRAP_PYTHONQT_LIGHT)
  694. if((${logical_expr}) AND NOT CTK_LIB_Scripting/Python/Core)
  695. set(CTK_LIB_Scripting/Python/Core ON CACHE BOOL "Build the Python Core library" FORCE)
  696. set(enabling_msg)
  697. ctk_option_logical_expression_to_message(enabling_msg "${logical_expr}")
  698. message("Enabling [CTK_LIB_Scripting/Python/Core] because of [${enabling_msg}] evaluates to True")
  699. endif()
  700. set(logical_expr CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
  701. if(${logical_expr} AND NOT CTK_LIB_Visualization/VTK/Core)
  702. set(CTK_LIB_Visualization/VTK/Core ON CACHE BOOL "Build the VTK Core library" FORCE)
  703. set(enabling_msg)
  704. ctk_option_logical_expression_to_message(enabling_msg "${logical_expr}")
  705. message("Enabling [CTK_LIB_Visualization/VTK/Core] because of [${enabling_msg}] evaluates to True")
  706. endif()
  707. # Check if dependencies are satisfied
  708. if(CTK_LIB_Scripting/Python/Core)
  709. find_package(PythonInterp)
  710. if(NOT PYTHONINTERP_FOUND)
  711. message(FATAL_ERROR "PYTHON_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
  712. endif()
  713. find_package(PythonLibs)
  714. if(NOT PYTHONLIBS_FOUND)
  715. message(FATAL_ERROR "PYTHON_LIBRARIES and PYTHON_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
  716. endif()
  717. endif()
  718. #-----------------------------------------------------------------------------
  719. # DGraph
  720. #
  721. # Generate DGraph input file expected by DGraph
  722. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_OPTION)
  723. # Obtain list of target ordered topologically
  724. ctkMacroSetPaths("${QT_INSTALLED_LIBRARY_DIR}")
  725. execute_process(
  726. COMMAND "${DGraph_EXECUTABLE}" "${CTK_BINARY_DIR}/DGraphInput.txt"
  727. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  728. RESULT_VARIABLE RESULT_VAR
  729. OUTPUT_VARIABLE CTEST_PROJECT_SUBPROJECTS_OUTPUT
  730. ERROR_VARIABLE error
  731. OUTPUT_STRIP_TRAILING_WHITESPACE
  732. )
  733. if(RESULT_VAR)
  734. message(FATAL_ERROR "Failed to obtain list of target ordered topologically.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  735. endif()
  736. # Convert 'CTEST_PROJECT_SUBPROJECTS_OUTPUT' to a list
  737. string(REPLACE " " "\\;" CTEST_PROJECT_SUBPROJECTS "${CTEST_PROJECT_SUBPROJECTS_OUTPUT}")
  738. set(CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS})
  739. # If the list of subproject is empty, let's at least build CTKCore
  740. list(LENGTH CTEST_PROJECT_SUBPROJECTS subproject_count)
  741. IF (subproject_count EQUAL 0)
  742. set(CTEST_PROJECT_SUBPROJECTS CTKCore)
  743. endif()
  744. # Configure CTestConfigSubProject.cmake that could be used by CTest scripts
  745. configure_file(${CTK_SOURCE_DIR}/CMake/CTestConfigSubProject.cmake.in
  746. ${CTK_BINARY_DIR}/CTestConfigSubProject.cmake)
  747. #-----------------------------------------------------------------------------
  748. # Project.xml
  749. #
  750. # Generate Project.xml file expected by the CTest driver script
  751. ctkFunctionGenerateProjectXml(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_directories}" ${CTK_SUPERBUILD})
  752. #-----------------------------------------------------------------------------
  753. # CTK dependencies - Projects should be TOPOLOGICALLY ordered
  754. #-----------------------------------------------------------------------------
  755. set(CTK_DEPENDENCIES
  756. Log4Qt
  757. VTK
  758. PythonQt
  759. DCMTK
  760. ZMQ
  761. QtSOAP
  762. qxmlrpc
  763. qRestAPI
  764. OpenIGTLink
  765. XIP
  766. ITK
  767. )
  768. if(BUILD_TESTING)
  769. list(APPEND CTK_DEPENDENCIES CTKData)
  770. endif()
  771. if(CTK_USE_KWSTYLE)
  772. list(APPEND CTK_DEPENDENCIES KWStyle)
  773. endif()
  774. if(CTK_USE_QTTESTING)
  775. list(APPEND CTK_DEPENDENCIES QtTesting)
  776. endif()
  777. #-----------------------------------------------------------------------------
  778. # Check out the ExternalProjectsContrib repository
  779. if(CTK_USE_CONTRIBUTED_PLUGINS)
  780. if(CTK_SUPERBUILD)
  781. ctkFunctionCheckoutRepo(
  782. NAME ExternalProjectsContrib
  783. GIT_URL github.com/commontk/ExternalProjectsContrib.git
  784. GIT_TAG 4c944ef
  785. )
  786. mark_as_superbuild(ExternalProjectsContrib_DIR:PATH)
  787. endif()
  788. file(GLOB _contrib_scripts ${ExternalProjectsContrib_DIR}/*.cmake)
  789. foreach(_contrib_script ${_contrib_scripts})
  790. get_filename_component(_script_name ${_contrib_script} NAME_WE)
  791. list(APPEND CTK_DEPENDENCIES ${_script_name})
  792. set(${_script_name}_FILEPATH ${_contrib_script})
  793. endforeach()
  794. endif()
  795. include(CMake/ctkBlockCheckDependencies.cmake)
  796. #-----------------------------------------------------------------------------
  797. # Superbuild script
  798. #
  799. if(CTK_SUPERBUILD)
  800. include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  801. return()
  802. endif()
  803. if(BUILD_TESTING)
  804. add_subdirectory(CMake/Testing)
  805. endif()
  806. #-----------------------------------------------------------------------------
  807. # Expand variables containing include and library directories for external projects
  808. # This relies on the variable EXTERNAL_TARGETS set in ctkMacroValidateBuildOptions
  809. foreach(_external_target ${EXTERNAL_TARGETS})
  810. set(_package_name ${${_external_target}_FIND_PACKAGE_CMD})
  811. if(_package_name)
  812. superbuild_is_external_project_includable(${_package_name} required)
  813. if(required)
  814. #message("Calling find_package(${_package_name})")
  815. find_package(${_package_name} REQUIRED)
  816. endif()
  817. endif()
  818. endforeach()
  819. foreach(_external_target ${EXTERNAL_TARGETS})
  820. set(_package_name ${${_external_target}_FIND_PACKAGE_CMD})
  821. if("${_package_name}" STREQUAL "")
  822. set(_package_name ${_external_target})
  823. endif()
  824. if(${_external_target}_INCLUDE_DIRS)
  825. #message("[${_package_name}] Resolving include variables: ${${_external_target}_INCLUDE_DIRS}")
  826. set(_updated_include_dirs)
  827. foreach(_include_variable ${${_external_target}_INCLUDE_DIRS})
  828. set(_expanded_include_variable ${_include_variable})
  829. if(${_include_variable})
  830. #message("[${_package_name}] Expanding [${_include_variable}] into [${${_include_variable}}]")
  831. set(_expanded_include_variable ${${_include_variable}})
  832. endif()
  833. foreach(_include_dir ${_expanded_include_variable})
  834. if(EXISTS ${_include_dir})
  835. #message("[${_package_name}] Appending ${_include_dir}")
  836. list(APPEND _updated_include_dirs ${_include_dir})
  837. else()
  838. message(STATUS "[${_package_name}] Skipping nonexistent include directory or not set variable [${_include_dir}]")
  839. endif()
  840. endforeach()
  841. #message("[${_package_name}] New dirs: ${_updated_include_dirs}")
  842. endforeach()
  843. set(${_external_target}_INCLUDE_DIRS ${_updated_include_dirs})
  844. #message("[${_package_name}] Appended dirs: ${${_external_target}_INCLUDE_DIRS}")
  845. endif()
  846. if(${_external_target}_LIBRARY_DIRS)
  847. #message("[${_package_name}] Resolving library variables: ${${_external_target}_LIBRARY_DIRS}")
  848. set(_updated_library_dirs)
  849. foreach(_library_variable ${${_external_target}_LIBRARY_DIRS})
  850. set(_expanded_library_variable ${_library_variable})
  851. if(${_library_variable})
  852. #message("[${_package_name}] Expanding [${_library_variable}] into [${${_library_variable}}]")
  853. set(_expanded_library_variable ${${_library_variable}})
  854. endif()
  855. foreach(_library_dir ${_expanded_library_variable})
  856. if(EXISTS ${_library_dir})
  857. #message("[${_package_name}] Appending ${_library_dir}")
  858. list(APPEND _updated_library_dirs ${_library_dir})
  859. else()
  860. message(STATUS "[${_package_name}] Skipping nonexistent library directory or not set variable [${_library_dir}]")
  861. endif()
  862. endforeach()
  863. #message("[${_package_name}] New dirs: ${_updated_library_dirs}")
  864. endforeach()
  865. set(${_external_target}_LIBRARY_DIRS ${_updated_library_dirs})
  866. #message("[${_package_name}] Appended dirs: ${${_external_target}_LIBRARY_DIRS}")
  867. endif()
  868. endforeach()
  869. set(CTK_WRAP_PYTHONQT_USE_VTK ${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK})
  870. #-----------------------------------------------------------------------------
  871. # CTK_SUPERBUILD_BINARY_DIR
  872. # If CTK_SUPERBUILD_BINARY_DIR isn't defined, it means CTK is *NOT* build using Superbuild.
  873. # In that specific case, CTK_SUPERBUILD_BINARY_DIR should default to CTK_BINARY_DIR
  874. if(NOT DEFINED CTK_SUPERBUILD_BINARY_DIR)
  875. set(CTK_SUPERBUILD_BINARY_DIR ${CTK_BINARY_DIR})
  876. endif()
  877. #-----------------------------------------------------------------------------
  878. # Configure files with settings
  879. #
  880. configure_file(${CTK_SOURCE_DIR}/CMake/UseCTK.cmake.in
  881. ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY)
  882. install(
  883. FILES ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake
  884. DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
  885. )
  886. set(CTK_CONFIG_H_INCLUDE_DIR ${CTK_BINARY_DIR})
  887. #-----------------------------------------------------------------------------
  888. # Set C/CXX Flags
  889. #
  890. set(CMAKE_CXX_FLAGS ${CTK_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE)
  891. set(CMAKE_C_FLAGS ${CTK_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE)
  892. #-----------------------------------------------------------------------------
  893. # Set the header template which defines custom export/import macros
  894. # for shared libraries
  895. #
  896. set(CTK_EXPORT_HEADER_TEMPLATE "${CTK_SOURCE_DIR}/Libs/ctkExport.h.in")
  897. #-----------------------------------------------------------------------------
  898. # Setup testing environment before Libs are added
  899. #
  900. add_subdirectory(Libs/Testing)
  901. #-----------------------------------------------------------------------------
  902. # Add CTK library subdirectories
  903. #
  904. foreach(lib ${CTK_LIBS})
  905. if(CTK_LIB_${lib})
  906. add_subdirectory(Libs/${lib})
  907. endif()
  908. # Always add the Documentation sub-directory for additional processing
  909. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}/Documentation/CMakeLists.txt)
  910. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}/Documentation)
  911. endif()
  912. endforeach()
  913. # Add the CommandLineModules root directory for additional processing
  914. add_subdirectory(Libs/CommandLineModules)
  915. #-----------------------------------------------------------------------------
  916. if(CTK_USE_QTTESTING)
  917. add_subdirectory(Libs/QtTesting)
  918. endif()
  919. #-----------------------------------------------------------------------------
  920. # Add CTK plugin subdirectories
  921. #
  922. foreach(plugin ${CTK_PLUGINS})
  923. if(CTK_PLUGIN_${plugin})
  924. if(${plugin}_SOURCE_DIR)
  925. add_subdirectory(${${plugin}_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/Plugins/${plugin})
  926. else()
  927. add_subdirectory(Plugins/${plugin})
  928. endif()
  929. endif()
  930. endforeach()
  931. #-----------------------------------------------------------------------------
  932. # Add CTK application subdirectories
  933. #
  934. foreach(app ${CTK_APPS})
  935. IF (CTK_APP_${app})
  936. add_subdirectory(Applications/${app})
  937. endif()
  938. endforeach()
  939. if(BUILD_TESTING)
  940. add_subdirectory(Applications/Testing)
  941. endif()
  942. #-----------------------------------------------------------------------------
  943. # Add general purpose subdirectories
  944. #
  945. #add_subdirectory(Testing)
  946. #add_subdirectory(Examples)
  947. #-----------------------------------------------------------------------------
  948. # Style Checking configuration
  949. #
  950. include(Utilities/KWStyle/KWStyle.cmake)
  951. #---------------------------------------------------------------------------
  952. # Documentation
  953. #
  954. add_subdirectory( Documentation )
  955. #-----------------------------------------------------------------------------
  956. # The commands in this directory are intended to be executed as
  957. # the end of the whole configuration process, as a "last step".
  958. # This directory is typically the last SUBDIRS in the main CMakeLists.txt.
  959. add_subdirectory(CMake/LastConfigureStep)