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