CMakeLists.txt 42 KB

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