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