CMakeLists.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. IF(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  42. SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CTK_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
  43. ENDIF()
  44. #-----------------------------------------------------------------------------
  45. # Install directories, used for install rules.
  46. #
  47. SET(CTK_INSTALL_BIN_DIR "bin")
  48. SET(CTK_INSTALL_LIB_DIR "lib")
  49. SET(CTK_INSTALL_INCLUDE_DIR "include")
  50. SET(CTK_INSTALL_DOC_DIR "doc")
  51. #-----------------------------------------------------------------------------
  52. # CTK version number. An even minor number corresponds to releases.
  53. #
  54. SET(CTK_MAJOR_VERSION 0)
  55. SET(CTK_MINOR_VERSION 1)
  56. SET(CTK_BUILD_VERSION 0)
  57. SET(CTK_VERSION
  58. "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_BUILD_VERSION}")
  59. # Append the library version information to the library target
  60. # properties. A parent project may set its own properties and/or may
  61. # block this.
  62. IF(NOT CTK_NO_LIBRARY_VERSION)
  63. SET(CTK_LIBRARY_PROPERTIES ${CTK_LIBRARY_PROPERTIES}
  64. VERSION "${CTK_VERSION}"
  65. SOVERSION "${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}"
  66. )
  67. ENDIF()
  68. #-----------------------------------------------------------------------------
  69. # Update CMake module path
  70. # Note: FindXXX.cmake script specific to utility should be copied into Utilities/CMake
  71. #
  72. SET(CMAKE_MODULE_PATH
  73. "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/CMake"
  74. "${CMAKE_CURRENT_SOURCE_DIR}/CMake"
  75. ${CMAKE_MODULE_PATH})
  76. #-----------------------------------------------------------------------------
  77. # Clear CTK_BASE_INCLUDE_DIRS and CTK_BASE_LIBRARIES
  78. #
  79. SET(CTK_BASE_LIBRARIES CACHE INTERNAL "CTK libraries" FORCE)
  80. SET(CTK_BASE_INCLUDE_DIRS CACHE INTERNAL "CTK includes" FORCE)
  81. #-----------------------------------------------------------------------------
  82. # CMake Function(s) and Macro(s)
  83. #
  84. INCLUDE(CMake/ctkMacroParseArguments.cmake)
  85. INCLUDE(CMake/ctkMacroListFilter.cmake)
  86. INCLUDE(CMake/ctkMacroBuildLib.cmake)
  87. INCLUDE(CMake/ctkMacroBuildPlugin.cmake)
  88. INCLUDE(CMake/ctkMacroBuildApp.cmake)
  89. INCLUDE(CMake/ctkMacroBuildQtDesignerPlugin.cmake)
  90. INCLUDE(CMake/ctkMacroSetupQt.cmake)
  91. INCLUDE(CMake/ctkMacroTargetLibraries.cmake) # Import multiple macros
  92. INCLUDE(CMake/ctkFunctionExtractOptionNameAndValue.cmake)
  93. INCLUDE(CMake/ctkFunctionExecuteProcess.cmake)
  94. INCLUDE(CMake/ctkMacroValidateBuildOptions.cmake)
  95. INCLUDE(CMake/ctkMacroAddCtkLibraryOptions.cmake)
  96. INCLUDE(CMake/ctkFunctionGenerateDGraphInput.cmake)
  97. INCLUDE(CMake/ctkFunctionGenerateProjectXml.cmake)
  98. # Used by CTKGenerateCTKConfig.cmake
  99. SET(CTK_CMAKE_DIR ${CTK_SOURCE_DIR}/CMake)
  100. SET(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
  101. #-----------------------------------------------------------------------------
  102. # Patch program
  103. #
  104. FIND_PROGRAM(CTK_PATCH_EXECUTABLE patch
  105. "C:/Program Files/GnuWin32/bin"
  106. "C:/Program Files (x86)/GnuWin32/bin")
  107. MARK_AS_ADVANCED(CTK_PATCH_EXECUTABLE)
  108. #-----------------------------------------------------------------------------
  109. # Testing
  110. #
  111. OPTION(BUILD_TESTING "Test the project" ON)
  112. IF(BUILD_TESTING)
  113. ENABLE_TESTING()
  114. INCLUDE(CTest)
  115. SET(CPP_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  116. MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
  117. # Setup file for setting custom ctest vars
  118. CONFIGURE_FILE(
  119. CMake/CTestCustom.cmake.in
  120. ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
  121. @ONLY
  122. )
  123. # Configuration for the CMake-generated test driver
  124. SET(CMAKE_TESTDRIVER_EXTRA_INCLUDES "#include <stdexcept>")
  125. SET(CMAKE_TESTDRIVER_BEFORE_TESTMAIN "
  126. try
  127. {")
  128. SET(CMAKE_TESTDRIVER_AFTER_TESTMAIN " }
  129. catch( std::exception & excp )
  130. {
  131. fprintf(stderr,\"%s\\n\",excp.what());
  132. return EXIT_FAILURE;
  133. }
  134. catch( ... )
  135. {
  136. printf(\"Exception caught in the test driver\\n\");
  137. return EXIT_FAILURE;
  138. }
  139. ")
  140. ENDIF()
  141. #-----------------------------------------------------------------------------
  142. # Coverage
  143. #
  144. OPTION(WITH_COVERAGE "Enable/Disable coverage" OFF)
  145. #-----------------------------------------------------------------------------
  146. # Additional CXX/C Flags
  147. #
  148. SET(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
  149. MARK_AS_ADVANCED(ADDITIONAL_C_FLAGS)
  150. SET(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
  151. MARK_AS_ADVANCED(ADDITIONAL_CXX_FLAGS)
  152. #-----------------------------------------------------------------------------
  153. # Set symbol visibility Flags
  154. #
  155. IF(CMAKE_CXX_COMPILER_ID)
  156. # Set the default symbol visibility to hidden for gcc
  157. IF(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  158. SET(VISIBILITY_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
  159. ENDIF()
  160. ENDIF()
  161. #-----------------------------------------------------------------------------
  162. # Set coverage Flags
  163. #
  164. IF(WITH_COVERAGE)
  165. IF(CMAKE_CXX_COMPILER_ID AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  166. SET(coverage_flags "-g -fdiagnostics-show-option -fprofile-arcs -ftest-coverage -O3 -DNDEBUG")
  167. SET(COVERAGE_CXX_FLAGS ${coverage_flags})
  168. SET(COVERAGE_C_FLAGS ${coverage_flags})
  169. ENDIF()
  170. ENDIF()
  171. #-----------------------------------------------------------------------------
  172. # CTK C/CXX Flags
  173. #
  174. SET(CTK_C_FLAGS "${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
  175. SET(CTK_CXX_FLAGS "${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
  176. #-----------------------------------------------------------------------------
  177. # QT
  178. #
  179. ctkMacroSetupQt()
  180. # Update CTK_BASE_LIBRARIES with QT libraries
  181. IF(QT4_FOUND)
  182. SET(CTK_BASE_LIBRARIES ${CTK_BASE_LIBRARIES} ${QT_LIBRARIES} CACHE INTERNAL "CTK libraries" FORCE)
  183. ENDIF()
  184. #-----------------------------------------------------------------------------
  185. # CTK Libraries - Use ON or OFF to indicate if the library should be built by default
  186. #
  187. SET(CTK_LIBS
  188. Core:ON
  189. Widgets:OFF
  190. DICOM/Core:OFF
  191. DICOM/Widgets:OFF
  192. Scripting/Python/Core:OFF
  193. Scripting/Python/Widgets:OFF
  194. Visualization/VTK/Core:OFF
  195. Visualization/VTK/Widgets:OFF
  196. Visualization/XIP:OFF
  197. )
  198. #-----------------------------------------------------------------------------
  199. # CTK Plugins - Use ON or OFF to indicate if the plugin should be built by default
  200. #
  201. SET(CTK_PLUGINS
  202. #org.commontk.cli:OFF
  203. )
  204. #-----------------------------------------------------------------------------
  205. # CTK Applications - Use ON or OFF to indicate if the application should be built by default
  206. #
  207. SET(CTK_APPLICATIONS
  208. ctkDICOM:OFF
  209. ctkDICOMIndexer:OFF
  210. )
  211. #-----------------------------------------------------------------------------
  212. # To make options show up in both CTK-SuperBuild and CTK regular build, let's add them
  213. # before the SuperBuild script is included
  214. #
  215. # Let's mark as advanced some default properties
  216. MARK_AS_ADVANCED(CMAKE_INSTALL_PREFIX)
  217. MARK_AS_ADVANCED(DART_TESTING_TIMEOUT)
  218. # KWStyle
  219. OPTION(CTK_USE_KWSTYLE "Enable sourcecode-based style tests." OFF)
  220. #MARK_AS_ADVANCED(CTK_USE_KWSTYLE)
  221. #---------------------------------------------------------------------------
  222. # Documentation
  223. ADD_SUBDIRECTORY( Documentation )
  224. #---------------------------------------------------------------------------
  225. # Will contain a list of sub-directory without option ON or OFF
  226. #
  227. SET(CTK_LIBS_SUBDIRS )
  228. SET(CTK_PLUGINS_SUBDIRS )
  229. SET(CTK_APPLICATIONS_SUBDIRS )
  230. #-----------------------------------------------------------------------------
  231. # Build options associated with CTK libraries
  232. # Note also that if
  233. # the file Libs/<DIR>/<LIBNAME>/ctk_library_options.cmake exists and look like:
  234. #
  235. # SET(ctk_library_options
  236. # OPT1:OFF
  237. # OPT2:ON
  238. # )
  239. #
  240. # In addition to 'CTK_LIB_<DIR>/<LIBNAME>' option, the following ones
  241. # will also be available in CMake configure menu:
  242. # CTK_LIB_<DIR>/<LIBNAME>_OPT1 (set to OFF)
  243. # CTK_LIB_<DIR>/<LIBNAME>_OPT2 (set to ON)
  244. #
  245. FOREACH(lib ${CTK_LIBS})
  246. ctkFunctionExtractOptionNameAndValue(${lib} lib_name lib_value)
  247. OPTION(CTK_LIB_${lib_name} "Enable ${lib_name} Library." ${lib_value})
  248. ctkMacroAddCtkLibraryOptions(${lib_name})
  249. LIST(APPEND CTK_LIBS_SUBDIRS "${lib_name}")
  250. ENDFOREACH()
  251. # Build options associated with CTK plugins
  252. FOREACH(plugin ${CTK_PLUGINS})
  253. ctkFunctionExtractOptionNameAndValue(${plugin} plugin_name plugin_value)
  254. OPTION(CTK_PLUGIN_${plugin_name} "Build ${plugin_name} Plugin." ${plugin_value})
  255. LIST(APPEND CTK_PLUGINS_SUBDIRS "${plugin_name}")
  256. ENDFOREACH()
  257. # Build options associated with CTK applications
  258. FOREACH(app ${CTK_APPLICATIONS})
  259. ctkFunctionExtractOptionNameAndValue(${app} app_name app_value)
  260. OPTION(CTK_APP_${app_name} "Build ${app_name} Application." ${app_value})
  261. LIST(APPEND CTK_APPLICATIONS_SUBDIRS "${app_name}")
  262. ENDFOREACH()
  263. #-----------------------------------------------------------------------------
  264. # Superbuild Option - Enabled by default
  265. #
  266. OPTION(CTK_SUPERBUILD "Build CTK and the projects it depends on via SuperBuild.cmake." ON)
  267. MARK_AS_ADVANCED(CTK_SUPERBUILD)
  268. #-----------------------------------------------------------------------------
  269. # Generate target_directories list - List of directory corresponding to the different
  270. # libraries, plugins and applications associated with the corresponding option name.
  271. #
  272. # Create list of directories corresponding to the enabled targets
  273. SET(target_directories)
  274. FOREACH(lib ${CTK_LIBS_SUBDIRS})
  275. SET(option_name CTK_LIB_${lib})
  276. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Libs/${lib}^^${option_name}")
  277. ENDFOREACH()
  278. FOREACH(plugin ${CTK_PLUGINS_SUBDIRS})
  279. SET(option_name CTK_PLUGIN_${plugin})
  280. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Plugins/${plugin}^^${option_name}")
  281. ENDFOREACH()
  282. FOREACH(app ${CTK_APPLICATIONS_SUBDIRS})
  283. SET(option_name CTK_APP_${app})
  284. LIST(APPEND target_directories "${CMAKE_CURRENT_SOURCE_DIR}/Applications/${app}^^${option_name}")
  285. ENDFOREACH()
  286. #MESSAGE(STATUS target_directories:${target_directories})
  287. #-----------------------------------------------------------------------------
  288. # Compile DGraph - An application allowing to check for cycle in DAG and also obtain the
  289. # topological order.
  290. TRY_COMPILE(RESULT_VAR ${CTK_BINARY_DIR}/Utilities/DGraph ${CTK_SOURCE_DIR}/Utilities/DGraph
  291. DGraph
  292. CMAKE_FLAGS
  293. -DQT_QMAKE_EXECUTABLE:BOOL=${QT_QMAKE_EXECUTABLE}
  294. -DCMAKE_VERBOSE_MAKEFILE:BOOL=FALSE
  295. OUTPUT_VARIABLE output)
  296. IF(NOT RESULT_VAR)
  297. MESSAGE(FATAL_ERROR "Failed to compile DGraph application.\n${output}")
  298. ENDIF()
  299. FIND_PROGRAM(DGraph_EXECUTABLE DGraph
  300. "${CTK_BINARY_DIR}/Utilities/DGraph/"
  301. "${CTK_BINARY_DIR}/Utilities/DGraph/bin/"
  302. "${CTK_BINARY_DIR}/Utilities/DGraph/Debug/"
  303. "${CTK_BINARY_DIR}/Utilities/DGraph/Release/")
  304. MARK_AS_ADVANCED(DGraph_EXECUTABLE)
  305. #-----------------------------------------------------------------------------
  306. # Let's make sure the enabled/disabled libraries, plugins or applications are coherent
  307. #
  308. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" FALSE)
  309. ctkMacroValidateBuildOptions("${CTK_BINARY_DIR}" "${DGraph_EXECUTABLE}" "${target_directories}")
  310. #-----------------------------------------------------------------------------
  311. # DGraph
  312. #
  313. # Generate DGraph input file expected by DGraph
  314. ctkFunctionGenerateDGraphInput(${CTK_BINARY_DIR} "${target_directories}" TRUE)
  315. # Obtain list of target ordered topologically
  316. ctkFunctionExecuteProcess(
  317. COMMAND "${DGraph_EXECUTABLE}" "${CTK_BINARY_DIR}/DGraphInput.txt"
  318. PATH_LIST \"${QT_INSTALLED_LIBRARY_DIR}\"
  319. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  320. RESULT_VARIABLE RESULT_VAR
  321. OUTPUT_VARIABLE CTEST_PROJECT_SUBPROJECTS
  322. ERROR_VARIABLE error
  323. OUTPUT_STRIP_TRAILING_WHITESPACE
  324. )
  325. IF(RESULT_VAR)
  326. MESSAGE(FATAL_ERROR "Failed to obtain list of target ordered topologically.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  327. ENDIF()
  328. # If the list of subproject is empty, let's at least build CTKCore
  329. LIST(LENGTH CTEST_PROJECT_SUBPROJECTS subproject_count)
  330. IF (subproject_count EQUAL 0)
  331. SET(CTEST_PROJECT_SUBPROJECTS CTKCore)
  332. ENDIF()
  333. # Configure CTestConfigSubProject.cmake used that could be used by CTest scripts
  334. CONFIGURE_FILE(${CTK_SOURCE_DIR}/CTestConfigSubProject.cmake.in
  335. ${CTK_BINARY_DIR}/CTestConfigSubProject.cmake)
  336. #-----------------------------------------------------------------------------
  337. # Project.xml
  338. #
  339. # Generate Project.xml file expected by the CTest driver script
  340. ctkFunctionGenerateProjectXml(${CTK_BINARY_DIR} ${PROJECT_NAME} "${target_directories}" ${CTK_SUPERBUILD})
  341. #-----------------------------------------------------------------------------
  342. # Superbuild script
  343. #
  344. IF(CTK_SUPERBUILD)
  345. INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  346. RETURN()
  347. ENDIF()
  348. #-----------------------------------------------------------------------------
  349. # CTK_SUPERBUILD_BINARY_DIR
  350. # If CTK_SUPERBUILD_BINARY_DIR isn't defined, it means CTK is *NOT* build using Superbuild.
  351. # In that specific case, CTK_SUPERBUILD_BINARY_DIR should default to CTK_BINARY_DIR
  352. IF(NOT DEFINED CTK_SUPERBUILD_BINARY_DIR)
  353. SET(CTK_SUPERBUILD_BINARY_DIR ${CTK_BINARY_DIR})
  354. ENDIF()
  355. #-----------------------------------------------------------------------------
  356. # Configure files with settings
  357. #
  358. CONFIGURE_FILE(${CTK_SOURCE_DIR}/UseCTK.cmake.in
  359. ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY IMMEDIATE)
  360. #-----------------------------------------------------------------------------
  361. # Set C/CXX Flags
  362. #
  363. SET(CMAKE_CXX_FLAGS ${CTK_CXX_FLAGS})
  364. SET(CMAKE_C_FLAGS ${CTK_C_FLAGS})
  365. #-----------------------------------------------------------------------------
  366. # Add CTK library subdirectories
  367. #
  368. FOREACH(lib ${CTK_LIBS_SUBDIRS})
  369. IF (CTK_LIB_${lib})
  370. ADD_SUBDIRECTORY(Libs/${lib})
  371. ENDIF()
  372. ENDFOREACH()
  373. #-----------------------------------------------------------------------------
  374. # Add CTK plugin subdirectories
  375. #
  376. FOREACH(plugin ${CTK_PLUGINS_SUBDIRS})
  377. IF (CTK_PLUGIN_${plugin})
  378. ADD_SUBDIRECTORY(Plugins/${plugin})
  379. ENDIF()
  380. ENDFOREACH()
  381. #-----------------------------------------------------------------------------
  382. # Add CTK application subdirectories
  383. #
  384. FOREACH(app ${CTK_APPLICATIONS_SUBDIRS})
  385. IF (CTK_APP_${app})
  386. ADD_SUBDIRECTORY(Applications/${app})
  387. ENDIF()
  388. ENDFOREACH()
  389. #-----------------------------------------------------------------------------
  390. # Add general purpose subdirectories
  391. #
  392. #ADD_SUBDIRECTORY(Testing)
  393. #ADD_SUBDIRECTORY(Examples)
  394. #-----------------------------------------------------------------------------
  395. # Style Checking configuration
  396. #
  397. INCLUDE(Utilities/KWStyle/KWStyle.cmake)
  398. #-----------------------------------------------------------------------------
  399. # The commands in this directory are intended to be executed as
  400. # the end of the whole configuration process, as a "last step".
  401. # This directory is typically the last SUBDIRS in the main CMakeLists.txt.
  402. ADD_SUBDIRECTORY(Utilities/LastConfigureStep)