SuperBuild.cmake 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) 2010 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. SET(ep_base "${CMAKE_BINARY_DIR}/CMakeExternals")
  55. SET_PROPERTY(DIRECTORY PROPERTY EP_BASE ${ep_base})
  56. SET(ep_install_dir ${ep_base}/Install)
  57. SET(ep_build_dir ${ep_base}/Build)
  58. SET(ep_source_dir ${ep_base}/Source)
  59. #SET(ep_parallelism_level)
  60. SET(ep_build_shared_libs ON)
  61. SET(ep_build_testing OFF)
  62. SET(ep_common_args
  63. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  64. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  65. -DBUILD_TESTING:BOOL=${ep_build_testing}
  66. )
  67. # Compute -G arg for configuring external projects with the same CMake generator:
  68. IF(CMAKE_EXTRA_GENERATOR)
  69. SET(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  70. ELSE()
  71. SET(gen "${CMAKE_GENERATOR}")
  72. ENDIF()
  73. # Use this value where semi-colons are needed in ep_add args:
  74. set(sep "^^")
  75. #-----------------------------------------------------------------------------
  76. # Collect CTK library target dependencies
  77. #
  78. ctkMacroCollectAllTargetLibraries("${CTK_LIBS_SUBDIRS}" "Libs" ALL_TARGET_LIBRARIES)
  79. ctkMacroCollectAllTargetLibraries("${CTK_PLUGINS_SUBDIRS}" "Plugins" ALL_TARGET_LIBRARIES)
  80. ctkMacroCollectAllTargetLibraries("${CTK_APPLICATIONS_SUBDIRS}" "Applications" ALL_TARGET_LIBRARIES)
  81. #MESSAGE(STATUS ALL_TARGET_LIBRARIES:${ALL_TARGET_LIBRARIES})
  82. #-----------------------------------------------------------------------------
  83. # Initialize NON_CTK_DEPENDENCIES variable
  84. #
  85. # Using the variable ALL_TARGET_LIBRARIES initialized above with the help
  86. # of the macro ctkMacroCollectAllTargetLibraries, let's get the list of all Non-CTK dependencies.
  87. # NON_CTK_DEPENDENCIES is expected by the macro ctkMacroShouldAddExternalProject
  88. ctkMacroGetAllNonCTKTargetLibraries("${ALL_TARGET_LIBRARIES}" NON_CTK_DEPENDENCIES)
  89. #MESSAGE(STATUS NON_CTK_DEPENDENCIES:${NON_CTK_DEPENDENCIES})
  90. #-----------------------------------------------------------------------------
  91. # Qt is expected to be setup by CTK/CMakeLists.txt just before it includes the SuperBuild script
  92. #
  93. #-----------------------------------------------------------------------------
  94. # ExternalProjects
  95. #
  96. SET(external_projects
  97. CTKData
  98. Log4Qt
  99. KWStyle
  100. PythonQt
  101. PythonQtGenerator # Should be added after PythonQt - See comment in CMakeExternals/PythonQtGenerator.cmake
  102. DCMTK
  103. ZMQ
  104. QtMobility
  105. QtSOAP
  106. OpenIGTLink
  107. VTK
  108. XIP
  109. )
  110. # Include external projects
  111. FOREACH(p ${external_projects})
  112. INCLUDE(CMakeExternals/${p}.cmake)
  113. ENDFOREACH()
  114. #-----------------------------------------------------------------------------
  115. # CTK Utilities
  116. #
  117. set(proj CTK-Utilities)
  118. ExternalProject_Add(${proj}
  119. DOWNLOAD_COMMAND ""
  120. CONFIGURE_COMMAND ""
  121. BUILD_COMMAND ""
  122. INSTALL_COMMAND ""
  123. DEPENDS
  124. # Mandatory dependencies
  125. ${Log4Qt_DEPENDS}
  126. # Optionnal dependencies
  127. ${CTKData_DEPENDS}
  128. ${QtMobility_DEPENDS}
  129. ${QtSOAP_DEPENDS}
  130. ${kwstyle_DEPENDS}
  131. ${DCMTK_DEPENDS}
  132. ${PythonQt_DEPENDS}
  133. ${PythonQtGenerator_DEPENDS}
  134. ${ZMQ_DEPENDS}
  135. ${OpenIGTLink_DEPENDS}
  136. ${VTK_DEPENDS}
  137. ${XIP_DEPENDS}
  138. )
  139. #-----------------------------------------------------------------------------
  140. # Generate cmake variable name corresponding to Libs, Plugins and Applications
  141. #
  142. SET(ctk_libs_bool_vars)
  143. FOREACH(lib ${CTK_LIBS_SUBDIRS})
  144. LIST(APPEND ctk_libs_bool_vars CTK_LIB_${lib})
  145. ENDFOREACH()
  146. SET(ctk_plugins_bool_vars)
  147. FOREACH(plugin ${CTK_PLUGINS_SUBDIRS})
  148. LIST(APPEND ctk_plugins_bool_vars CTK_PLUGIN_${plugin})
  149. ENDFOREACH()
  150. SET(ctk_applications_bool_vars)
  151. FOREACH(app ${CTK_APPLICATIONS_SUBDIRS})
  152. LIST(APPEND ctk_applications_bool_vars CTK_APP_${app})
  153. ENDFOREACH()
  154. #-----------------------------------------------------------------------------
  155. # Set superbuild boolean args
  156. #
  157. SET(ctk_cmake_boolean_args
  158. BUILD_TESTING
  159. CTK_USE_KWSTYLE
  160. WITH_COVERAGE
  161. DOCUMENTATION_TARGET_IN_ALL
  162. CTEST_USE_LAUNCHERS
  163. CTK_WRAP_PYTHONQT_FULL
  164. CTK_WRAP_PYTHONQT_LIGHT
  165. ${ctk_libs_bool_vars}
  166. ${ctk_plugins_bool_vars}
  167. ${ctk_applications_bool_vars}
  168. ${ctk_lib_options_list}
  169. )
  170. SET(ctk_superbuild_boolean_args)
  171. FOREACH(ctk_cmake_arg ${ctk_cmake_boolean_args})
  172. LIST(APPEND ctk_superbuild_boolean_args -D${ctk_cmake_arg}:BOOL=${${ctk_cmake_arg}})
  173. ENDFOREACH()
  174. # MESSAGE("CMake args:")
  175. # FOREACH(arg ${ctk_superbuild_boolean_args})
  176. # MESSAGE(" ${arg}")
  177. # ENDFOREACH()
  178. #-----------------------------------------------------------------------------
  179. # CTK Configure
  180. #
  181. SET(proj CTK-Configure)
  182. ExternalProject_Add(${proj}
  183. DOWNLOAD_COMMAND ""
  184. CMAKE_GENERATOR ${gen}
  185. CMAKE_ARGS
  186. ${ctk_superbuild_boolean_args}
  187. -DCTK_SUPERBUILD:BOOL=OFF
  188. -DDOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  189. -DCTK_SUPERBUILD_BINARY_DIR:PATH=${CTK_BINARY_DIR}
  190. -DCTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
  191. -DCTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}
  192. -DCTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
  193. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  194. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  195. -DCTK_CXX_FLAGS:STRING=${CTK_CXX_FLAGS}
  196. -DCTK_C_FLAGS:STRING=${CTK_C_FLAGS}
  197. -DCTK_EXTERNAL_LIBRARY_DIRS:STRING=${CTK_EXTERNAL_LIBRARY_DIRS}
  198. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  199. # External projects
  200. -DCTKData_DIR:PATH=${CTKData_DIR}
  201. -DZMQ_DIR:PATH=${ZMQ_DIR} # FindVTK expects VTK_DIR variable to be defined
  202. -DOpenIGTLink_DIR:PATH=${OpenIGTLink_DIR} # FindOpenIGTLink expects OpenIGTLink_DIR variable to be defined
  203. -DCTK_KWSTYLE_EXECUTABLE:FILEPATH=${CTK_KWSTYLE_EXECUTABLE}
  204. -DDCMTK_DIR:PATH=${DCMTK_DIR} # FindDCMTK expects DCMTK_DIR variable to be defined
  205. -DVTK_DIR:PATH=${VTK_DIR} # FindVTK expects VTK_DIR variable to be defined
  206. -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} # FindPythonInterp expects PYTHON_EXECUTABLE variable to be defined
  207. -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} # FindPythonQt expects PYTHON_INCLUDE_DIR variable to be defined
  208. -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} # FindPythonQt expects PYTHON_LIBRARY variable to be defined
  209. -DPYTHONQT_INSTALL_DIR:PATH=${PYTHONQT_INSTALL_DIR} # FindPythonQt expects PYTHONQT_INSTALL_DIR variable to be defined
  210. -DPYTHONQTGENERATOR_EXECUTABLE:FILEPATH=${PYTHONQTGENERATOR_EXECUTABLE} #FindPythonQtGenerator expects PYTHONQTGENERATOR_EXECUTABLE to be defined
  211. -DLog4Qt_DIR:PATH=${Log4Qt_DIR} # FindLog4Qt expects Log4Qt_DIR variable to be defined
  212. -DQtSOAP_DIR:PATH=${QtSOAP_DIR} # FindQtSOAP expects QtSOAP_DIR variable to be defined
  213. SOURCE_DIR ${CTK_SOURCE_DIR}
  214. BINARY_DIR ${CTK_BINARY_DIR}/CTK-build
  215. BUILD_COMMAND ""
  216. INSTALL_COMMAND ""
  217. DEPENDS
  218. "CTK-Utilities"
  219. )
  220. #-----------------------------------------------------------------------------
  221. # CTK
  222. #
  223. #MESSAGE(STATUS SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:${SUPERBUILD_EXCLUDE_CTKBUILD_TARGET})
  224. IF(NOT DEFINED SUPERBUILD_EXCLUDE_CTKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_CTKBUILD_TARGET)
  225. SET(proj CTK-build)
  226. ExternalProject_Add(${proj}
  227. DOWNLOAD_COMMAND ""
  228. CMAKE_GENERATOR ${gen}
  229. SOURCE_DIR ${CTK_SOURCE_DIR}
  230. BINARY_DIR CTK-build
  231. INSTALL_COMMAND ""
  232. DEPENDS
  233. "CTK-Configure"
  234. )
  235. ENDIF()
  236. #-----------------------------------------------------------------------------
  237. # Custom target allowing to drive the build of CTK project itself
  238. #
  239. ADD_CUSTOM_TARGET(CTK
  240. COMMAND ${CMAKE_COMMAND} --build ${CTK_BINARY_DIR}/CTK-build
  241. WORKING_DIRECTORY ${CTK_BINARY_DIR}/CTK-build
  242. )