CMakeLists.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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.commontk.org/LICENSE
  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.2)
  21. #-----------------------------------------------------------------------------
  22. # See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
  23. #
  24. SET(project_policies
  25. CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
  26. CMP0002 # NEW: Logical target names must be globally unique.
  27. CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths.
  28. CMP0004 # NEW: Libraries linked may NOT have leading or trailing whitespace.
  29. CMP0005 # NEW: Preprocessor definition values are now escaped automatically.
  30. CMP0006 # NEW: Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
  31. CMP0007 # NEW: List command no longer ignores empty elements.
  32. CMP0008 # NEW: Libraries linked by full-path must have a valid library file name.
  33. CMP0009 # NEW: FILE GLOB_RECURSE calls should not follow symlinks by default.
  34. CMP0010 # NEW: Bad variable reference syntax is an error.
  35. CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
  36. CMP0012 # NEW: if() recognizes numbers and boolean constants.
  37. CMP0013 # NEW: Duplicate binary directories are not allowed.
  38. CMP0014 # NEW: Input directories must have CMakeLists.txt
  39. )
  40. FOREACH(policy ${project_policies})
  41. IF(POLICY ${policy})
  42. CMAKE_POLICY(SET ${policy} NEW)
  43. ENDIF()
  44. ENDFOREACH()
  45. #-----------------------------------------------------------------------------
  46. if(APPLE)
  47. # Note: By setting CMAKE_OSX_* variables before any enable_language() or project() calls,
  48. # we ensure that the bitness will be properly detected.
  49. include(${CMAKE_SOURCE_DIR}/CMake/ctkBlockSetCMakeOSXVariables.cmake)
  50. endif()
  51. #-----------------------------------------------------------------------------
  52. PROJECT(CTK)
  53. #-----------------------------------------------------------------------------
  54. #-----------------------------------------------------------------------------
  55. # Library mode: SHARED (default) or STATIC
  56. #
  57. SET(CTK_LIBRARY_MODE "SHARED")
  58. OPTION(CTK_BUILD_SHARED_LIBS "Build CTK libraries as shared module." ON)
  59. MARK_AS_ADVANCED(CTK_BUILD_SHARED_LIBS)
  60. IF(NOT CTK_BUILD_SHARED_LIBS)
  61. SET(CTK_LIBRARY_MODE "STATIC")
  62. ENDIF()
  63. #-----------------------------------------------------------------------------
  64. # Superbuild Option - Enabled by default
  65. #
  66. OPTION(CTK_SUPERBUILD "Build CTK and the projects it depends on via SuperBuild.cmake." ON)
  67. MARK_AS_ADVANCED(CTK_SUPERBUILD)
  68. #-----------------------------------------------------------------------------
  69. # Output directories.
  70. #
  71. FOREACH(type LIBRARY RUNTIME ARCHIVE)
  72. # Make sure the directory exists
  73. IF(DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY
  74. AND NOT EXISTS ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  75. MESSAGE(FATAL_ERROR "CTK_CMAKE_${type}_OUTPUT_DIRECTORY is set to a non-existing directory [${CTK_CMAKE_${type}_OUTPUT_DIRECTORY}]")
  76. ENDIF()
  77. IF(CTK_SUPERBUILD)
  78. SET(output_dir ${CTK_BINARY_DIR}/bin)
  79. IF(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  80. SET(CTK_CMAKE_${type}_OUTPUT_DIRECTORY ${CTK_BINARY_DIR}/CTK-build/bin)
  81. ENDIF()
  82. ELSE()
  83. IF(NOT DEFINED CTK_CMAKE_${type}_OUTPUT_DIRECTORY)
  84. SET(output_dir ${CTK_BINARY_DIR}/bin)
  85. ELSE()
  86. SET(output_dir ${CTK_CMAKE_${type}_OUTPUT_DIRECTORY})
  87. ENDIF()
  88. ENDIF()
  89. SET(CMAKE_${type}_OUTPUT_DIRECTORY ${output_dir} CACHE INTERNAL "Single output directory for building all libraries.")
  90. ENDFOREACH()
  91. #-----------------------------------------------------------------------------
  92. # CTK version number. An even minor number corresponds to releases.
  93. #
  94. SET(CTK_MAJOR_VERSION 0)
  95. SET(CTK_MINOR_VERSION 1)
  96. SET(CTK_BUILD_VERSION 0)
  97. SET(CTK_VERSION
  98. "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_BUILD_VERSION}")
  99. # Append the library version information to the library target
  100. # properties. A parent project may set its own properties and/or may
  101. # block this.
  102. IF(NOT CTK_NO_LIBRARY_VERSION)
  103. SET(CTK_LIBRARY_PROPERTIES ${CTK_LIBRARY_PROPERTIES}
  104. VERSION "${CTK_VERSION}"
  105. SOVERSION "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}"
  106. )
  107. ENDIF()
  108. #-----------------------------------------------------------------------------
  109. # Install directories, used for install rules.
  110. #
  111. IF(NOT CTK_INSTALL_BIN_DIR)
  112. SET(CTK_INSTALL_BIN_DIR "bin")
  113. ENDIF()
  114. IF(NOT CTK_INSTALL_LIB_DIR)
  115. SET(CTK_INSTALL_LIB_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
  116. ENDIF()
  117. IF(NOT CTK_INSTALL_INCLUDE_DIR)
  118. SET(CTK_INSTALL_INCLUDE_DIR "include/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
  119. ENDIF()
  120. IF(NOT CTK_INSTALL_DOC_DIR)
  121. SET(CTK_INSTALL_DOC_DIR "doc")
  122. ENDIF()
  123. #-----------------------------------------------------------------------------
  124. # Update CMake module path
  125. # Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
  126. #
  127. SET(CMAKE_MODULE_PATH
  128. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
  129. "${CMAKE_CURRENT_SOURCE_DIR}/CMake"
  130. ${CMAKE_MODULE_PATH})
  131. #-----------------------------------------------------------------------------
  132. # Clear CTK_BASE_INCLUDE_DIRS, CTK_BASE_LIBRARIES and CTK_WRAPPED_LIBRARIES_PYTHONQT
  133. #
  134. SET(CTK_BASE_LIBRARIES CACHE INTERNAL "CTK base libraries" FORCE)
  135. SET(CTK_BASE_INCLUDE_DIRS CACHE INTERNAL "CTK includes" FORCE)
  136. SET(CTK_WRAPPED_LIBRARIES_PYTHONQT CACHE INTERNAL "CTK libraries wrapped using PythonQt" FORCE)
  137. # Variable use in CTKConfig.cmake.in
  138. SET(CTK_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
  139. SET(CTK_PLUGIN_LIBRARIES CACHE INTERNAL "CTK plugins" FORCE)
  140. # Used by CTKGenerateCTKConfig.cmake and also used to reference script from other scripts
  141. SET(CTK_CMAKE_DIR ${CTK_SOURCE_DIR}/CMake)
  142. SET(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
  143. #-----------------------------------------------------------------------------
  144. # CMake Function(s) and Macro(s)
  145. #
  146. INCLUDE(CMake/ctkMacroParseArguments.cmake)
  147. INCLUDE(CMake/ctkMacroSetPaths.cmake)
  148. INCLUDE(CMake/ctkMacroListFilter.cmake)
  149. INCLUDE(CMake/ctkMacroBuildLib.cmake)
  150. INCLUDE(CMake/ctkMacroBuildPlugin.cmake)
  151. INCLUDE(CMake/ctkMacroBuildApp.cmake)
  152. INCLUDE(CMake/ctkMacroCompilePythonScript.cmake)
  153. INCLUDE(CMake/ctkMacroWrapPythonQt.cmake)
  154. INCLUDE(CMake/ctkMacroSetupQt.cmake)
  155. INCLUDE(CMake/ctkMacroTargetLibraries.cmake) # Import multiple macros
  156. INCLUDE(CMake/ctkFunctionExtractOptionNameAndValue.cmake)
  157. INCLUDE(CMake/ctkMacroValidateBuildOptions.cmake)
  158. INCLUDE(CMake/ctkMacroAddCtkLibraryOptions.cmake)
  159. INCLUDE(CMake/ctkFunctionGenerateDGraphInput.cmake)
  160. INCLUDE(CMake/ctkFunctionGenerateProjectXml.cmake)
  161. INCLUDE(CMake/ctkFunctionGeneratePluginManifest.cmake)
  162. INCLUDE(CMake/ctkMacroGeneratePluginResourceFile.cmake)
  163. INCLUDE(CMake/ctkFunctionCheckCompilerFlags.cmake)
  164. INCLUDE(CMake/ctkFunctionGetIncludeDirs.cmake)
  165. INCLUDE(CMake/ctkFunctionGetLibraryDirs.cmake)
  166. INCLUDE(CMake/ctkFunctionGetGccVersion.cmake)
  167. #-----------------------------------------------------------------------------
  168. # Qt Designer Plugins
  169. OPTION(BUILD_QTDESIGNER_PLUGINS "Build Qt Designer plugins" ON)
  170. IF(BUILD_QTDESIGNER_PLUGINS)
  171. INCLUDE(CMake/ctkMacroBuildQtDesignerPlugin.cmake)
  172. ENDIF()
  173. #-----------------------------------------------------------------------------
  174. # Testing
  175. #
  176. OPTION(BUILD_TESTING "Test the project" ON)
  177. IF(BUILD_TESTING)
  178. ENABLE_TESTING()
  179. INCLUDE(CTest)
  180. SET(CPP_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  181. MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
  182. # Setup file for setting custom ctest vars
  183. CONFIGURE_FILE(
  184. CMake/CTestCustom.cmake.in
  185. ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
  186. @ONLY
  187. )
  188. # Configuration for the CMake-generated test driver
  189. SET(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include <stdexcept>")
  190. SET(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
  191. try
  192. {")
  193. SET(CMAKE_TESTDRIVER_AFTER_TESTMAIN " }
  194. catch( std::exception & excp )
  195. {
  196. fprintf(stderr,\"%s\\n\",excp.what());
  197. return EXIT_FAILURE;
  198. }
  199. catch( ... )
  200. {
  201. printf(\"Exception caught in the test driver\\n\");
  202. return EXIT_FAILURE;
  203. }
  204. ")
  205. ENDIF()
  206. #-----------------------------------------------------------------------------
  207. # Coverage
  208. #
  209. OPTION(WITH_COVERAGE "Enable/Disable coverage" OFF)
  210. #-----------------------------------------------------------------------------
  211. # Documentation
  212. #
  213. OPTION(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
  214. MARK_AS_ADVANCED(DOCUMENTATION_TARGET_IN_ALL)
  215. SET(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  216. CACHE PATH "Where documentation archives should be stored")
  217. MARK_AS_ADVANCED(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
  218. #-----------------------------------------------------------------------------
  219. # Additional CXX/C Flags
  220. #
  221. SET(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
  222. MARK_AS_ADVANCED(ADDITIONAL_C_FLAGS)
  223. SET(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
  224. MARK_AS_ADVANCED(ADDITIONAL_CXX_FLAGS)
  225. #-----------------------------------------------------------------------------
  226. # Set symbol visibility Flags
  227. #
  228. # MinGW does not export all symbols automatically, so no need to set flags
  229. IF(CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
  230. SET(VISIBILITY_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
  231. ENDIF()
  232. #-----------------------------------------------------------------------------
  233. # Set coverage Flags
  234. #
  235. IF(WITH_COVERAGE)
  236. IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  237. SET(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
  238. SET(COVERAGE_CXX_FLAGS ${coverage_flags})
  239. SET(COVERAGE_C_FLAGS ${coverage_flags})
  240. ENDIF()
  241. ENDIF()
  242. #-----------------------------------------------------------------------------
  243. # CTK C/CXX Flags
  244. #
  245. SET(CTK_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
  246. SET(CTK_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
  247. IF(CMAKE_COMPILER_IS_GNUCXX)
  248. SET(cflags "-Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -D_FORTIFY_SOURCE=2")
  249. ctkFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
  250. ctkFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
  251. ctkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
  252. # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
  253. # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
  254. # Doing so should allow to build package made for distribution using older linux distro.
  255. IF(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0"))
  256. ctkFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
  257. ENDIF()
  258. IF(MINGW)
  259. # suppress warnings about auto imported symbols
  260. SET(CTK_CXX_FLAGS "-Wl,--enable-auto-import ${CTK_CXX_FLAGS}")
  261. ENDIF()
  262. SET(CTK_C_FLAGS "${cflags} ${CTK_C_FLAGS}")
  263. SET(CTK_CXX_FLAGS "${cflags} -Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${CTK_CXX_FLAGS}")
  264. ENDIF()
  265. IF(MSVC)
  266. SET(msvc_suppressed_warnings
  267. "/wd4290" # C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  268. )
  269. SET(CTK_CXX_FLAGS "${CTK_CXX_FLAGS} ${msvc_suppressed_warnings}")
  270. ENDIF()
  271. #-----------------------------------------------------------------------------
  272. # QT
  273. #
  274. ctkMacroSetupQt()
  275. # Update CTK_BASE_LIBRARIES with QT libraries
  276. IF(QT4_FOUND)
  277. SET(CTK_BASE_LIBRARIES ${CTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "CTK base libraries" FORCE)
  278. ENDIF()
  279. #-----------------------------------------------------------------------------
  280. # CTK Libraries - Use ON or OFF to indicate if the library should be built by default
  281. #
  282. SET(CTK_LIBS
  283. Core:ON
  284. PluginFramework:ON
  285. Widgets:OFF
  286. DICOM/Core:OFF
  287. DICOM/Widgets:OFF
  288. ImageProcessing/ITK/Core:OFF
  289. #Messaging/Core:OFF # MessagingCore library need some love :) - Let's disable it for now :(
  290. #ModuleDescription:OFF # ModuleDescription library need some love :) - Let's disable it for now :(
  291. Scripting/Python/Core:OFF
  292. Scripting/Python/Widgets:OFF
  293. Visualization/VTK/Core:OFF
  294. Visualization/VTK/Widgets:OFF
  295. #Visualization/XIP:OFF # XIP library need some love :) - Let's disable it for now :(
  296. )
  297. #-----------------------------------------------------------------------------
  298. # CTK Plugins - Use ON or OFF to indicate if the plugin should be built by default
  299. #
  300. SET(CTK_PLUGINS
  301. org.commontk.eventbus:OFF
  302. org.commontk.configadmin:OFF
  303. org.commontk.dah.app:OFF
  304. org.commontk.dah.core:OFF
  305. org.commontk.dah.exampleapp:OFF
  306. org.commontk.dah.examplehost:OFF
  307. org.commontk.dah.host:OFF
  308. org.commontk.eventadmin:OFF
  309. org.commontk.log:OFF
  310. org.commontk.log4qt:OFF
  311. org.commontk.metatype:OFF
  312. org.commontk.plugingenerator.core:OFF
  313. org.commontk.plugingenerator.ui:OFF
  314. org.commontk.qtmobility.service:OFF
  315. org.commontk.slicermodule:OFF
  316. )
  317. #-----------------------------------------------------------------------------
  318. # CTK Applications - Use ON or OFF to indicate if the application should be built by default
  319. #
  320. SET(CTK_APPLICATIONS
  321. ctkCLIPluginExplorer:OFF
  322. ctkDICOM:OFF
  323. ctkDICOMIndexer:OFF
  324. ctkDICOMDemoSCU:OFF
  325. ctkDICOMQuery:OFF
  326. ctkDICOMRetrieve:OFF
  327. ctkDICOMQueryRetrieve:OFF
  328. ctkExampleHost:OFF
  329. ctkExampleHostedApp:OFF
  330. ctkPluginBrowser:OFF
  331. ctkPluginGenerator:OFF
  332. ctkDICOMObjectViewer:OFF
  333. ctkSimplePythonShell:OFF
  334. )
  335. #-----------------------------------------------------------------------------
  336. # To make options show up in both CTK-SuperBuild and CTK regular build, let's add them
  337. # before the SuperBuild script is included
  338. #
  339. # Let's mark as advanced some default properties
  340. MARK_AS_ADVANCED(CMAKE_INSTALL_PREFIX)
  341. MARK_AS_ADVANCED(DART_TESTING_TIMEOUT)
  342. # KWStyle
  343. OPTION(CTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
  344. #MARK_AS_ADVANCED(CTK_USE_KWSTYLE)
  345. #---------------------------------------------------------------------------
  346. # Will contain a list of sub-directory without option ON or OFF
  347. #
  348. SET(CTK_LIBS_SUBDIRS )
  349. SET(CTK_PLUGINS_SUBDIRS )
  350. SET(CTK_APPLICATIONS_SUBDIRS )
  351. #-----------------------------------------------------------------------------
  352. # Build options associated with CTK libraries
  353. #
  354. # The following FOREACH loops are used to:
  355. # 1) Add build options associated with either libraries, plugins and applications
  356. # 2) Update either CTK_LIBS_SUBDIRS, CTK_PLUGINS_SUBDIRS or CTK_APPS_SUBDIRS variables
  357. #
  358. # For CTK libraries, if the file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake exists,
  359. # in addition to 'CTK_LIB_<DIR>/<LIBNAME>' option, the following ones
  360. # will also be available in CMake configure menu:
  361. # CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
  362. # CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)
  363. #
  364. # The file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake should look like:
  365. #
  366. # SET(ctk_library_options
  367. # OPT1:OFF
  368. # OPT2:ON
  369. # )
  370. # Build options associated with CTK libraries
  371. SET(ctk_lib_options_list) # This list will be updated in ctkFunctionExtractOptionNameAndValue
  372. FOREACH(lib ${CTK_LIBS})
  373. ctkFunctionExtractOptionNameAndValue(${lib} lib_name lib_value)
  374. OPTION(CTK_LIB_${lib_name} "Enable ${lib_name} Library." ${lib_value})
  375. IF(CTK_LIB_${lib_name})
  376. ctkMacroAddCtkLibraryOptions(${lib_name})
  377. ENDIF()
  378. LIST(APPEND CTK_LIBS_SUBDIRS "${lib_name}")
  379. ENDFOREACH()
  380. # Build options associated with CTK plugins
  381. FOREACH(plugin ${CTK_PLUGINS})
  382. ctkFunctionExtractOptionNameAndValue(${plugin} plugin_name plugin_value)
  383. OPTION(CTK_PLUGIN_${plugin_name} "Build ${plugin_name} Plugin." ${plugin_value})
  384. LIST(APPEND CTK_PLUGINS_SUBDIRS "${plugin_name}")
  385. ENDFOREACH()
  386. # Build options associated with CTK applications
  387. FOREACH(app ${CTK_APPLICATIONS})
  388. ctkFunctionExtractOptionNameAndValue(${app} app_name app_value)
  389. OPTION(CTK_APP_${app_name} "Build ${app_name} Application." ${app_value})
  390. LIST(APPEND CTK_APPLICATIONS_SUBDIRS "${app_name}")
  391. ENDFOREACH()
  392. #-----------------------------------------------------------------------------
  393. # Generate target_directories list - List of directory corresponding to the different
  394. # libraries, plugins and applications associated with the corresponding option name.
  395. #
  396. # Create list of directories corresponding to the enabled targets
  397. SET(target_directories)
  398. FOREACH(lib ${CTK_LIBS_SUBDIRS})
  399. SET(option_name CTK_LIB_${lib})
  400. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}^^${option_name}")
  401. ENDFOREACH()
  402. FOREACH(plugin ${CTK_PLUGINS_SUBDIRS})
  403. SET(option_name CTK_PLUGIN_${plugin})
  404. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/${plugin}^^${option_name}")
  405. ENDFOREACH()
  406. FOREACH(app ${CTK_APPLICATIONS_SUBDIRS})
  407. SET(option_name CTK_APP_${app})
  408. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${app}^^${option_name}")
  409. ENDFOREACH()
  410. #MESSAGE(STATUS target_directories:${target_directories})
  411. #-----------------------------------------------------------------------------
  412. # Compile DGraph - An application allowing to check for cycle in DAG and also obtain the
  413. # topological order.
  414. TRY_COMPILE(RESULT_VAR ${CTK_BINARY_DIR}/Utilities/DGraph ${CTK_SOURCE_DIR}/Utilities/DGraph
  415. DGraph
  416. CMAKE_FLAGS
  417. -DQT_QMAKE_EXECUTABLE:BOOL=${QT_QMAKE_EXECUTABLE}
  418. -DCMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
  419. OUTPUT_VARIABLE output)
  420. IF(NOT RESULT_VAR)
  421. MESSAGE(FATAL_ERROR "Failed to compile DGraph application.\n${output}")
  422. ENDIF()
  423. FIND_PROGRAM(DGraph_EXECUTABLE DGraph
  424. "${CTK_BINARY_DIR}/Utilities/DGraph/"
  425. "${CTK_BINARY_DIR}/Utilities/DGraph/bin/"
  426. "${CTK_BINARY_DIR}/Utilities/DGraph/Debug/"
  427. "${CTK_BINARY_DIR}/Utilities/DGraph/Release/")
  428. MARK_AS_ADVANCED(DGraph_EXECUTABLE)
  429. #-----------------------------------------------------------------------------
  430. # Let's make sure the enabled/disabled libraries, plugins or applications are coherent
  431. #
  432. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}")
  433. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_EXTERNALS)
  434. ctkMacroValidateBuildOptions("${CTK_BINARY_DIR}" "${DGraph_EXECUTABLE}" "${target_directories}")
  435. #-----------------------------------------------------------------------------
  436. # CTK Python wrapping - Propose the option only if CTK_LIB_Scriping/Python/Core is ON
  437. IF(CTK_LIB_Scripting/Python/Core)
  438. find_package(PythonInterp)
  439. IF(NOT PYTHONINTERP_FOUND)
  440. MESSAGE(SEND_ERROR "PYTHON_EXECUTABLE variable should be set to build CTK_LIB_Scripting/Python")
  441. ENDIF()
  442. FIND_PACKAGE(PythonLibs)
  443. IF(NOT PYTHONLIBS_FOUND)
  444. MESSAGE(FATAL_ERROR "PYTHON_LIBRARIES and PYTHON_INCLUDE_DIRS should be set to build CTK_LIB_Scripting/Python")
  445. ENDIF()
  446. OPTION(CTK_WRAP_PYTHONQT_FULL "Experimental - Wrap CTK classes using Qt meta-object system into Python language" OFF)
  447. MARK_AS_ADVANCED(CTK_WRAP_PYTHONQT_FULL)
  448. OPTION(CTK_WRAP_PYTHONQT_LIGHT "Wrap CTK classes using Qt meta-object system into Python language" OFF)
  449. IF(CTK_WRAP_PYTHONQT_FULL AND CTK_WRAP_PYTHONQT_LIGHT)
  450. MESSAGE(SEND_ERROR "CTK_WRAP_PYTHONQT_{LIGHT,FULL} options are mutually exclusive. Please enable only one !")
  451. ENDIF()
  452. ELSE()
  453. # Note that an unset boolean variable is considered to be False
  454. UNSET(CTK_WRAP_PYTHONQT_FULL CACHE)
  455. UNSET(CTK_WRAP_PYTHONQT_LIGHT CACHE)
  456. ENDIF()
  457. #-----------------------------------------------------------------------------
  458. # DGraph
  459. #
  460. # Generate DGraph input file expected by DGraph
  461. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" WITH_OPTION)
  462. # Obtain list of target ordered topologically
  463. ctkMacroSetPaths("${QT_INSTALLED_LIBRARY_DIR}")
  464. EXECUTE_PROCESS(
  465. COMMAND "${DGraph_EXECUTABLE}" "${CTK_BINARY_DIR}/DGraphInput.txt"
  466. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  467. RESULT_VARIABLE RESULT_VAR
  468. OUTPUT_VARIABLE CTEST_PROJECT_SUBPROJECTS_OUTPUT
  469. ERROR_VARIABLE error
  470. OUTPUT_STRIP_TRAILING_WHITESPACE
  471. )
  472. IF(RESULT_VAR)
  473. MESSAGE(FATAL_ERROR "Failed to obtain list of target ordered topologically.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  474. ENDIF()
  475. # Convert 'CTEST_PROJECT_SUBPROJECTS_OUTPUT' to a list
  476. STRING(REPLACE " " "\\;" CTEST_PROJECT_SUBPROJECTS "${CTEST_PROJECT_SUBPROJECTS_OUTPUT}")
  477. SET(CTEST_PROJECT_SUBPROJECTS ${CTEST_PROJECT_SUBPROJECTS})
  478. # If the list of subproject is empty, let's at least build CTKCore
  479. LIST(LENGTH CTEST_PROJECT_SUBPROJECTS subproject_count)
  480. IF (subproject_count EQUAL 0)
  481. SET(CTEST_PROJECT_SUBPROJECTS CTKCore)
  482. ENDIF()
  483. # Configure CTestConfigSubProject.cmake used that could be used by CTest scripts
  484. CONFIGURE_FILE(${CTK_SOURCE_DIR}/CTestConfigSubProject.cmake.in
  485. ${CTK_BINARY_DIR}/CTestConfigSubProject.cmake)
  486. #-----------------------------------------------------------------------------
  487. # Project.xml
  488. #
  489. # Generate Project.xml file expected by the CTest driver script
  490. ctkFunctionGenerateProjectXml(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_directories}" ${CTK_SUPERBUILD})
  491. #-----------------------------------------------------------------------------
  492. # Superbuild script
  493. #
  494. IF(CTK_SUPERBUILD)
  495. INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  496. RETURN()
  497. ENDIF()
  498. #-----------------------------------------------------------------------------
  499. # Expand variables containing include and library directories for external projects
  500. # This relies on the variable EXTERNAL_TARGETS set in ctkMacroValidateBuildOptions
  501. FOREACH(_external_target ${EXTERNAL_TARGETS})
  502. IF(${_external_target}_FIND_PACKAGE_CMD)
  503. #MESSAGE("Calling FIND_PACKAGE(${${_external_target}_FIND_PACKAGE_CMD})")
  504. FIND_PACKAGE(${${_external_target}_FIND_PACKAGE_CMD} REQUIRED)
  505. ENDIF()
  506. ENDFOREACH()
  507. FOREACH(_external_target ${EXTERNAL_TARGETS})
  508. IF(${_external_target}_INCLUDE_DIRS)
  509. STRING(REPLACE "^" ";" _include_variable_list "${${_external_target}_INCLUDE_DIRS}")
  510. IF(_include_variable_list)
  511. #MESSAGE("[${_external_target}] Resolving include variables: ${${_external_target}_INCLUDE_DIRS}")
  512. SET(${_external_target}_INCLUDE_DIRS "")
  513. FOREACH(_include_variable ${_include_variable_list})
  514. #MESSAGE("[${_external_target}] Appending ${${_include_variable}}")
  515. IF(${_include_variable})
  516. LIST(APPEND ${_external_target}_INCLUDE_DIRS ${${_include_variable}})
  517. ELSE()
  518. LIST(APPEND ${_external_target}_INCLUDE_DIRS ${_include_variable})
  519. ENDIF()
  520. #MESSAGE("[${_external_target}] New dirs: ${${_external_target}_INCLUDE_DIRS}")
  521. ENDFOREACH()
  522. #MESSAGE("[${_external_target}] Appended dirs: ${${_external_target}_INCLUDE_DIRS}")
  523. ENDIF()
  524. ENDIF()
  525. IF(${_external_target}_LIBRARY_DIRS)
  526. STRING(REPLACE "^" ";" _library_variable_list "${${_external_target}_LIBRARY_DIRS}")
  527. IF(_library_variable_list)
  528. #MESSAGE("[${_external_target}] Resolving library variables: ${${_external_target}_LIBRARY_DIRS}")
  529. SET(${_external_target}_LIBRARY_DIRS "")
  530. FOREACH(_library_variable ${_library_variable_list})
  531. #MESSAGE("[${_external_target}] Appending ${${_library_variable}}")
  532. IF(${_library_variable})
  533. LIST(APPEND ${_external_target}_LIBRARY_DIRS ${${_library_variable}})
  534. ELSE()
  535. LIST(APPEND ${_external_target}_LIBRARY_DIRS ${_library_variable})
  536. ENDIF()
  537. #MESSAGE("[${_external_target}] New dirs: ${${_external_target}_LIBRARY_DIRS}")
  538. ENDFOREACH()
  539. #MESSAGE("[${_external_target}] Appended dirs: ${${_external_target}_LIBRARY_DIRS}")
  540. ENDIF()
  541. ENDIF()
  542. ENDFOREACH()
  543. # Since PYTHONQT_USE_VTK library option can be enabled independently of
  544. # Visualization/VTK/Core, let's make sure VTK has been properly discovered
  545. IF(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
  546. FIND_PACKAGE(VTK REQUIRED)
  547. ENDIF()
  548. SET(CTK_WRAP_PYTHONQT_USE_VTK ${CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK})
  549. #-----------------------------------------------------------------------------
  550. # CTK_SUPERBUILD_BINARY_DIR
  551. # If CTK_SUPERBUILD_BINARY_DIR isn't defined, it means CTK is *NOT* build using Superbuild.
  552. # In that specific case, CTK_SUPERBUILD_BINARY_DIR should default to CTK_BINARY_DIR
  553. IF(NOT DEFINED CTK_SUPERBUILD_BINARY_DIR)
  554. SET(CTK_SUPERBUILD_BINARY_DIR ${CTK_BINARY_DIR})
  555. ENDIF()
  556. #-----------------------------------------------------------------------------
  557. # Configure files with settings
  558. #
  559. CONFIGURE_FILE(${CTK_SOURCE_DIR}/UseCTK.cmake.in
  560. ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY IMMEDIATE)
  561. #-----------------------------------------------------------------------------
  562. # Set C/CXX Flags
  563. #
  564. SET(CMAKE_CXX_FLAGS ${CTK_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE)
  565. SET(CMAKE_C_FLAGS ${CTK_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE)
  566. #-----------------------------------------------------------------------------
  567. # Set the header template which defines custom export/import macros
  568. # for shared libraries
  569. #
  570. SET(CTK_EXPORT_HEADER_TEMPLATE "${CTK_SOURCE_DIR}/Libs/ctkExport.h.in")
  571. #-----------------------------------------------------------------------------
  572. # Add CTK library subdirectories
  573. #
  574. FOREACH(lib ${CTK_LIBS_SUBDIRS})
  575. IF (CTK_LIB_${lib})
  576. ADD_SUBDIRECTORY(Libs/${lib})
  577. ENDIF()
  578. ENDFOREACH()
  579. #-----------------------------------------------------------------------------
  580. # Add CTK plugin subdirectories
  581. #
  582. FOREACH(plugin ${CTK_PLUGINS_SUBDIRS})
  583. IF(CTK_PLUGIN_${plugin})
  584. ADD_SUBDIRECTORY(Plugins/${plugin})
  585. ENDIF()
  586. ENDFOREACH()
  587. #-----------------------------------------------------------------------------
  588. # Add CTK application subdirectories
  589. #
  590. FOREACH(app ${CTK_APPLICATIONS_SUBDIRS})
  591. IF (CTK_APP_${app})
  592. ADD_SUBDIRECTORY(Applications/${app})
  593. ENDIF()
  594. ENDFOREACH()
  595. IF(BUILD_TESTING)
  596. ADD_SUBDIRECTORY(Applications/Testing)
  597. ENDIF(BUILD_TESTING)
  598. #-----------------------------------------------------------------------------
  599. # Add general purpose subdirectories
  600. #
  601. #ADD_SUBDIRECTORY(Testing)
  602. #ADD_SUBDIRECTORY(Examples)
  603. #-----------------------------------------------------------------------------
  604. # Style Checking configuration
  605. #
  606. INCLUDE(Utilities/KWStyle/KWStyle.cmake)
  607. #---------------------------------------------------------------------------
  608. # Documentation
  609. #
  610. ADD_SUBDIRECTORY( Documentation )
  611. #-----------------------------------------------------------------------------
  612. # The commands in this directory are intended to be executed as
  613. # the end of the whole configuration process, as a "last step".
  614. # This directory is typically the last SUBDIRS in the main CMakeLists.txt.
  615. ADD_SUBDIRECTORY(Utilities/LastConfigureStep)