diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx index 545782fa3d..1c05f25fe0 100644 --- a/Source/cmDyndepCollation.cxx +++ b/Source/cmDyndepCollation.cxx @@ -194,6 +194,20 @@ TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt, return info; } +Json::Value CollationInformationDatabaseInfo(cmGeneratorTarget const* gt, + std::string const& config) +{ + Json::Value db_info; + + auto db_path = gt->BuildDatabasePath("CXX", config); + if (!db_path.empty()) { + db_info["template-path"] = cmStrCat(db_path, ".in"); + db_info["output"] = db_path; + } + + return db_info; +} + Json::Value CollationInformationBmiInstallation(cmGeneratorTarget const* gt, std::string const& config) { @@ -323,6 +337,7 @@ void cmDyndepCollation::AddCollationInformation( auto sourcesInfo = CollationInformationSources(gt, config, cb); tdi["sources"] = sourcesInfo.Sources; tdi["cxx-modules"] = sourcesInfo.CxxModules; + tdi["database-info"] = CollationInformationDatabaseInfo(gt, config); tdi["bmi-installation"] = CollationInformationBmiInstallation(gt, config); tdi["exports"] = CollationInformationExports(gt); tdi["config"] = config; @@ -414,6 +429,15 @@ cmDyndepCollation::ParseExportInfo(Json::Value const& tdi) export_info->Exports.push_back(exp); } } + auto const& database_info = tdi["database-info"]; + if (database_info.isObject()) { + CxxModuleDatabaseInfo db_info; + + db_info.TemplatePath = database_info["template-path"].asString(); + db_info.Output = database_info["output"].asString(); + + export_info->DatabaseInfo = db_info; + } auto const& bmi_installation = tdi["bmi-installation"]; if (bmi_installation.isObject()) { CxxModuleBmiInstall bmi_install; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 293a4b7111..ced18fdcef 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5921,6 +5921,27 @@ cmGeneratorTarget::CxxModuleSupport cmGeneratorTarget::NeedCxxDyndep( return policyAnswer; } +std::string cmGeneratorTarget::BuildDatabasePath( + std::string const& lang, std::string const& config) const +{ + // Check to see if the target wants it. + if (!this->GetPropertyAsBool("EXPORT_BUILD_DATABASE")) { + return {}; + } + // Check to see if the generator supports it. + if (!this->GetGlobalGenerator()->SupportsBuildDatabase()) { + return {}; + } + + if (this->GetGlobalGenerator()->IsMultiConfig()) { + return cmStrCat(this->GetSupportDirectory(), '/', config, '/', lang, + "_build_database.json"); + } + + return cmStrCat(this->GetSupportDirectory(), '/', lang, + "_build_database.json"); +} + void cmGeneratorTarget::BuildFileSetInfoCache(std::string const& config) const { auto& per_config = this->Configs[config]; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 210f0abb72..b05673378f 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -1502,6 +1502,9 @@ public: }; CxxModuleSupport NeedCxxDyndep(std::string const& config) const; + std::string BuildDatabasePath(std::string const& lang, + std::string const& config) const; + private: void BuildFileSetInfoCache(std::string const& config) const; struct InfoByConfig diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 85dec7279b..355cb80d6c 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -171,6 +171,8 @@ public: return false; } + virtual bool SupportsBuildDatabase() const { return false; } + virtual bool IsGNUMakeJobServerAware() const { return false; } bool Compute(); diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json index 4bb2455c01..dfca73ea1f 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json @@ -38,6 +38,7 @@ "visibility": "PRIVATE" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "", diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json index 364bce203c..20f164a2f0 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json @@ -38,6 +38,7 @@ "visibility": "PUBLIC" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "", diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json index 45cd8abab6..235e17de78 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json @@ -33,6 +33,7 @@ "visibility": "PRIVATE" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "", diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json index 43a4e4fbe1..ed19dd81b3 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json @@ -33,6 +33,7 @@ "visibility": "PUBLIC" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "", diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json index 03e2018f84..22005a2bb2 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json @@ -33,6 +33,7 @@ "visibility": "PRIVATE" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "", diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json index 4128252469..e9d4852225 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json @@ -33,6 +33,7 @@ "visibility": "PUBLIC" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "", diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json index f4e19f4cc1..571998f684 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json @@ -33,6 +33,7 @@ "visibility": "PRIVATE" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "", diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json index 9604ba212e..781b988a61 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json @@ -33,6 +33,7 @@ "visibility": "PUBLIC" } }, + "database-info": null, "dir-cur-bld": "", "dir-cur-src": "", "dir-top-bld": "",