CMakeLists.txt 28 KB

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