SuperBuild.cmake 11 KB

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