CMakeLists.txt 27 KB

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