SuperBuild.cmake 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. #-----------------------------------------------------------------------------
  21. # Declare CTK_EXTERNAL_LIBRARY_DIRS variable - This variable stores
  22. # the library output directory associated with the different external project
  23. # It's then used in Utilities/LastConfigureStep/CTKGenerateCTKConfig.cmake to
  24. # configure CTKConfig.cmake.in
  25. # This variable would then be exposed to project building against CTK
  26. SET(CTK_EXTERNAL_LIBRARY_DIRS)
  27. #-----------------------------------------------------------------------------
  28. # Make sure ${CTK_BINARY_DIR}/CTK-build/bin exists
  29. # May be used by some external project to install libs (e.g QtMobility)
  30. IF(NOT EXISTS ${CTK_BINARY_DIR}/CTK-build/bin)
  31. FILE(MAKE_DIRECTORY ${CTK_BINARY_DIR}/CTK-build/bin)
  32. ENDIF()
  33. #-----------------------------------------------------------------------------
  34. # Git protocole option
  35. #
  36. option(CTK_USE_GIT_PROTOCOL "If behind a firewall turn this OFF to use http instead." ON)
  37. set(git_protocol "git")
  38. if(NOT CTK_USE_GIT_PROTOCOL)
  39. set(git_protocol "http")
  40. endif()
  41. #-----------------------------------------------------------------------------
  42. # Enable and setup External project global properties
  43. #
  44. INCLUDE(ExternalProject)
  45. INCLUDE(ctkMacroEmptyExternalProject)
  46. SET(ep_base "${CMAKE_BINARY_DIR}/CMakeExternals")
  47. SET_PROPERTY(DIRECTORY PROPERTY EP_BASE ${ep_base})
  48. SET(ep_install_dir ${ep_base}/Install)
  49. SET(ep_build_dir ${ep_base}/Build)
  50. SET(ep_source_dir ${ep_base}/Source)
  51. #SET(ep_parallelism_level)
  52. SET(ep_build_shared_libs ON)
  53. SET(ep_build_testing OFF)
  54. SET(ep_common_args
  55. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  56. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  57. -DBUILD_TESTING:BOOL=${ep_build_testing}
  58. )
  59. # Compute -G arg for configuring external projects with the same CMake generator:
  60. IF(CMAKE_EXTRA_GENERATOR)
  61. SET(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  62. ELSE()
  63. SET(gen "${CMAKE_GENERATOR}")
  64. ENDIF()
  65. # Use this value where semi-colons are needed in ep_add args:
  66. set(sep "^^")
  67. #-----------------------------------------------------------------------------
  68. # Collect CTK library target dependencies
  69. #
  70. ctkMacroCollectAllTargetLibraries("${CTK_LIBS_SUBDIRS}" "Libs" ALL_TARGET_LIBRARIES)
  71. ctkMacroCollectAllTargetLibraries("${CTK_PLUGINS_SUBDIRS}" "Plugins" ALL_TARGET_LIBRARIES)
  72. ctkMacroCollectAllTargetLibraries("${CTK_APPLICATIONS_SUBDIRS}" "Applications" ALL_TARGET_LIBRARIES)
  73. #MESSAGE(STATUS ALL_TARGET_LIBRARIES:${ALL_TARGET_LIBRARIES})
  74. #-----------------------------------------------------------------------------
  75. # Initialize NON_CTK_DEPENDENCIES variable
  76. #
  77. # Using the variable ALL_TARGET_LIBRARIES initialized above with the help
  78. # of the macro ctkMacroCollectAllTargetLibraries, let's get the list of all Non-CTK dependencies.
  79. # NON_CTK_DEPENDENCIES is expected by the macro ctkMacroShouldAddExternalProject
  80. ctkMacroGetAllNonCTKTargetLibraries("${ALL_TARGET_LIBRARIES}" NON_CTK_DEPENDENCIES)
  81. #MESSAGE(STATUS NON_CTK_DEPENDENCIES:${NON_CTK_DEPENDENCIES})
  82. #-----------------------------------------------------------------------------
  83. # Qt is expected to be setup by CTK/CMakeLists.txt just before it includes the SuperBuild script
  84. #
  85. #-----------------------------------------------------------------------------
  86. # Attempt to discover Doxygen so that DOXYGEN_EXECUTABLE is set to an appropriate default value
  87. #
  88. FIND_PACKAGE(Doxygen QUIET)
  89. #-----------------------------------------------------------------------------
  90. # ExternalProjects - Project should be topologically ordered
  91. #
  92. SET(external_projects
  93. CTKData
  94. Log4Qt
  95. KWStyle
  96. VTK
  97. PythonQt
  98. PythonQtGenerator # Should be added after PythonQt - See comment in CMakeExternals/PythonQtGenerator.cmake
  99. DCMTK
  100. ZMQ
  101. QtMobility
  102. QtSOAP
  103. OpenIGTLink
  104. XIP
  105. ITK
  106. )
  107. # This variable will contain the list of CMake variable specific to each external project
  108. # that should passed to CTK.
  109. # The item of this list should have the following form: -D<EP>_DIR:PATH=${<EP>_DIR}
  110. # where '<EP>' is an external project name.
  111. SET(CTK_SUPERBUILD_EP_ARGS)
  112. # Include external projects
  113. SET(dependency_args )
  114. FOREACH(p ${external_projects})
  115. INCLUDE(CMakeExternals/${p}.cmake)
  116. IF(${p}_enabling_variable)
  117. # Provides the include and library directories either directly or provides the variable name
  118. # used by the corresponding Find<package>.cmake files.
  119. # The top-level CMakeLists.txt file will expand the variable names if not in
  120. # superbuild mode. The include and library dirs are then used in
  121. # ctkMacroBuildApp, ctkMacroBuildLib, and ctkMacroBuildPlugin
  122. STRING(REPLACE ";" "^" _include_dirs "${${${p}_enabling_variable}_INCLUDE_DIRS}")
  123. LIST(APPEND dependency_args
  124. -D${${p}_enabling_variable}_INCLUDE_DIRS:STRING=${_include_dirs})
  125. STRING(REPLACE ";" "^" _library_dirs "${${${p}_enabling_variable}_LIBRARY_DIRS}")
  126. LIST(APPEND dependency_args
  127. -D${${p}_enabling_variable}_LIBRARY_DIRS:STRING=${_library_dirs})
  128. IF(${${p}_enabling_variable}_FIND_PACKAGE_CMD)
  129. LIST(APPEND dependency_args
  130. -D${${p}_enabling_variable}_FIND_PACKAGE_CMD:STRING=${${${p}_enabling_variable}_FIND_PACKAGE_CMD})
  131. ENDIF()
  132. ENDIF()
  133. ENDFOREACH()
  134. #MESSAGE("Superbuild args: ${dependency_args}")
  135. #-----------------------------------------------------------------------------
  136. # CTK Utilities
  137. #
  138. set(proj CTK-Utilities)
  139. ExternalProject_Add(${proj}
  140. DOWNLOAD_COMMAND ""
  141. CONFIGURE_COMMAND ""
  142. BUILD_COMMAND ""
  143. INSTALL_COMMAND ""
  144. DEPENDS
  145. # Mandatory dependencies
  146. ${Log4Qt_DEPENDS}
  147. # Optionnal dependencies
  148. ${CTKData_DEPENDS}
  149. ${QtMobility_DEPENDS}
  150. ${QtSOAP_DEPENDS}
  151. ${kwstyle_DEPENDS}
  152. ${DCMTK_DEPENDS}
  153. ${PythonQt_DEPENDS}
  154. ${PythonQtGenerator_DEPENDS}
  155. ${ZMQ_DEPENDS}
  156. ${OpenIGTLink_DEPENDS}
  157. ${VTK_DEPENDS}
  158. ${XIP_DEPENDS}
  159. ${ITK_DEPENDS}
  160. )
  161. #-----------------------------------------------------------------------------
  162. # Generate cmake variable name corresponding to Libs, Plugins and Applications
  163. #
  164. SET(ctk_libs_bool_vars)
  165. FOREACH(lib ${CTK_LIBS_SUBDIRS})
  166. LIST(APPEND ctk_libs_bool_vars CTK_LIB_${lib})
  167. ENDFOREACH()
  168. SET(ctk_plugins_bool_vars)
  169. FOREACH(plugin ${CTK_PLUGINS_SUBDIRS})
  170. LIST(APPEND ctk_plugins_bool_vars CTK_PLUGIN_${plugin})
  171. ENDFOREACH()
  172. SET(ctk_applications_bool_vars)
  173. FOREACH(app ${CTK_APPLICATIONS_SUBDIRS})
  174. LIST(APPEND ctk_applications_bool_vars CTK_APP_${app})
  175. ENDFOREACH()
  176. #-----------------------------------------------------------------------------
  177. # Set superbuild boolean args
  178. #
  179. SET(ctk_cmake_boolean_args
  180. BUILD_TESTING
  181. CTK_USE_KWSTYLE
  182. WITH_COVERAGE
  183. DOCUMENTATION_TARGET_IN_ALL
  184. CTEST_USE_LAUNCHERS
  185. CTK_WRAP_PYTHONQT_FULL
  186. CTK_WRAP_PYTHONQT_LIGHT
  187. ${ctk_libs_bool_vars}
  188. ${ctk_plugins_bool_vars}
  189. ${ctk_applications_bool_vars}
  190. ${ctk_lib_options_list}
  191. )
  192. SET(ctk_superbuild_boolean_args)
  193. FOREACH(ctk_cmake_arg ${ctk_cmake_boolean_args})
  194. LIST(APPEND ctk_superbuild_boolean_args -D${ctk_cmake_arg}:BOOL=${${ctk_cmake_arg}})
  195. ENDFOREACH()
  196. # MESSAGE("CMake args:")
  197. # FOREACH(arg ${ctk_superbuild_boolean_args})
  198. # MESSAGE(" ${arg}")
  199. # ENDFOREACH()
  200. #-----------------------------------------------------------------------------
  201. # CTK Configure
  202. #
  203. SET(proj CTK-Configure)
  204. ExternalProject_Add(${proj}
  205. DOWNLOAD_COMMAND ""
  206. CMAKE_GENERATOR ${gen}
  207. CMAKE_ARGS
  208. ${ctk_superbuild_boolean_args}
  209. -DCTK_SUPERBUILD:BOOL=OFF
  210. -DDOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  211. -DDOXYGEN_EXECUTABLE:FILEPATH=${DOXYGEN_EXECUTABLE}
  212. -DCTK_SUPERBUILD_BINARY_DIR:PATH=${CTK_BINARY_DIR}
  213. -DCTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
  214. -DCTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}
  215. -DCTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
  216. -DCTK_INSTALL_BIN_DIR:STRING=${CTK_INSTALL_BIN_DIR}
  217. -DCTK_INSTALL_LIB_DIR:STRING=${CTK_INSTALL_LIB_DIR}
  218. -DCTK_INSTALL_INCLUDE_DIR:STRING=${CTK_INSTALL_INCLUDE_DIR}
  219. -DCTK_INSTALL_DOC_DIR:STRING=${CTK_INSTALL_DOC_DIR}
  220. -DCTK_BUILD_SHARED_LIBS:BOOL=${CTK_BUILD_SHARED_LIBS}
  221. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  222. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  223. -DCTK_CXX_FLAGS:STRING=${CTK_CXX_FLAGS}
  224. -DCTK_C_FLAGS:STRING=${CTK_C_FLAGS}
  225. -DCTK_EXTERNAL_LIBRARY_DIRS:STRING=${CTK_EXTERNAL_LIBRARY_DIRS}
  226. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  227. ${CTK_SUPERBUILD_EP_ARGS}
  228. ${dependency_args}
  229. SOURCE_DIR ${CTK_SOURCE_DIR}
  230. BINARY_DIR ${CTK_BINARY_DIR}/CTK-build
  231. BUILD_COMMAND ""
  232. INSTALL_COMMAND ""
  233. DEPENDS
  234. "CTK-Utilities"
  235. )
  236. #-----------------------------------------------------------------------------
  237. # CTK
  238. #
  239. #MESSAGE(STATUS SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:${SUPERBUILD_EXCLUDE_CTKBUILD_TARGET})
  240. IF(NOT DEFINED SUPERBUILD_EXCLUDE_CTKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_CTKBUILD_TARGET)
  241. SET(proj CTK-build)
  242. ExternalProject_Add(${proj}
  243. DOWNLOAD_COMMAND ""
  244. CMAKE_GENERATOR ${gen}
  245. SOURCE_DIR ${CTK_SOURCE_DIR}
  246. BINARY_DIR CTK-build
  247. INSTALL_COMMAND ""
  248. DEPENDS
  249. "CTK-Configure"
  250. )
  251. ENDIF()
  252. #-----------------------------------------------------------------------------
  253. # Custom target allowing to drive the build of CTK project itself
  254. #
  255. ADD_CUSTOM_TARGET(CTK
  256. COMMAND ${CMAKE_COMMAND} --build ${CTK_BINARY_DIR}/CTK-build
  257. WORKING_DIRECTORY ${CTK_BINARY_DIR}/CTK-build
  258. )