mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-29 02:20:17 -06:00
install: Do not crash on imported global target
Since commit e89ad0f94e (install: Allow installing targets created in
another directory, 2018-06-18, v3.13.0-rc1~407^2) the `install(TARGETS)`
command may find a global-scoped target outside the calling directory.
Ignore an `IMPORTED GLOBAL` target if it is found in this way. Imported
targets cannot be installed, and trying to do so violates internal
invariants.
Fixes: #19022
This commit is contained in:
@@ -402,7 +402,11 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||
cmTarget* target = this->Makefile->FindLocalNonAliasTarget(tgt);
|
||||
if (!target) {
|
||||
// If no local target has been found, find it in the global scope.
|
||||
target = this->Makefile->GetGlobalGenerator()->FindTarget(tgt, true);
|
||||
cmTarget* const global_target =
|
||||
this->Makefile->GetGlobalGenerator()->FindTarget(tgt, true);
|
||||
if (global_target && !global_target->IsImported()) {
|
||||
target = global_target;
|
||||
}
|
||||
}
|
||||
if (target) {
|
||||
// Found the target. Check its type.
|
||||
|
||||
@@ -66,6 +66,7 @@ run_cmake(CMP0062-WARN)
|
||||
run_cmake(CMP0087-OLD)
|
||||
run_cmake(CMP0087-NEW)
|
||||
run_cmake(CMP0087-WARN)
|
||||
run_cmake(TARGETS-ImportedGlobal)
|
||||
run_cmake(TARGETS-NAMELINK_COMPONENT-bad-all)
|
||||
run_cmake(TARGETS-NAMELINK_COMPONENT-bad-exc)
|
||||
run_cmake(FILES-DESTINATION-TYPE)
|
||||
|
||||
1
Tests/RunCMake/install/TARGETS-ImportedGlobal-result.txt
Normal file
1
Tests/RunCMake/install/TARGETS-ImportedGlobal-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
4
Tests/RunCMake/install/TARGETS-ImportedGlobal-stderr.txt
Normal file
4
Tests/RunCMake/install/TARGETS-ImportedGlobal-stderr.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
^CMake Error at TARGETS-ImportedGlobal.cmake:[0-9]+ \(install\):
|
||||
install TARGETS given target "imported_global" which does not exist.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)$
|
||||
3
Tests/RunCMake/install/TARGETS-ImportedGlobal.cmake
Normal file
3
Tests/RunCMake/install/TARGETS-ImportedGlobal.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
add_library(imported_global STATIC IMPORTED GLOBAL)
|
||||
set_property(TARGET imported_global PROPERTY IMPORTED_LOCATION /does_not_exist)
|
||||
install(TARGETS imported_global DESTINATION bin)
|
||||
Reference in New Issue
Block a user