| 34 | } |
| 35 | |
| 36 | bool 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…