Files
CMake/Tests/RunCMake/ExternalProject/Steps-CMP0114-Common.cmake
Brad King b4fc4da903 ExternalProject: Add policy CMP0114 to refine step target dependencies
`ExternalProject_Add_StepTargets` and `INDEPENDENT_STEP_TARGETS` have
some limitations and lack some sanity checks.  They can cause confusing
build systems to be generated.  The basic problems are:

* The notion of step independence is attached to the step target
  rather than the step itself.

* The custom commands implementing the steps are duplicated in the
  step targets and the primary targets.  This can cause races.
  It is also incompatible with the Xcode "new build system".

Fix this by introducing policy CMP0114 to change the way step target
dependencies are handled.  Define independence from external
dependencies as a property of each individual step regardless of whether
there is a target for it.  Add dependencies among the primary target and
the step targets such that each custom command only appears in one
target.  When some steps are disconnected from the primary target, add
step targets for the steps commonly depended upon so that there is a
place to hold their custom commands uniquely.

Fixes: #18663
2020-09-14 10:48:16 -04:00

35 lines
1.5 KiB
CMake

include(ExternalProject)
ExternalProject_Add(proj0
SOURCE_DIR "."
DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj0-download-mark
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj0-configure-mark
BUILD_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj0-build-mark
INSTALL_COMMAND ""
)
cmake_policy(GET CMP0114 cmp0114)
if(cmp0114 STREQUAL "NEW")
set(step_targets "update;test")
set(independent_step_targets "")
else()
set(step_targets "install;test")
set(independent_step_targets "download;update")
endif()
ExternalProject_Add(proj1
DEPENDS proj0
SOURCE_DIR "."
DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj1-download-mark
UPDATE_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj1-update-mark
PATCH_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj1-patch-mark
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj1-configure-mark
BUILD_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj1-build-mark
INSTALL_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj1-install-mark
TEST_COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/proj1-test-mark
TEST_EXCLUDE_FROM_MAIN 1 # Along with 'STEP_TARGETS test', implies 'STEP_TARGETS install'
UPDATE_DISCONNECTED 1 # Along with 'STEP_TARGETS update', implies 'STEP_TARGETS download'
STEP_TARGETS ${step_targets}
INDEPENDENT_STEP_TARGETS ${independent_step_targets}
)