diff options
author | Brad King <brad.king@kitware.com> | 2023-01-13 13:47:11 +0000 |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-01-13 08:47:19 -0500 |
commit | e35255f2a5bfdc71eab9b6e44033954e6f829ac1 (patch) | |
tree | 1530014977989570b2ab89a5bea87df5d3f3018e | |
parent | 2d9e66a23bd469b5c89fb7951f6dc59738cd2516 (diff) | |
parent | 2f85ec0a37d1ad75956dd81016a8c7ab90ff845b (diff) | |
download | cmake-e35255f2a5bfdc71eab9b6e44033954e6f829ac1.tar.gz |
Merge topic 'try_run-cross-compile' into release-3.25
2f85ec0a37 try_run: Avoid crash in keyword-dispatched signature when cross-compiling
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !8066
-rw-r--r-- | Source/cmTryRunCommand.cxx | 14 | ||||
-rw-r--r-- | Tests/RunCMake/try_run/CrossCompile.cmake | 8 | ||||
-rw-r--r-- | Tests/RunCMake/try_run/old_and_new_signature_tests.cmake | 2 |
3 files changed, 18 insertions, 6 deletions
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 1e81195b81..8d62cb1555 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -40,7 +40,7 @@ public: std::string* runOutputStdOutContents, std::string* runOutputStdErrContents); void DoNotRunExecutable(const std::string& runArgs, - const std::string& srcFile, + cm::optional<std::string> const& srcFile, std::string const& compileResultVariable, std::string* runOutputContents, std::string* runOutputStdOutContents, @@ -128,7 +128,7 @@ bool TryRunCommandImpl::TryRunCode(std::vector<std::string> const& argv) if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING") && !this->Makefile->IsDefinitionSet("CMAKE_CROSSCOMPILING_EMULATOR")) { this->DoNotRunExecutable( - runArgs, *arguments.SourceDirectoryOrFile, + runArgs, arguments.SourceDirectoryOrFile, *arguments.CompileResultVariable, captureRunOutput ? &runOutputContents : nullptr, captureRunOutputStdOutErr && arguments.RunOutputStdOutVariable @@ -238,7 +238,7 @@ void TryRunCommandImpl::RunExecutable(const std::string& runArgs, the executable would have produced. */ void TryRunCommandImpl::DoNotRunExecutable( - const std::string& runArgs, const std::string& srcFile, + const std::string& runArgs, cm::optional<std::string> const& srcFile, std::string const& compileResultVariable, std::string* out, std::string* stdOut, std::string* stdErr) { @@ -421,9 +421,11 @@ void TryRunCommandImpl::DoNotRunExecutable( comment += "The "; comment += compileResultVariable; - comment += " variable holds the build result for this try_run().\n\n" - "Source file : "; - comment += srcFile + "\n"; + comment += " variable holds the build result for this try_run().\n\n"; + if (srcFile) { + comment += "Source file : "; + comment += *srcFile + "\n"; + } comment += "Executable : "; comment += copyDest + "\n"; comment += "Run arguments : "; diff --git a/Tests/RunCMake/try_run/CrossCompile.cmake b/Tests/RunCMake/try_run/CrossCompile.cmake new file mode 100644 index 0000000000..4993768b79 --- /dev/null +++ b/Tests/RunCMake/try_run/CrossCompile.cmake @@ -0,0 +1,8 @@ +include(${CMAKE_CURRENT_SOURCE_DIR}/${try_compile_DEFS}) + +# Pretend we are cross-compiling to take that try_run code path. +set(CMAKE_CROSSCOMPILING 1) +set(RUN_RESULT 0) +try_run(RUN_RESULT COMPILE_RESULT ${try_compile_bindir_or_SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/src.c) +unset(CMAKE_CROSSCOMPILING) diff --git a/Tests/RunCMake/try_run/old_and_new_signature_tests.cmake b/Tests/RunCMake/try_run/old_and_new_signature_tests.cmake index e1c1784b7c..2b51eb24bb 100644 --- a/Tests/RunCMake/try_run/old_and_new_signature_tests.cmake +++ b/Tests/RunCMake/try_run/old_and_new_signature_tests.cmake @@ -11,6 +11,8 @@ run_cmake(BadLinkLibraries) run_cmake(BinDirEmpty) run_cmake(BinDirRelative) +run_cmake(CrossCompile) + run_cmake(WorkingDirArg) run_cmake(NoCompileOutputVariable) |