mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-30 18:29:37 -06:00
Fix crash in target-specific commands called from initial cache script
Fixes: #26018
This commit is contained in:
@@ -85,8 +85,7 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
// Lookup the target for which libraries are specified.
|
||||
cmTarget* target =
|
||||
mf.GetCMakeInstance()->GetGlobalGenerator()->FindTarget(args[0]);
|
||||
cmTarget* target = mf.GetGlobalGenerator()->FindTarget(args[0]);
|
||||
if (!target) {
|
||||
for (const auto& importedTarget : mf.GetOwnedImportedTargets()) {
|
||||
if (importedTarget->GetName() == args[0]) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "cmStateTypes.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmValue.h"
|
||||
#include "cmake.h"
|
||||
|
||||
cmTargetPropCommandBase::cmTargetPropCommandBase(cmExecutionStatus& status)
|
||||
: Makefile(&status.GetMakefile())
|
||||
@@ -35,9 +34,7 @@ bool cmTargetPropCommandBase::HandleArguments(
|
||||
return false;
|
||||
}
|
||||
// Lookup the target for which property-values are specified.
|
||||
this->Target =
|
||||
this->Makefile->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(
|
||||
args[0]);
|
||||
this->Target = this->Makefile->GetGlobalGenerator()->FindTarget(args[0]);
|
||||
if (!this->Target) {
|
||||
this->Target = this->Makefile->FindTargetToUse(args[0]);
|
||||
}
|
||||
|
||||
1
Tests/RunCMake/CommandLine/C_target-commands-result.txt
Normal file
1
Tests/RunCMake/CommandLine/C_target-commands-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
44
Tests/RunCMake/CommandLine/C_target-commands-stderr.txt
Normal file
44
Tests/RunCMake/CommandLine/C_target-commands-stderr.txt
Normal file
@@ -0,0 +1,44 @@
|
||||
^CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_sources\):
|
||||
Cannot specify sources for target "DoesNotExist" which is not built by this
|
||||
project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_compile_definitions\):
|
||||
Cannot specify compile definitions for target "DoesNotExist" which is not
|
||||
built by this project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_compile_features\):
|
||||
Cannot specify compile features for target "DoesNotExist" which is not
|
||||
built by this project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_compile_options\):
|
||||
Cannot specify compile options for target "DoesNotExist" which is not built
|
||||
by this project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_include_directories\):
|
||||
Cannot specify include directories for target "DoesNotExist" which is not
|
||||
built by this project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_precompile_headers\):
|
||||
Cannot specify precompile headers for target "DoesNotExist" which is not
|
||||
built by this project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_link_directories\):
|
||||
Cannot specify link directories for target "DoesNotExist" which is not
|
||||
built by this project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_link_options\):
|
||||
Cannot specify link options for target "DoesNotExist" which is not built by
|
||||
this project\.
|
||||
+
|
||||
CMake Error at [^
|
||||
]*C_target-commands_initial-cache\.cmake:[0-9]+ \(target_link_libraries\):
|
||||
Cannot specify link libraries for target "DoesNotExist" which is not built
|
||||
by this project\.$
|
||||
1
Tests/RunCMake/CommandLine/C_target-commands-stdout.txt
Normal file
1
Tests/RunCMake/CommandLine/C_target-commands-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
loading initial cache file \.\./C_target-commands_initial-cache\.cmake
|
||||
0
Tests/RunCMake/CommandLine/C_target-commands.cmake
Normal file
0
Tests/RunCMake/CommandLine/C_target-commands.cmake
Normal file
@@ -0,0 +1,9 @@
|
||||
target_sources(DoesNotExist PRIVATE)
|
||||
target_compile_definitions(DoesNotExist PRIVATE)
|
||||
target_compile_features(DoesNotExist PRIVATE)
|
||||
target_compile_options(DoesNotExist PRIVATE)
|
||||
target_include_directories(DoesNotExist PRIVATE)
|
||||
target_precompile_headers(DoesNotExist PRIVATE)
|
||||
target_link_directories(DoesNotExist PRIVATE)
|
||||
target_link_options(DoesNotExist PRIVATE)
|
||||
target_link_libraries(DoesNotExist PRIVATE)
|
||||
@@ -897,6 +897,8 @@ run_cmake_command(P_working-dir ${CMAKE_COMMAND} -DEXPECTED_WORKING_DIR=${RunCMa
|
||||
file(COPY ${RunCMake_SOURCE_DIR}/C_basic_initial-cache.txt DESTINATION ${RunCMake_BINARY_DIR})
|
||||
run_cmake_with_options(C_basic -C ../C_basic_initial-cache.txt)
|
||||
run_cmake_with_options(C_basic_fullpath -C ${RunCMake_BINARY_DIR}/C_basic_initial-cache.txt)
|
||||
file(COPY ${RunCMake_SOURCE_DIR}/C_target-commands_initial-cache.cmake DESTINATION ${RunCMake_BINARY_DIR})
|
||||
run_cmake_command(C_target-commands ${CMAKE_COMMAND} -S ${RunCMake_SOURCE_DIR} -DRunCMake_TEST=C_target-commands -C ../C_target-commands_initial-cache.cmake)
|
||||
|
||||
set(RunCMake_TEST_OPTIONS
|
||||
"-DFOO=-DBAR:BOOL=BAZ")
|
||||
|
||||
Reference in New Issue
Block a user