CMakeLists.txt 42 KB

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