| 3210 | } |
| 3211 | |
| 3212 | int 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(); |
no test coverage detected