| 3365 | } |
| 3366 | |
| 3367 | bool cmGlobalGenerator::AddBuildDatabaseTargets() |
| 3368 | { |
| 3369 | auto& mf = this->Makefiles[0]; |
| 3370 | if (!mf->IsOn("CMAKE_EXPORT_BUILD_DATABASE")) { |
| 3371 | return true; |
| 3372 | } |
| 3373 | if (!cmExperimental::HasSupportEnabled( |
| 3374 | *mf.get(), cmExperimental::Feature::ExportBuildDatabase)) { |
| 3375 | return {}; |
| 3376 | } |
| 3377 | |
| 3378 | static auto const reservedTargets = { "cmake_build_database" }; |
| 3379 | for (auto const& target : reservedTargets) { |
| 3380 | if (!this->CheckReservedTargetName( |
| 3381 | target, "when exporting build databases are enabled")) { |
| 3382 | return false; |
| 3383 | } |
| 3384 | } |
| 3385 | static auto const reservedPrefixes = { "cmake_build_database-" }; |
| 3386 | for (auto const& prefix : reservedPrefixes) { |
| 3387 | if (!this->CheckReservedTargetNamePrefix( |
| 3388 | prefix, "when exporting build databases are enabled")) { |
| 3389 | return false; |
| 3390 | } |
| 3391 | } |
| 3392 | |
| 3393 | if (!this->SupportsBuildDatabase()) { |
| 3394 | return true; |
| 3395 | } |
| 3396 | |
| 3397 | auto configs = mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); |
| 3398 | |
| 3399 | static cm::static_string_view TargetPrefix = "cmake_build_database"_s; |
| 3400 | auto AddMergeTarget = |
| 3401 | [&mf](std::string const& name, char const* comment, |
| 3402 | std::string const& output, |
| 3403 | std::function<std::vector<std::string>()> inputs) { |
| 3404 | // Add the custom command. |
| 3405 | { |
| 3406 | ModuleCompilationDatabaseCommandAction action{ output, |
| 3407 | std::move(inputs) }; |
| 3408 | auto cc = cm::make_unique<cmCustomCommand>(); |
| 3409 | cc->SetComment(comment); |
| 3410 | mf->AddGeneratorAction( |
| 3411 | std::move(cc), action, |
| 3412 | cmMakefile::GeneratorActionWhen::AfterGeneratorTargets); |
| 3413 | } |
| 3414 | |
| 3415 | // Add a custom target with the given name. |
| 3416 | { |
| 3417 | cmTarget* target = mf->AddNewUtilityTarget(name, true); |
| 3418 | ModuleCompilationDatabaseTargetAction action{ output, target }; |
| 3419 | auto cc = cm::make_unique<cmCustomCommand>(); |
| 3420 | mf->AddGeneratorAction(std::move(cc), action); |
| 3421 | } |
| 3422 | }; |
| 3423 | |
| 3424 | std::string module_languages[] = { "CXX" }; |
no test coverage detected