CMakeLists.txt 42 KB

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