SuperBuild.cmake 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 CMake/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_QTTESTING
  66. CTK_USE_KWSTYLE
  67. WITH_COVERAGE
  68. DOCUMENTATION_TARGET_IN_ALL
  69. CTEST_USE_LAUNCHERS
  70. CTK_WRAP_PYTHONQT_FULL
  71. CTK_ENABLE_Python_Wrapping
  72. ${ctk_libs_bool_vars}
  73. ${ctk_plugins_bool_vars}
  74. ${ctk_applications_bool_vars}
  75. ${ctk_lib_options_list}
  76. )
  77. set(ctk_superbuild_boolean_args)
  78. foreach(ctk_cmake_arg ${ctk_cmake_boolean_args})
  79. list(APPEND ctk_superbuild_boolean_args -D${ctk_cmake_arg}:BOOL=${${ctk_cmake_arg}})
  80. endforeach()
  81. # message("CMake boolean args:")
  82. # foreach(arg ${ctk_superbuild_boolean_args})
  83. # message(" ${arg}")
  84. # endforeach()
  85. #-----------------------------------------------------------------------------
  86. # Expand superbuild external project args
  87. #
  88. set(CTK_SUPERBUILD_EP_ARGS)
  89. set(CTK_SUPERBUILD_EP_VARNAMES)
  90. foreach(arg ${CTK_SUPERBUILD_EP_VARS})
  91. string(REPLACE ":" ";" varname_and_vartype ${arg})
  92. set(target_info_list ${target_info_list})
  93. list(GET varname_and_vartype 0 _varname)
  94. list(GET varname_and_vartype 1 _vartype)
  95. list(APPEND CTK_SUPERBUILD_EP_ARGS -D${_varname}:${_vartype}=${${_varname}})
  96. list(APPEND CTK_SUPERBUILD_EP_VARNAMES ${_varname})
  97. endforeach()
  98. string(REPLACE ";" "^" CTK_SUPERBUILD_EP_VARNAMES "${CTK_SUPERBUILD_EP_VARNAMES}")
  99. # message("CMake external project args:")
  100. # foreach(arg ${CTK_SUPERBUILD_EP_ARGS})
  101. # message(" ${arg}")
  102. # endforeach()
  103. #-----------------------------------------------------------------------------
  104. # CTK Configure
  105. #
  106. set(proj CTK-Configure)
  107. ExternalProject_Add(${proj}
  108. DOWNLOAD_COMMAND ""
  109. CMAKE_GENERATOR ${gen}
  110. CMAKE_ARGS
  111. -DCTK_SUPERBUILD:BOOL=OFF
  112. -DCTK_SUPERBUILD_BINARY_DIR:PATH=${CTK_BINARY_DIR}
  113. ${ctk_superbuild_boolean_args}
  114. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  115. -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
  116. -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
  117. -DCMAKE_CXX_FLAGS_INIT:STRING=${CMAKE_CXX_FLAGS_INIT}
  118. -DCMAKE_C_FLAGS_INIT:STRING=${CMAKE_C_FLAGS_INIT}
  119. -DADDITIONAL_C_FLAGS:STRING=${ADDITIONAL_C_FLAGS}
  120. -DADDITIONAL_CXX_FLAGS:STRING=${ADDITIONAL_CXX_FLAGS}
  121. -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
  122. -DCTK_BUILD_SHARED_LIBS:BOOL=${CTK_BUILD_SHARED_LIBS}
  123. ${CMAKE_OSX_EXTERNAL_PROJECT_ARGS}
  124. -DDOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
  125. -DDOXYGEN_EXECUTABLE:FILEPATH=${DOXYGEN_EXECUTABLE}
  126. -DCTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
  127. -DCTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}
  128. -DCTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
  129. -DCTK_INSTALL_BIN_DIR:STRING=${CTK_INSTALL_BIN_DIR}
  130. -DCTK_INSTALL_LIB_DIR:STRING=${CTK_INSTALL_LIB_DIR}
  131. -DCTK_INSTALL_QTPLUGIN_DIR:STRING=${CTK_INSTALL_QTPLUGIN_DIR}
  132. -DCTK_INSTALL_INCLUDE_DIR:STRING=${CTK_INSTALL_INCLUDE_DIR}
  133. -DCTK_INSTALL_DOC_DIR:STRING=${CTK_INSTALL_DOC_DIR}
  134. -DCTK_EXTERNAL_LIBRARY_DIRS:STRING=${CTK_EXTERNAL_LIBRARY_DIRS}
  135. -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
  136. ${CTK_SUPERBUILD_EP_ARGS}
  137. -DCTK_SUPERBUILD_EP_VARNAMES:STRING=${CTK_SUPERBUILD_EP_VARNAMES}
  138. SOURCE_DIR ${CTK_SOURCE_DIR}
  139. BINARY_DIR ${CTK_BINARY_DIR}/CTK-build
  140. BUILD_COMMAND ""
  141. INSTALL_COMMAND ""
  142. DEPENDS
  143. ${CTK_DEPENDENCIES}
  144. )
  145. if(CMAKE_GENERATOR MATCHES ".*Makefiles.*")
  146. set(ctk_build_cmd "$(MAKE)")
  147. else()
  148. set(ctk_build_cmd ${CMAKE_COMMAND} --build ${CTK_BINARY_DIR}/CTK-build --config ${CMAKE_CFG_INTDIR})
  149. endif()
  150. #-----------------------------------------------------------------------------
  151. # CTK
  152. #
  153. #message(STATUS SUPERBUILD_EXCLUDE_CTKBUILD_TARGET:${SUPERBUILD_EXCLUDE_CTKBUILD_TARGET})
  154. if(NOT DEFINED SUPERBUILD_EXCLUDE_CTKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_CTKBUILD_TARGET)
  155. set(CTKBUILD_TARGET_ALL_OPTION "ALL")
  156. else()
  157. set(CTKBUILD_TARGET_ALL_OPTION "")
  158. endif()
  159. add_custom_target(CTK-build ${CTKBUILD_TARGET_ALL_OPTION}
  160. COMMAND ${ctk_build_cmd}
  161. WORKING_DIRECTORY ${CTK_BINARY_DIR}/CTK-build
  162. )
  163. add_dependencies(CTK-build CTK-Configure)
  164. #-----------------------------------------------------------------------------
  165. # Custom target allowing to drive the build of CTK project itself
  166. #
  167. add_custom_target(CTK
  168. COMMAND ${ctk_build_cmd}
  169. WORKING_DIRECTORY ${CTK_BINARY_DIR}/CTK-build
  170. )