MCPcopy Create free account
hub / github.com/Kitware/CMake / cmTryCompileCommand

Function cmTryCompileCommand

Source/cmTryCompileCommand.cxx:36–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36bool cmTryCompileCommand(std::vector<std::string> const& args,
37 cmExecutionStatus& status)
38{
39 cmMakefile& mf = status.GetMakefile();
40
41 if (args.size() < 3) {
42 mf.IssueMessage(
43 MessageType::FATAL_ERROR,
44 "The try_compile() command requires at least 3 arguments.");
45 return false;
46 }
47
48 if (mf.GetCMakeInstance()->GetState()->GetRole() ==
49 cmState::Role::FindPackage) {
50 mf.IssueMessage(
51 MessageType::FATAL_ERROR,
52 "The try_compile() command is not supported in --find-package mode.");
53 return false;
54 }
55
56 cmStateEnums::TargetType targetType = cmStateEnums::EXECUTABLE;
57 cmValue tt = mf.GetDefinition("CMAKE_TRY_COMPILE_TARGET_TYPE");
58 if (cmNonempty(tt)) {
59 if (*tt == cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE)) {
60 targetType = cmStateEnums::EXECUTABLE;
61 } else if (*tt ==
62 cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY)) {
63 targetType = cmStateEnums::STATIC_LIBRARY;
64 } else {
65 mf.IssueMessage(
66 MessageType::FATAL_ERROR,
67 cmStrCat("Invalid value '", *tt,
68 "' for CMAKE_TRY_COMPILE_TARGET_TYPE. Only '",
69 cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE),
70 "' and '",
71 cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY),
72 "' are allowed."));
73 return false;
74 }
75 }
76
77 cmCoreTryCompile tc(&mf);
78 cmCoreTryCompile::Arguments arguments =
79 tc.ParseArgs(cmMakeRange(args), false);
80 if (!arguments) {
81 return true;
82 }
83
84 cm::optional<cmTryCompileResult> compileResult =
85 tc.TryCompileCode(arguments, targetType);
86#ifndef CMAKE_BOOTSTRAP
87 if (compileResult && !arguments.NoLog) {
88 if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
89 WriteTryCompileEvent(*log, mf, *compileResult);
90 }
91 }
92#endif
93

Callers

nothing calls this directly

Calls 15

cmNonemptyFunction · 0.85
cmMakeRangeFunction · 0.85
WriteTryCompileEventFunction · 0.85
GetRoleMethod · 0.80
ParseArgsMethod · 0.80
TryCompileCodeMethod · 0.80
GetConfigureLogMethod · 0.80
GetDebugTryCompileMethod · 0.80
CleanupFilesMethod · 0.80
cmStrCatFunction · 0.70
GetMakefileMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…