CMakeLists.txt 42 KB

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