diff options
author | Brad King <brad.king@kitware.com> | 2022-07-29 18:56:00 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-08-02 12:04:21 (GMT) |
commit | 067ba3a2bd1ce168b2867de74d2ea6b944a936fc (patch) | |
tree | 8a8cdfb134a09085495488059e1bb1ece246589c /Source | |
parent | 781e1b191a812e3f808ce272baaaa0689d30d953 (diff) | |
download | CMake-067ba3a2bd1ce168b2867de74d2ea6b944a936fc.zip CMake-067ba3a2bd1ce168b2867de74d2ea6b944a936fc.tar.gz CMake-067ba3a2bd1ce168b2867de74d2ea6b944a936fc.tar.bz2 |
cmCoreTryCompile: Move target type selection logic to try_compile
This is specific to `try_compile` since `try_run` always needs an
executable. Move the logic out of the common code path.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 23 | ||||
-rw-r--r-- | Source/cmCoreTryCompile.h | 3 | ||||
-rw-r--r-- | Source/cmTryCompileCommand.cxx | 27 | ||||
-rw-r--r-- | Source/cmTryRunCommand.cxx | 2 |
4 files changed, 30 insertions, 25 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 44dbb7f..3c749ed 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -236,34 +236,13 @@ std::set<std::string> const ghs_platform_vars{ } bool cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, - bool isTryRun) + cmStateEnums::TargetType targetType) { std::string const& resultVar = argv[0]; this->OutputFile.clear(); // which signature were we called with ? this->SrcFileSignature = true; - cmStateEnums::TargetType targetType = cmStateEnums::EXECUTABLE; - cmValue tt = this->Makefile->GetDefinition("CMAKE_TRY_COMPILE_TARGET_TYPE"); - if (!isTryRun && cmNonempty(tt)) { - if (*tt == cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE)) { - targetType = cmStateEnums::EXECUTABLE; - } else if (*tt == - cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY)) { - targetType = cmStateEnums::STATIC_LIBRARY; - } else { - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Invalid value '", *tt, - "' for CMAKE_TRY_COMPILE_TARGET_TYPE. Only '", - cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE), - "' and '", - cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY), - "' are allowed.")); - return false; - } - } - std::string sourceDirectory; std::string projectName; std::string targetName; diff --git a/Source/cmCoreTryCompile.h b/Source/cmCoreTryCompile.h index 1e70293..6ca08e8 100644 --- a/Source/cmCoreTryCompile.h +++ b/Source/cmCoreTryCompile.h @@ -30,7 +30,8 @@ public: * commands, such as TryRun can access the same logic without * duplication. */ - bool TryCompileCode(std::vector<std::string> const& argv, bool isTryRun); + bool TryCompileCode(std::vector<std::string> const& argv, + cmStateEnums::TargetType targetType); /** * This deletes all the files created by TryCompileCode. diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index 7514a23..971dccb 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -6,6 +6,10 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmState.h" +#include "cmStateTypes.h" +#include "cmStringAlgorithms.h" +#include "cmValue.h" #include "cmake.h" bool cmTryCompileCommand(std::vector<std::string> const& args, @@ -24,8 +28,29 @@ bool cmTryCompileCommand(std::vector<std::string> const& args, return false; } + cmStateEnums::TargetType targetType = cmStateEnums::EXECUTABLE; + cmValue tt = mf.GetDefinition("CMAKE_TRY_COMPILE_TARGET_TYPE"); + if (cmNonempty(tt)) { + if (*tt == cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE)) { + targetType = cmStateEnums::EXECUTABLE; + } else if (*tt == + cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY)) { + targetType = cmStateEnums::STATIC_LIBRARY; + } else { + mf.IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Invalid value '", *tt, + "' for CMAKE_TRY_COMPILE_TARGET_TYPE. Only '", + cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE), + "' and '", + cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY), + "' are allowed.")); + return false; + } + } + cmCoreTryCompile tc(&mf); - tc.TryCompileCode(args, false); + tc.TryCompileCode(args, targetType); // if They specified clean then we clean up what we can if (tc.SrcFileSignature) { diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index b42a6ce..2cf75e2 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -192,7 +192,7 @@ bool TryRunCommandImpl::TryRunCode(std::vector<std::string> const& argv) this->CompileResultVariable = argv[1]; // do the try compile - bool compiled = this->TryCompileCode(tryCompile, true); + bool compiled = this->TryCompileCode(tryCompile, cmStateEnums::EXECUTABLE); // now try running the command if it compiled if (compiled) { |