CMakeLists.txt 42 KB

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