CMakeLists.txt 41 KB

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