SuperBuild.cmake 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. # WARNING - No change should be required after this comment
  22. # when you are adding a new external project dependency.
  23. #-----------------------------------------------------------------------------
  24. #-----------------------------------------------------------------------------
  25. # Declare CTK_EXTERNAL_LIBRARY_DIRS variable - This variable stores
  26. # the library output directory associated with the different external project
  27. # It's then used in Utilities/LastConfigureStep/CTKGenerateCTKConfig.cmake to
  28. # configure CTKConfig.cmake.in
  29. # This variable would then be exposed to project building against CTK
  30. set(CTK_EXTERNAL_LIBRARY_DIRS)
  31. #-----------------------------------------------------------------------------
  32. # Make sure ${CTK_BINARY_DIR}/CTK-build/bin exists
  33. # May be used by some external project to install libs
  34. if(NOT EXISTS ${CTK_BINARY_DIR}/CTK-build/bin)
  35. file(MAKE_DIRECTORY ${CTK_BINARY_DIR}/CTK-build/bin)
  36. endif()
  37. #-----------------------------------------------------------------------------
  38. # Qt is expected to be setup by CTK/CMakeLists.txt just before it includes the SuperBuild script
  39. #
  40. #-----------------------------------------------------------------------------
  41. # Attempt to discover Doxygen so that DOXYGEN_EXECUTABLE is set to an appropriate default value
  42. #
  43. find_package(Doxygen QUIET)
  44. #-----------------------------------------------------------------------------
  45. # Generate cmake variable name corresponding to Libs, Plugins and Applications
  46. #
  47. set(ctk_libs_bool_vars)
  48. foreach(lib ${CTK_LIBS})
  49. list(APPEND ctk_libs_bool_vars CTK_LIB_${lib})
  50. endforeach()
  51. set(ctk_plugins_bool_vars)
  52. foreach(plugin ${CTK_PLUGINS})
  53. list(APPEND ctk_plugins_bool_vars CTK_PLUGIN_${plugin})
  54. endforeach()
  55. set(ctk_applications_bool_vars)
  56. foreach(app ${CTK_APPS})
  57. list(APPEND ctk_applications_bool_vars CTK_APP_${app})
  58. endforeach()
  59. #-----------------------------------------------------------------------------
  60. # Set superbuild boolean args
  61. #
  62. set(ctk_cmake_boolean_args
  63. BUILD_TESTING
  64. CTK_BUILD_QTDESIGNER_PLUGINS
  65. CTK_USE_KWSTYLE
  66. WITH_COVERAGE
  67. DOCUMENTATION_TARGET_IN_ALL
  68. CTEST_USE_LAUNCHERS
  69. CTK_WRAP_PYTHONQT_FULL
  70. CTK_WRAP_PYTHONQT_LIGHT
  71. ${ctk_libs_bool_vars}
  72. ${ctk_plugins_bool_vars}
  73. ${ctk_applications_bool_vars}
  74. ${ctk_lib_options_list}
  75. )
  76. set(ctk_superbuild_boolean_args)
  77. foreach(ctk_cmake_arg ${ctk_cmake_boolean_args})
  78. list(APPEND ctk_superbuild_boolean_args -D${ctk_cmake_arg}:BOOL=${${ctk_cmake_arg}})
  79. endforeach()
  80. # message("CMake boolean args:")
  81. # foreach(arg ${ctk_superbuild_boolean_args})
  82. # message(" ${arg}")
  83. # endforeach()
  84. #-----------------------------------------------------------------------------
  85. # Expand superbuild external project args
  86. #
  87. set(CTK_SUPERBUILD_EP_ARGS)
  88. set(CTK_SUPERBUILD_EP_VARNAMES)
  89. foreach(arg ${CTK_SUPERBUILD_EP_VARS})
  90. string(REPLACE ":" ";" varname_and_vartype ${arg})
  91. set(target_info_list ${target_info_list})
  92. list(GET varname_and_vartype 0 _varname)
  93. list(GET varname_and_vartype 1 _vartype)
  94. list(APPEND CTK_SUPERBUILD_EP_ARGS -D${_varname}:${_vartype}=${${_varname}})
  95. list(APPEND CTK_SUPERBUILD_EP_VARNAMES ${_varname})
  96. endforeach()
  97. string(REPLACE ";" "^" CTK_SUPERBUILD_EP_VARNAMES "${CTK_SUPERBUILD_EP_VARNAMES}")
  98. # message("CMake external project args:")
  99. # foreach(arg ${CTK_SUPERBUILD_EP_ARGS})
  100. # message(" ${arg}")
  101. # endforeach()
  102. #-----------------------------------------------------------------------------
  103. # Set CMake OSX variable to pass down the external project
  104. set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS)
  105. if(APPLE)
  106. list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS
  107. -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
  108. -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
  109. -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
  110. endif()
  111. #-----------------------------------------------------------------------------
  112. # CTK Configure
  113. #
  114. set(proj CTK-Configure)
  115. ExternalProject_Add(${proj}
  116. DOWNLOAD_COMMAND ""
  117. CMAKE_GENERATOR ${gen}
  118. CMAKE_ARGS
  119. ${ctk_superbuild_boolean_args}
  120. ${CMAKE_OSX_EXTERNAL_PROJECT_ARGS}
  121. -DCTK_SUPERBUILD:BOOL=OFF
  122. -DDOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  123. -DDOXYGEN_EXECUTABLE:FILEPATH=${DOXYGEN_EXECUTABLE}
  124. -DCTK_SUPERBUILD_BINARY_DIR:PATH=${CTK_BINARY_DIR}
  125. -DCTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
  126. -DCTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}
  127. -DCTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
  128. -DCTK_INSTALL_BIN_DIR:STRING=${CTK_INSTALL_BIN_DIR}
  129. -DCTK_INSTALL_LIB_DIR:STRING=${CTK_INSTALL_LIB_DIR}
  130. -DCTK_INSTALL_INCLUDE_DIR:STRING=${CTK_INSTALL_INCLUDE_DIR}
  131. -DCTK_INSTALL_DOC_DIR:STRING=${CTK_INSTALL_DOC_DIR}
  132. -DCTK_BUILD_SHARED_LIBS:BOOL=${CTK_BUILD_SHARED_LIBS}
  133. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  134. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  135. -DCTK_CXX_FLAGS:STRING=${CTK_CXX_FLAGS}
  136. -DCTK_C_FLAGS:STRING=${CTK_C_FLAGS}
  137. -DCTK_EXTERNAL_LIBRARY_DIRS:STRING=${CTK_EXTERNAL_LIBRARY_DIRS}
  138. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  139. ${CTK_SUPERBUILD_EP_ARGS}
  140. -DCTK_SUPERBUILD_EP_VARNAMES:STRING=${CTK_SUPERBUILD_EP_VARNAMES}
  141. SOURCE_DIR ${CTK_SOURCE_DIR}
  142. BINARY_DIR ${CTK_BINARY_DIR}/CTK-build
  143. BUILD_COMMAND ""
  144. INSTALL_COMMAND ""
  145. DEPENDS
  146. ${CTK_DEPENDENCIES}
  147. )
  148. if(CMAKE_GENERATOR MATCHES ".*Makefiles.*")
  149. set(ctk_build_cmd "$(MAKE)")
  150. else()
  151. set(ctk_build_cmd ${CMAKE_COMMAND} --build ${CTK_BINARY_DIR}/CTK-build --config ${CMAKE_CFG_INTDIR})
  152. endif()
  153. #-----------------------------------------------------------------------------
  154. # CTK
  155. #
  156. #message(STATUS SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:${SUPERBUILD_EXCLUDE_CTKBUILD_TARGET})
  157. if(NOT DEFINED SUPERBUILD_EXCLUDE_CTKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_CTKBUILD_TARGET)
  158. set(CTKBUILD_TARGET_ALL_OPTION "ALL")
  159. else()
  160. set(CTKBUILD_TARGET_ALL_OPTION "")
  161. endif()
  162. add_custom_target(CTK-build ${CTKBUILD_TARGET_ALL_OPTION}
  163. COMMAND ${ctk_build_cmd}
  164. WORKING_DIRECTORY ${CTK_BINARY_DIR}/CTK-build
  165. )
  166. add_dependencies(CTK-build CTK-Configure)
  167. #-----------------------------------------------------------------------------
  168. # Custom target allowing to drive the build of CTK project itself
  169. #
  170. add_custom_target(CTK
  171. COMMAND ${ctk_build_cmd}
  172. WORKING_DIRECTORY ${CTK_BINARY_DIR}/CTK-build
  173. )