SuperBuild.cmake 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. SET(cmake_version_required "2.8")
  21. SET(cmake_version_required_dash "2-8")
  22. CMAKE_MINIMUM_REQUIRED(VERSION ${cmake_version_required})
  23. #
  24. # CTK_KWSTYLE_EXECUTABLE
  25. # DCMTK_DIR
  26. # QT_QMAKE_EXECUTABLE
  27. # VTK_DIR
  28. # PYTHONQT_INSTALL_DIR
  29. # PYTHON_LIBRARY
  30. # PYTHON_INCLUDE_DIR
  31. #
  32. #-----------------------------------------------------------------------------
  33. # Enable and setup External project global properties
  34. #
  35. INCLUDE(ExternalProject)
  36. SET(ep_base "${CMAKE_BINARY_DIR}/CMakeExternals")
  37. SET_PROPERTY(DIRECTORY PROPERTY EP_BASE ${ep_base})
  38. SET(ep_install_dir ${ep_base}/Install)
  39. SET(ep_build_dir ${ep_base}/Build)
  40. SET(ep_source_dir ${ep_base}/Source)
  41. #SET(ep_parallelism_level)
  42. SET(ep_build_shared_libs ON)
  43. SET(ep_build_testing OFF)
  44. SET(ep_common_args
  45. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  46. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  47. -DBUILD_TESTING:BOOL=${ep_build_testing}
  48. )
  49. # Compute -G arg for configuring external projects with the same CMake generator:
  50. IF(CMAKE_EXTRA_GENERATOR)
  51. SET(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  52. ELSE()
  53. SET(gen "${CMAKE_GENERATOR}")
  54. ENDIF()
  55. # Use this value where semi-colons are needed in ep_add args:
  56. set(sep "^^")
  57. #-----------------------------------------------------------------------------
  58. # Update CMake module path
  59. #
  60. SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
  61. #-----------------------------------------------------------------------------
  62. # Collect CTK library target dependencies
  63. #
  64. ctkMacroCollectAllTargetLibraries("${CTK_LIBS_SUBDIRS}" "Libs" ALL_TARGET_LIBRARIES)
  65. ctkMacroCollectAllTargetLibraries("${CTK_PLUGINS_SUBDIRS}" "Plugins" ALL_TARGET_LIBRARIES)
  66. ctkMacroCollectAllTargetLibraries("${CTK_APPLICATIONS_SUBDIRS}" "Applications" ALL_TARGET_LIBRARIES)
  67. #MESSAGE(STATUS ALL_TARGET_LIBRARIES:${ALL_TARGET_LIBRARIES})
  68. #-----------------------------------------------------------------------------
  69. # Initialize NON_CTK_DEPENDENCIES variable
  70. #
  71. # Using the variable ALL_TARGET_LIBRARIES initialized above with the help
  72. # of the macro ctkMacroCollectAllTargetLibraries, let's get the list of all Non-CTK dependencies.
  73. # NON_CTK_DEPENDENCIES is expected by the macro ctkMacroShouldAddExternalProject
  74. ctkMacroGetAllNonCTKTargetLibraries("${ALL_TARGET_LIBRARIES}" NON_CTK_DEPENDENCIES)
  75. #MESSAGE(STATUS NON_CTK_DEPENDENCIES:${NON_CTK_DEPENDENCIES})
  76. #-----------------------------------------------------------------------------
  77. # Qt is expected to be setup by CTK/CMakeLists.txt just before it includes the SuperBuild script
  78. #
  79. #-----------------------------------------------------------------------------
  80. # ExternalProjects
  81. #
  82. SET(external_projects
  83. log4cpp
  84. KWStyle
  85. PythonQt
  86. DCMTK
  87. ZMQ
  88. QtMobility
  89. OpenIGTLink
  90. VTK
  91. XIP
  92. )
  93. # Include external projects
  94. FOREACH(p ${external_projects})
  95. INCLUDE(CMakeExternals/${p}.cmake)
  96. ENDFOREACH()
  97. #-----------------------------------------------------------------------------
  98. # CTK Utilities
  99. #
  100. set(proj CTK-Utilities)
  101. ExternalProject_Add(${proj}
  102. DOWNLOAD_COMMAND ""
  103. CONFIGURE_COMMAND ""
  104. BUILD_COMMAND ""
  105. INSTALL_COMMAND ""
  106. DEPENDS
  107. # Mandatory dependencies
  108. ${log4cpp_DEPENDS}
  109. # Optionnal dependencies
  110. ${QtMobility_DEPENDS}
  111. ${kwstyle_DEPENDS}
  112. ${DCMTK_DEPENDS}
  113. ${PythonQt_DEPENDS}
  114. ${ZMQ_DEPENDS}
  115. ${OpenIGTLink_DEPENDS}
  116. ${VTK_DEPENDS}
  117. ${XIP_DEPENDS}
  118. )
  119. #-----------------------------------------------------------------------------
  120. # Generate cmake variable name corresponding to Libs, Plugins and Applications
  121. #
  122. SET(ctk_libs_bool_vars)
  123. FOREACH(lib ${CTK_LIBS_SUBDIRS})
  124. LIST(APPEND ctk_libs_bool_vars CTK_LIB_${lib})
  125. ENDFOREACH()
  126. SET(ctk_plugins_bool_vars)
  127. FOREACH(plugin ${CTK_PLUGINS_SUBDIRS})
  128. LIST(APPEND ctk_plugins_bool_vars CTK_PLUGIN_${plugin})
  129. ENDFOREACH()
  130. SET(ctk_applications_bool_vars)
  131. FOREACH(app ${CTK_APPLICATIONS_SUBDIRS})
  132. LIST(APPEND ctk_applications_bool_vars CTK_APP_${app})
  133. ENDFOREACH()
  134. #-----------------------------------------------------------------------------
  135. # Convenient macro allowing to define superbuild arg
  136. #
  137. MACRO(ctk_set_superbuild_boolean_arg ctk_cmake_var)
  138. SET(superbuild_${ctk_cmake_var} ON)
  139. IF(DEFINED ${ctk_cmake_var} AND NOT ${ctk_cmake_var})
  140. SET(superbuild_${ctk_cmake_var} OFF)
  141. ENDIF()
  142. ENDMACRO()
  143. #-----------------------------------------------------------------------------
  144. # Set superbuild boolean args
  145. #
  146. SET(ctk_cmake_boolean_args
  147. BUILD_TESTING
  148. CTK_USE_KWSTYLE
  149. ${ctk_libs_bool_vars}
  150. ${ctk_plugins_bool_vars}
  151. ${ctk_applications_bool_vars}
  152. )
  153. SET(ctk_superbuild_boolean_args)
  154. FOREACH(ctk_cmake_arg ${ctk_cmake_boolean_args})
  155. ctk_set_superbuild_boolean_arg(${ctk_cmake_arg})
  156. LIST(APPEND ctk_superbuild_boolean_args -D${ctk_cmake_arg}:BOOL=${superbuild_${ctk_cmake_arg}})
  157. ENDFOREACH()
  158. # MESSAGE("CMake args:")
  159. # FOREACH(arg ${ctk_superbuild_boolean_args})
  160. # MESSAGE(" ${arg}")
  161. # ENDFOREACH()
  162. #-----------------------------------------------------------------------------
  163. # CTK Configure
  164. #
  165. SET(proj CTK-Configure)
  166. ExternalProject_Add(${proj}
  167. DOWNLOAD_COMMAND ""
  168. CMAKE_GENERATOR ${gen}
  169. CMAKE_ARGS
  170. ${ctk_superbuild_boolean_args}
  171. -DCTK_SUPERBUILD:BOOL=OFF
  172. -DWITH_COVERAGE:BOOL=${WITH_COVERAGE}
  173. -DCTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS}
  174. -DCTK_SUPERBUILD_BINARY_DIR:PATH=${CTK_BINARY_DIR}
  175. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  176. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  177. -DCTK_CXX_FLAGS:STRING=${CTK_CXX_FLAGS}
  178. -DCTK_C_FLAGS:STRING=${CTK_C_FLAGS}
  179. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  180. -DCTK_KWSTYLE_EXECUTABLE:FILEPATH=${CTK_KWSTYLE_EXECUTABLE}
  181. -DDCMTK_DIR:PATH=${DCMTK_DIR} # FindDCMTK expects DCMTK_DIR
  182. -DVTK_DIR:PATH=${VTK_DIR} # FindVTK expects VTK_DIR
  183. -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} # FindPythonQt expects PYTHON_INCLUDE_DIR
  184. -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} # FindPythonQt expects PYTHON_LIBRARY
  185. -DPYTHONQT_INSTALL_DIR:PATH=${PYTHONQT_INSTALL_DIR} # FindPythonQt expects PYTHONQT_INSTALL_DIR
  186. -Dlog4cpp_DIR:PATH=${log4cpp_DIR} # Findlog4cpp expects a log4cpp_DIR variable to be defined
  187. SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
  188. BINARY_DIR ${CMAKE_BINARY_DIR}/CTK-build
  189. BUILD_COMMAND ""
  190. INSTALL_COMMAND ""
  191. DEPENDS
  192. "CTK-Utilities"
  193. )
  194. #-----------------------------------------------------------------------------
  195. # CTK
  196. #
  197. #MESSAGE(STATUS SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:${SUPERBUILD_EXCLUDE_CTKBUILD_TARGET})
  198. IF(NOT DEFINED SUPERBUILD_EXCLUDE_CTKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_CTKBUILD_TARGET)
  199. SET(proj CTK-build)
  200. ExternalProject_Add(${proj}
  201. DOWNLOAD_COMMAND ""
  202. CMAKE_GENERATOR ${gen}
  203. SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
  204. BINARY_DIR CTK-build
  205. INSTALL_COMMAND ""
  206. DEPENDS
  207. "CTK-Configure"
  208. )
  209. ENDIF()
  210. #-----------------------------------------------------------------------------
  211. # Custom target allowing to drive the build of CTK project itself
  212. #
  213. ADD_CUSTOM_TARGET(CTK
  214. COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/CTK-build
  215. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CTK-build
  216. )