CMakeLists.txt 42 KB

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