CMakeLists.txt 42 KB

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