summaryrefslogtreecommitdiffstats
path: root/Source/cmTryCompileCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-07-29 18:56:00 (GMT)
committerBrad King <brad.king@kitware.com>2022-08-02 12:04:21 (GMT)
commit067ba3a2bd1ce168b2867de74d2ea6b944a936fc (patch)
tree8a8cdfb134a09085495488059e1bb1ece246589c /Source/cmTryCompileCommand.cxx
parent781e1b191a812e3f808ce272baaaa0689d30d953 (diff)
downloadCMake-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/cmTryCompileCommand.cxx')
-rw-r--r--Source/cmTryCompileCommand.cxx27
1 files changed, 26 insertions, 1 deletions
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) {