SuperBuild.cmake 12 KB

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