CMakeLists.txt 42 KB

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