diff options
author | Brad King <brad.king@kitware.com> | 2024-06-03 13:10:43 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-06-03 13:10:52 (GMT) |
commit | 1df18d5e54023af6d7802a7219d2d4ef6e88bdb2 (patch) | |
tree | acfd636a868dd9fd1e0ad5c7e8d60f9c2f2f7d88 | |
parent | 54551123d24adc1768b698acddc19418c15545f5 (diff) | |
parent | 7330121467e9da7a6845de005264ecec980133e5 (diff) | |
download | CMake-1df18d5e54023af6d7802a7219d2d4ef6e88bdb2.zip CMake-1df18d5e54023af6d7802a7219d2d4ef6e88bdb2.tar.gz CMake-1df18d5e54023af6d7802a7219d2d4ef6e88bdb2.tar.bz2 |
Merge topic 'cmake-C-crash'
7330121467 Fix crash in target-specific commands called from initial cache script
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9571
8 files changed, 59 insertions, 6 deletions
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index bfd3972..51dce76 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -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]) { diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 8d2ff71..de2012f 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -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]); } diff --git a/Tests/RunCMake/CommandLine/C_target-commands-result.txt b/Tests/RunCMake/CommandLine/C_target-commands-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CommandLine/C_target-commands-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CommandLine/C_target-commands-stderr.txt b/Tests/RunCMake/CommandLine/C_target-commands-stderr.txt new file mode 100644 index 0000000..8e811a6 --- /dev/null +++ b/Tests/RunCMake/CommandLine/C_target-commands-stderr.txt @@ -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\.$ diff --git a/Tests/RunCMake/CommandLine/C_target-commands-stdout.txt b/Tests/RunCMake/CommandLine/C_target-commands-stdout.txt new file mode 100644 index 0000000..beaa2c6 --- /dev/null +++ b/Tests/RunCMake/CommandLine/C_target-commands-stdout.txt @@ -0,0 +1 @@ +loading initial cache file \.\./C_target-commands_initial-cache\.cmake diff --git a/Tests/RunCMake/CommandLine/C_target-commands.cmake b/Tests/RunCMake/CommandLine/C_target-commands.cmake new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/CommandLine/C_target-commands.cmake diff --git a/Tests/RunCMake/CommandLine/C_target-commands_initial-cache.cmake b/Tests/RunCMake/CommandLine/C_target-commands_initial-cache.cmake new file mode 100644 index 0000000..a453334 --- /dev/null +++ b/Tests/RunCMake/CommandLine/C_target-commands_initial-cache.cmake @@ -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) diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 8a5a25a..7a5a334 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -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") |