CMakeLists.txt 42 KB

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