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

Method TryCompile

Source/cmMakefile.cxx:3212–3347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3210}
3211
3212int cmMakefile::TryCompile(std::string const& srcdir,
3213 std::string const& bindir,
3214 std::string const& projectName,
3215 std::string const& targetName, bool fast, int jobs,
3216 std::vector<std::string> const* cmakeArgs,
3217 std::string& output)
3218{
3219 this->IsSourceFileTryCompile = fast;
3220 // does the binary directory exist ? If not create it...
3221 if (!cmSystemTools::FileIsDirectory(bindir)) {
3222 cmSystemTools::MakeDirectory(bindir);
3223 }
3224
3225 // change to the tests directory and run cmake
3226 // use the cmake object instead of calling cmake
3227 cmWorkingDirectory workdir(bindir);
3228 if (workdir.Failed()) {
3229 this->IssueMessage(MessageType::FATAL_ERROR, workdir.GetError());
3230 cmSystemTools::SetFatalErrorOccurred();
3231 this->IsSourceFileTryCompile = false;
3232 return 1;
3233 }
3234
3235 // unset the NINJA_STATUS environment variable while running try compile.
3236 // since we parse the output, we need to ensure there aren't any unexpected
3237 // characters that will cause issues, such as ANSI color escape codes.
3238 cm::optional<cmSystemTools::ScopedEnv> maybeNinjaStatus;
3239 if (this->GetGlobalGenerator()->IsNinja()) {
3240 maybeNinjaStatus.emplace("NINJA_STATUS=");
3241 }
3242
3243 // make sure the same generator is used
3244 // use this program as the cmake to be run, it should not
3245 // be run that way but the cmake object requires a valid path
3246 cmake cm(cmState::Role::Project, cmState::TryCompile::Yes);
3247 auto gg = cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName());
3248 if (!gg) {
3249 this->IssueMessage(MessageType::INTERNAL_ERROR,
3250 "Global generator '" +
3251 this->GetGlobalGenerator()->GetName() +
3252 "' could not be created.");
3253 cmSystemTools::SetFatalErrorOccurred();
3254 this->IsSourceFileTryCompile = false;
3255 return 1;
3256 }
3257 gg->RecursionDepth = this->RecursionDepth;
3258 cm.SetGlobalGenerator(std::move(gg));
3259
3260 // copy trace state
3261 cm.SetTraceRedirect(this->GetCMakeInstance());
3262
3263 // do a configure
3264 cm.SetHomeDirectory(srcdir);
3265 cm.SetHomeOutputDirectory(bindir);
3266 cm.SetGeneratorInstance(this->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE"));
3267 cm.SetGeneratorPlatform(this->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM"));
3268 cm.SetGeneratorToolset(this->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET"));
3269 cm.LoadCache();

Callers 1

TryCompileCodeMethod · 0.45

Calls 15

IssueMessageMethod · 0.95
GetGlobalGeneratorMethod · 0.95
GetCMakeInstanceMethod · 0.95
GetDefinitionMethod · 0.95
IsOnMethod · 0.95
moveFunction · 0.85
FailedMethod · 0.80
emplaceMethod · 0.80
SetTraceRedirectMethod · 0.80
SetHomeDirectoryMethod · 0.80
SetWarnUnusedCliMethod · 0.80

Tested by

no test coverage detected