CMakeLists.txt 26 KB

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