CMakeLists.txt 42 KB

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