CMakeLists.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
  2. #-----------------------------------------------------------------------------
  3. # See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
  4. #
  5. SET(project_policies
  6. CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
  7. CMP0002 # NEW: Logical target names must be globally unique.
  8. CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths.
  9. CMP0004 # NEW: Libraries linked may NOT have leading or trailing whitespace.
  10. CMP0005 # NEW: Preprocessor definition values are now escaped automatically.
  11. CMP0006 # NEW: Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
  12. CMP0007 # NEW: List command no longer ignores empty elements.
  13. CMP0008 # NEW: Libraries linked by full-path must have a valid library file name.
  14. CMP0009 # NEW: FILE GLOB_RECURSE calls should not follow symlinks by default.
  15. CMP0010 # NEW: Bad variable reference syntax is an error.
  16. CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
  17. CMP0012 # NEW: if() recognizes numbers and boolean constants.
  18. CMP0013 # NEW: Duplicate binary directories are not allowed.
  19. CMP0014 # NEW: Input directories must have CMakeLists.txt
  20. )
  21. FOREACH(policy ${project_policies})
  22. IF(POLICY ${policy})
  23. CMAKE_POLICY(SET ${policy} NEW)
  24. ENDIF()
  25. ENDFOREACH()
  26. #-----------------------------------------------------------------------------
  27. PROJECT(CTK)
  28. #-----------------------------------------------------------------------------
  29. # Default to shared library
  30. SET(CTK_LIBRARY_MODE "SHARED")
  31. SET(CTK_BUILD_SHARED_LIBS TRUE)
  32. #-----------------------------------------------------------------------------
  33. # Output directories.
  34. #
  35. IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  36. SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CTK_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
  37. ENDIF()
  38. IF(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  39. SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CTK_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
  40. ENDIF()
  41. #SET(CTK_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
  42. #SET(CTK_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
  43. #-----------------------------------------------------------------------------
  44. # Install directories, used for install rules.
  45. #
  46. SET(CTK_INSTALL_BIN_DIR "bin")
  47. SET(CTK_INSTALL_LIB_DIR "lib")
  48. SET(CTK_INSTALL_INCLUDE_DIR "include")
  49. SET(CTK_INSTALL_DOC_DIR "doc")
  50. #-----------------------------------------------------------------------------
  51. # CTK version number. An even minor number corresponds to releases.
  52. #
  53. SET(CTK_MAJOR_VERSION 0)
  54. SET(CTK_MINOR_VERSION 1)
  55. SET(CTK_BUILD_VERSION 0)
  56. SET(CTK_VERSION
  57. "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_BUILD_VERSION}")
  58. # Append the library version information to the library target
  59. # properties. A parent project may set its own properties and/or may
  60. # block this.
  61. IF(NOT CTK_NO_LIBRARY_VERSION)
  62. SET(CTK_LIBRARY_PROPERTIES ${CTK_LIBRARY_PROPERTIES}
  63. VERSION "${CTK_VERSION}"
  64. SOVERSION "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}"
  65. )
  66. ENDIF()
  67. #-----------------------------------------------------------------------------
  68. # Update CMake module path
  69. # Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
  70. #
  71. SET(CMAKE_MODULE_PATH
  72. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
  73. "${CMAKE_CURRENT_SOURCE_DIR}/CMake"
  74. ${CMAKE_MODULE_PATH})
  75. #-----------------------------------------------------------------------------
  76. # Clear CTK_BASE_INCLUDE_DIRS and CTK_BASE_LIBRARIES
  77. #
  78. SET(CTK_BASE_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
  79. SET(CTK_BASE_INCLUDE_DIRS CACHE INTERNAL "CTK includes" FORCE)
  80. #-----------------------------------------------------------------------------
  81. # CMake Macro(s)
  82. #
  83. INCLUDE(CMake/ctkMacroParseArguments.cmake)
  84. INCLUDE(CMake/ctkMacroListFilter.cmake)
  85. INCLUDE(CMake/ctkMacroBuildLib.cmake)
  86. INCLUDE(CMake/ctkMacroBuildPlugin.cmake)
  87. INCLUDE(CMake/ctkMacroBuildApp.cmake)
  88. INCLUDE(CMake/ctkMacroBuildQtDesignerPlugin.cmake)
  89. INCLUDE(CMake/ctkMacroSetupQt.cmake)
  90. INCLUDE(CMake/ctkMacroTargetLibraries.cmake) # Import multiple macros
  91. INCLUDE(CMake/ctkMacroAddCtkLibraryOptions.cmake)
  92. INCLUDE(CMake/ctkMacroGenerateDGraphInput.cmake)
  93. INCLUDE(CMake/ctkMacroGenerateProjectXml.cmake)
  94. # Used by CTKGenerateCTKConfig.cmake
  95. SET(CTK_CMAKE_DIR ${CTK_SOURCE_DIR}/CMake)
  96. SET(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
  97. #-----------------------------------------------------------------------------
  98. # Patch program
  99. #
  100. FIND_PROGRAM(CTK_PATCH_EXECUTABLE patch
  101. "C:/Program Files/GnuWin32/bin"
  102. "C:/Program Files (x86)/GnuWin32/bin")
  103. MARK_AS_ADVANCED(CTK_PATCH_EXECUTABLE)
  104. #-----------------------------------------------------------------------------
  105. # Testing
  106. #
  107. OPTION(BUILD_TESTING "Test the project" ON)
  108. IF(BUILD_TESTING)
  109. ENABLE_TESTING()
  110. INCLUDE(CTest)
  111. SET(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
  112. MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
  113. # Setup file for setting custom ctest vars
  114. CONFIGURE_FILE(
  115. CMake/CTestCustom.cmake.in
  116. ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
  117. @ONLY
  118. )
  119. # Configuration for the CMake-generated test driver
  120. SET(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include <stdexcept>")
  121. SET(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
  122. try
  123. {")
  124. SET(CMAKE_TESTDRIVER_AFTER_TESTMAIN " }
  125. catch( std::exception & excp )
  126. {
  127. fprintf(stderr,\"%s\\n\",excp.what());
  128. return EXIT_FAILURE;
  129. }
  130. catch( ... )
  131. {
  132. printf(\"Exception caught in the test driver\\n\");
  133. return EXIT_FAILURE;
  134. }
  135. ")
  136. ENDIF()
  137. #-----------------------------------------------------------------------------
  138. # Coverage
  139. #
  140. OPTION(WITH_COVERAGE "Enable/Disable coverage" OFF)
  141. #-----------------------------------------------------------------------------
  142. # Additional CXX/C Flags
  143. #
  144. SET(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
  145. MARK_AS_ADVANCED(ADDITIONAL_C_FLAGS)
  146. SET(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
  147. MARK_AS_ADVANCED(ADDITIONAL_CXX_FLAGS)
  148. #-----------------------------------------------------------------------------
  149. # Set symbol visibility Flags
  150. #
  151. IF(CMAKE_CXX_COMPILER_ID)
  152. # Set the default symbol visibility to hidden for gcc
  153. IF(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  154. SET(VISIBILITY_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
  155. ENDIF()
  156. ENDIF()
  157. #-----------------------------------------------------------------------------
  158. # Set coverage Flags
  159. #
  160. IF(WITH_COVERAGE)
  161. IF(CMAKE_CXX_COMPILER_ID AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  162. SET(coverage_flags "-g -fdiagnostics-show-option -fprofile-arcs -ftest-coverage -O3 -DNDEBUG")
  163. SET(COVERAGE_CXX_FLAGS ${coverage_flags})
  164. SET(COVERAGE_C_FLAGS ${coverage_flags})
  165. ENDIF()
  166. ENDIF()
  167. #-----------------------------------------------------------------------------
  168. # CTK C/CXX Flags
  169. #
  170. SET(CTK_C_FLAGS "${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
  171. SET(CTK_CXX_FLAGS "${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
  172. #-----------------------------------------------------------------------------
  173. # QT
  174. #
  175. ctkMacroSetupQt()
  176. # Update CTK_BASE_LIBRARIES with QT libraries
  177. IF(QT4_FOUND)
  178. SET(CTK_BASE_LIBRARIES ${CTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "CTK libraries" FORCE)
  179. ENDIF()
  180. #-----------------------------------------------------------------------------
  181. # CTK Libraries
  182. #
  183. SET(CTK_LIBS
  184. Core
  185. Widgets
  186. DICOM/Core
  187. DICOM/Widgets
  188. Scripting/Python/Core
  189. Visualization/VTK/Core
  190. Visualization/VTK/Widgets
  191. Visualization/XIP
  192. )
  193. #-----------------------------------------------------------------------------
  194. # CTK Plugins
  195. #
  196. SET(CTK_PLUGINS
  197. #org.commontk.cli
  198. )
  199. #-----------------------------------------------------------------------------
  200. # CTK Applications
  201. #
  202. SET(CTK_APPLICATIONS
  203. ctkDICOM
  204. ctkDICOMIndexer
  205. )
  206. #-----------------------------------------------------------------------------
  207. # To make options show up in both CTK-SuperBuild and CTK regular build, let's add them
  208. # before the SuperBuild script is included
  209. #
  210. # Let's mark as advanced some default properties
  211. MARK_AS_ADVANCED(CMAKE_INSTALL_PREFIX)
  212. MARK_AS_ADVANCED(DART_TESTING_TIMEOUT)
  213. # KWStyle
  214. OPTION(CTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
  215. #MARK_AS_ADVANCED(CTK_USE_KWSTYLE)
  216. #-----------------------------------------------------------------------------
  217. # Documentation
  218. OPTION( BUILD_DOCUMENTATION "Build Documentation" OFF )
  219. IF( BUILD_DOCUMENTATION )
  220. ADD_SUBDIRECTORY( Documentation )
  221. ENDIF( BUILD_DOCUMENTATION )
  222. #-----------------------------------------------------------------------------
  223. # Build options associated with CTK libraries
  224. # Note also that if
  225. # the file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake exists and look like:
  226. #
  227. # SET(ctk_library_options
  228. # OPT1:OFF
  229. # OPT2:ON
  230. # )
  231. #
  232. # In addition to 'CTK_LIB_<DIR>/<LIBNAME>' option, the following ones
  233. # will also be available in CMake configure menu:
  234. # CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
  235. # CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)
  236. #
  237. FOREACH(lib ${CTK_LIBS})
  238. OPTION(CTK_LIB_${lib} "Enable ${lib} Library." ON)
  239. ctkMacroAddCtkLibraryOptions(${lib})
  240. ENDFOREACH()
  241. # Build options associated with CTK plugins
  242. FOREACH(plugin ${CTK_PLUGINS})
  243. OPTION(CTK_PLUGIN_${plugin} "Build ${plugin} Plugin." ON)
  244. ENDFOREACH()
  245. # Build options associated with CTK applications
  246. FOREACH(app ${CTK_APPLICATIONS})
  247. OPTION(CTK_APP_${app} "Build ${app} Application." ON)
  248. ENDFOREACH()
  249. #-----------------------------------------------------------------------------
  250. # Superbuild Option - Enabled by default
  251. #
  252. OPTION(CTK_SUPERBUILD "Build CTK and the projects it depends on via SuperBuild.cmake." ON)
  253. MARK_AS_ADVANCED(CTK_SUPERBUILD)
  254. #-----------------------------------------------------------------------------
  255. # Project.xml
  256. #
  257. # Create list of directories corresponding to the enabled targets
  258. SET(target_directories)
  259. FOREACH(lib ${CTK_LIBS})
  260. SET(option_name CTK_LIB_${lib})
  261. IF(${${option_name}})
  262. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}^^${option_name}")
  263. ENDIF()
  264. ENDFOREACH()
  265. FOREACH(plugin ${CTK_PLUGINS})
  266. SET(option_name CTK_PLUGIN_${plugin})
  267. IF(${${option_name}})
  268. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/${plugin}^^${option_name}")
  269. ENDIF()
  270. ENDFOREACH()
  271. FOREACH(app ${CTK_APPLICATIONS})
  272. SET(option_name CTK_APP_${app})
  273. IF(${${option_name}})
  274. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${app}^^${option_name}")
  275. ENDIF()
  276. ENDFOREACH()
  277. #MESSAGE(STATUS target_directories:${target_directories})
  278. # Generate Project.xml file expected by the CTest driver script
  279. ctkMacroGenerateProjectXml(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_directories}" ${CTK_SUPERBUILD})
  280. #-----------------------------------------------------------------------------
  281. # DGraph
  282. #
  283. # Generate DGraph input file expected by DGraph
  284. ctkMacroGenerateDGraphInput(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_directories}")
  285. # Compile DGraph - An application allowing to check for cycle in DAG and also obtain the
  286. # topological order.
  287. TRY_COMPILE(RESULT_VAR ${CTK_BINARY_DIR}/Utilities/DGraph ${CTK_SOURCE_DIR}/Utilities/DGraph
  288. DGraph
  289. CMAKE_FLAGS
  290. -DQT_QMAKE_EXECUTABLE:BOOL=${QT_QMAKE_EXECUTABLE}
  291. -DCMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
  292. OUTPUT_VARIABLE output)
  293. IF(NOT RESULT_VAR)
  294. MESSAGE(FATAL_ERROR "Failed to compile DGraph application.\n${output}")
  295. ENDIF()
  296. FIND_PROGRAM(DGraph_EXECUTABLE DGraph
  297. "${CTK_BINARY_DIR}/Utilities/DGraph/"
  298. "${CTK_BINARY_DIR}/Utilities/DGraph/bin/"
  299. "${CTK_BINARY_DIR}/Utilities/DGraph/Debug/"
  300. "${CTK_BINARY_DIR}/Utilities/DGraph/Release/")
  301. MARK_AS_ADVANCED(DGraph_EXECUTABLE)
  302. # Obtain list of target ordered topologically
  303. EXECUTE_PROCESS(
  304. COMMAND ${DGraph_EXECUTABLE} ${CTK_BINARY_DIR}/DGraphInput.txt
  305. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  306. RESULT_VARIABLE RESULT_VAR
  307. OUTPUT_VARIABLE CTEST_PROJECT_SUBPROJECTS
  308. ERROR_VARIABLE error
  309. OUTPUT_STRIP_TRAILING_WHITESPACE
  310. )
  311. IF(RESULT_VAR)
  312. MESSAGE(FATAL_ERROR "Failed to obtain list of target ordered topologically.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  313. ENDIF()
  314. # Configure CTestConfigSubProject.cmake used that could be used by CTest scripts
  315. CONFIGURE_FILE(${CTK_SOURCE_DIR}/CTestConfigSubProject.cmake.in
  316. ${CTK_BINARY_DIR}/CTestConfigSubProject.cmake)
  317. #-----------------------------------------------------------------------------
  318. # Superbuild script
  319. #
  320. IF(CTK_SUPERBUILD)
  321. INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  322. RETURN()
  323. ENDIF()
  324. #-----------------------------------------------------------------------------
  325. # CTK_SUPERBUILD_BINARY_DIR
  326. # If CTK_SUPERBUILD_BINARY_DIR isn't defined, it means CTK is *NOT* build using Superbuild.
  327. # In that specific case, CTK_SUPERBUILD_BINARY_DIR should default to CTK_BINARY_DIR
  328. IF(NOT DEFINED CTK_SUPERBUILD_BINARY_DIR)
  329. SET(CTK_SUPERBUILD_BINARY_DIR ${CTK_BINARY_DIR})
  330. ENDIF()
  331. #-----------------------------------------------------------------------------
  332. # Configure files with settings
  333. #
  334. CONFIGURE_FILE(${CTK_SOURCE_DIR}/UseCTK.cmake.in
  335. ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY IMMEDIATE)
  336. #-----------------------------------------------------------------------------
  337. # Set C/CXX Flags
  338. #
  339. SET(CMAKE_CXX_FLAGS ${CTK_CXX_FLAGS})
  340. SET(CMAKE_C_FLAGS ${CTK_C_FLAGS})
  341. #-----------------------------------------------------------------------------
  342. # Add CTK library subdirectories
  343. #
  344. FOREACH(lib ${CTK_LIBS})
  345. IF (CTK_LIB_${lib})
  346. ADD_SUBDIRECTORY(Libs/${lib})
  347. ENDIF()
  348. ENDFOREACH()
  349. #-----------------------------------------------------------------------------
  350. # Add CTK plugin subdirectories
  351. #
  352. FOREACH(plugin ${CTK_PLUGINS})
  353. IF (CTK_PLUGIN_${plugin})
  354. ADD_SUBDIRECTORY(Plugins/${plugin})
  355. ENDIF()
  356. ENDFOREACH()
  357. #-----------------------------------------------------------------------------
  358. # Add CTK application subdirectories
  359. #
  360. FOREACH(app ${CTK_APPLICATIONS})
  361. IF (CTK_APP_${app})
  362. ADD_SUBDIRECTORY(Applications/${app})
  363. ENDIF()
  364. ENDFOREACH()
  365. #-----------------------------------------------------------------------------
  366. # Add general purpose subdirectories
  367. #
  368. #ADD_SUBDIRECTORY(Testing)
  369. #ADD_SUBDIRECTORY(Examples)
  370. #-----------------------------------------------------------------------------
  371. # Style Checking configuration
  372. #
  373. INCLUDE(Utilities/KWStyle/KWStyle.cmake)
  374. #-----------------------------------------------------------------------------
  375. # The commands in this directory are intended to be executed as
  376. # the end of the whole configuration process, as a "last step".
  377. # This directory is typically the last SUBDIRS in the main CMakeLists.txt.
  378. ADD_SUBDIRECTORY(Utilities/LastConfigureStep)