ExternalProject: Restore driving install through build system

Revert commit 66b5d51f38 (ExternalProject: Install CMake projects
using 'cmake --install', 2022-09-08, v3.25.0-rc1~150^2).
It changed the ExternalProject install step command from:

    cmake --build <dir> --target install --config <cfg>

to:

    cmake --install <dir> --config <cfg>

The latter command no longer runs the external project build system
during the install step.  We could consider using the commands:

    cmake --build <dir> --target all --config <cfg>
    cmake --install <dir> --config <cfg>

as the install step, but if `CMAKE_SKIP_INSTALL_ALL_DEPENDENCY` is
used in the external project, that can change semantics too.

Revert the original change pending further investigation on other ways
to support its motivating use case.  Add a test covering the
previously-regressed use case.

Fixes: #24567
Issue: #23946
This commit is contained in:
Brad King
2023-03-02 13:46:44 -05:00
parent e2f1d6e7bd
commit 771387523a
5 changed files with 18 additions and 5 deletions

View File

@@ -1840,11 +1840,7 @@ function(_ep_get_build_command
else()
set(cmd "${CMAKE_COMMAND}")
endif()
if(step STREQUAL "INSTALL")
set(args --install ".")
else()
set(args --build ".")
endif()
set(args --build ".")
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
if (CMAKE_CFG_INTDIR AND
@@ -1866,6 +1862,9 @@ function(_ep_get_build_command
endif()
list(APPEND args --config ${config})
endif()
if(step STREQUAL "INSTALL")
list(APPEND args --target install)
endif()
# But for "TEST" drive the project with corresponding "ctest".
if("x${step}x" STREQUAL "xTESTx")
string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")

View File

@@ -0,0 +1,2 @@
.*build command suppressed
.*always builds

View File

@@ -0,0 +1,7 @@
include(ExternalProject)
ExternalProject_Add(InstallBuilds
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/InstallBuilds
DOWNLOAD_COMMAND ""
BUILD_COMMAND "${CMAKE_COMMAND}" -E echo "build command suppressed"
)

View File

@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.24)
project(InstallBuilds NONE)
add_custom_target(always ALL COMMAND ${CMAKE_COMMAND} -E echo "always builds")
install(CODE "")

View File

@@ -147,6 +147,7 @@ endfunction()
__ep_test_with_build(MultiCommand)
set(RunCMake_TEST_OUTPUT_MERGE 1)
__ep_test_with_build(InstallBuilds)
__ep_test_with_build(PreserveEmptyArgs)
set(RunCMake_TEST_OUTPUT_MERGE 0)