From 5b89e46c118d0339b0744daf423a2a6a2c4e5c39 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 9 Jun 2024 12:05:17 -0400 Subject: cmCommandLineArgument: add missing header to source list --- Source/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 67360bc..2dc3bcc 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -140,6 +140,7 @@ add_library( cmCMakePresetsGraphReadJSONTestPresets.cxx cmCMakePresetsGraphReadJSONWorkflowPresets.cxx cmCommandArgumentParserHelper.cxx + cmCommandLineArgument.h cmCommonTargetGenerator.cxx cmCommonTargetGenerator.h cmComputeComponentGraph.cxx -- cgit v0.12 From c66821b22bc65895bb6287d74d55cd9100de2362 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 20 Mar 2024 21:09:04 -0400 Subject: cmGeneratorTarget: add the concept of a "family" name With synthetic targets, a name which is the same between all synthetic targets which share a base target is warranted. --- Source/cmGeneratorTarget.cxx | 14 ++++++++++++++ Source/cmGeneratorTarget.h | 1 + Source/cmTarget.cxx | 11 +++++++++++ Source/cmTarget.h | 1 + 4 files changed, 27 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 9f814c2..312f570 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -173,6 +173,20 @@ const std::string& cmGeneratorTarget::GetName() const return this->Target->GetName(); } +std::string cmGeneratorTarget::GetFamilyName() const +{ + if (!this->IsImported() && !this->IsSynthetic()) { + return this->Target->GetTemplateName(); + } + cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512); + constexpr size_t HASH_TRUNCATION = 12; + auto dirhash = + hasher.HashString(this->GetLocalGenerator()->GetCurrentBinaryDirectory()); + auto targetIdent = hasher.HashString(cmStrCat("@d_", dirhash)); + return cmStrCat(this->Target->GetTemplateName(), '@', + targetIdent.substr(0, HASH_TRUNCATION)); +} + std::string cmGeneratorTarget::GetExportName() const { cmValue exportName = this->GetProperty("EXPORT_NAME"); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 85e6911..dcd4955 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -108,6 +108,7 @@ public: cmStateEnums::TargetType GetType() const; const std::string& GetName() const; + std::string GetFamilyName() const; std::string GetExportName() const; std::string GetFilesystemExportName() const; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index d609d80..32fd16f 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -645,6 +645,7 @@ public: cmStateEnums::TargetType TargetType; cmMakefile* Makefile; cmPolicies::PolicyMap PolicyMap; + cmTarget const* TemplateTarget; std::string Name; std::string InstallPath; std::string RuntimeInstallPath; @@ -931,6 +932,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->impl->TargetType = type; this->impl->Makefile = mf; this->impl->Name = name; + this->impl->TemplateTarget = nullptr; this->impl->IsGeneratorProvided = false; this->impl->HaveInstallRule = false; this->impl->IsDLLPlatform = false; @@ -1186,6 +1188,14 @@ const std::string& cmTarget::GetName() const return this->impl->Name; } +const std::string& cmTarget::GetTemplateName() const +{ + if (this->impl->TemplateTarget) { + return this->impl->TemplateTarget->GetTemplateName(); + } + return this->impl->Name; +} + cmPolicies::PolicyStatus cmTarget::GetPolicyStatus( cmPolicies::PolicyID policy) const { @@ -1784,6 +1794,7 @@ void cmTarget::CopyPolicyStatuses(cmTarget const* tgt) assert(tgt->IsImported()); this->impl->PolicyMap = tgt->impl->PolicyMap; + this->impl->TemplateTarget = tgt; } void cmTarget::CopyImportedCxxModulesEntries(cmTarget const* tgt) diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 98cacef..d0e9e3d 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -78,6 +78,7 @@ public: //! Set/Get the name of the target const std::string& GetName() const; + const std::string& GetTemplateName() const; //! Get the policy map cmPolicies::PolicyMap const& GetPolicyMap() const; -- cgit v0.12 From c48affe037ca3cbc78505188b9dd56f2aa5144dd Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 20 Mar 2024 04:14:51 -0400 Subject: cmMakefile: support "after generator target" generator actions These actions may require additional information gathered during generation. Run them at the appropriate time. --- Source/cmGlobalGenerator.cxx | 7 +++++++ Source/cmMakefile.cxx | 17 +++++++++++++++-- Source/cmMakefile.h | 28 +++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 309a140..aeebc6f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1627,6 +1627,13 @@ bool cmGlobalGenerator::Compute() return false; } + // Perform after-generator-target generator actions. These involve collecting + // information gathered during the construction of generator targets. + for (unsigned int i = 0; i < this->Makefiles.size(); ++i) { + this->Makefiles[i]->GenerateAfterGeneratorTargets( + *this->LocalGenerators[i]); + } + // Add generator specific helper commands for (const auto& localGen : this->LocalGenerators) { localGen->AddHelperCommands(); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2803279..8ffd855 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1055,8 +1055,13 @@ void cmMakefile::AddGeneratorAction(GeneratorAction&& action) } void cmMakefile::GeneratorAction::operator()(cmLocalGenerator& lg, - const cmListFileBacktrace& lfbt) + const cmListFileBacktrace& lfbt, + GeneratorActionWhen when) { + if (this->When != when) { + return; + } + if (cc) { CCAction(lg, lfbt, std::move(cc)); } else { @@ -1073,7 +1078,7 @@ void cmMakefile::DoGenerate(cmLocalGenerator& lg) // give all the commands a chance to do something // after the file has been parsed before generation for (auto& action : this->GeneratorActions) { - action.Value(lg, action.Backtrace); + action.Value(lg, action.Backtrace, GeneratorActionWhen::AfterConfigure); } this->GeneratorActionsInvoked = true; @@ -1107,6 +1112,14 @@ void cmMakefile::Generate(cmLocalGenerator& lg) } } +void cmMakefile::GenerateAfterGeneratorTargets(cmLocalGenerator& lg) +{ + for (auto& action : this->GeneratorActions) { + action.Value(lg, action.Backtrace, + GeneratorActionWhen::AfterGeneratorTargets); + } +} + namespace { // There are still too many implicit backtraces through cmMakefile. As a // workaround we reset the backtrace temporarily. diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index da49af1..6e1739e 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -143,6 +143,14 @@ public: bool EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom = false) const; + enum class GeneratorActionWhen + { + // Run after all CMake code has been parsed. + AfterConfigure, + // Run after generator targets have been constructed. + AfterGeneratorTargets, + }; + class GeneratorAction { using ActionT = @@ -152,20 +160,29 @@ public: std::unique_ptr cc)>; public: - GeneratorAction(ActionT&& action) - : Action(std::move(action)) + GeneratorAction( + ActionT&& action, + GeneratorActionWhen when = GeneratorActionWhen::AfterConfigure) + : When(when) + , Action(std::move(action)) { } - GeneratorAction(std::unique_ptr tcc, CCActionT&& action) - : CCAction(std::move(action)) + GeneratorAction( + std::unique_ptr tcc, CCActionT&& action, + GeneratorActionWhen when = GeneratorActionWhen::AfterConfigure) + : When(when) + , CCAction(std::move(action)) , cc(std::move(tcc)) { } - void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt); + void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + GeneratorActionWhen when); private: + GeneratorActionWhen When; + ActionT Action; // FIXME: Use std::variant @@ -190,6 +207,7 @@ public: * the makefile. */ void Generate(cmLocalGenerator& lg); + void GenerateAfterGeneratorTargets(cmLocalGenerator& lg); /** * Get the target for PRE_BUILD, PRE_LINK, or POST_BUILD commands. -- cgit v0.12 From cf1e36e8c590ad5d40216fbd27881edb3ec341c3 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 28 Sep 2023 11:16:06 -0400 Subject: Tests/CXXModules: factor out running an import test --- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 69 +++++++++------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 8b7bc86..5048d3e 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -304,6 +304,11 @@ if ("internal_partitions" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(internal-partitions) endif () +function (run_cxx_module_import_test type name) + set(RunCMake_CXXModules_INSTALL 0) + run_cxx_module_test(import-modules "import-modules-${name}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${name}-${type}" ${ARGN}) +endfunction () + # Tests which install BMIs if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-interface-no-properties-build) @@ -320,29 +325,14 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) - set(test_suffix export-interface-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build") - - set(test_suffix export-interface-no-properties-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DNO_PROPERTIES=1) - - set(test_suffix export-include-directories-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DINCLUDE_PROPERTIES=1) - - set(test_suffix export-bmi-and-interface-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_BMIS=1) - - set(test_suffix export-command-sepdir-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DEXPORT_COMMAND_SEPDIR=1) - - set(test_suffix export-transitive-targets-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_TARGETS=1) - - set(test_suffix export-transitive-modules-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_MODULES=1) - - set(test_suffix export-with-headers-build) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_HEADERS=1) + run_cxx_module_import_test(build export-interface-build) + run_cxx_module_import_test(build export-interface-no-properties-build -DNO_PROPERTIES=1) + run_cxx_module_import_test(build export-include-directories-build -DINCLUDE_PROPERTIES=1) + run_cxx_module_import_test(build export-bmi-and-interface-build -DWITH_BMIS=1) + run_cxx_module_import_test(build export-command-sepdir-build -DEXPORT_COMMAND_SEPDIR=1) + run_cxx_module_import_test(build export-transitive-targets-build -DTRANSITIVE_TARGETS=1) + run_cxx_module_import_test(build export-transitive-modules-build -DTRANSITIVE_MODULES=1) + run_cxx_module_import_test(build export-with-headers-build -DWITH_HEADERS=1) endif () endif () @@ -369,31 +359,14 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) - set(RunCMake_CXXModules_INSTALL 0) - set(test_suffix export-interface-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install") - - set(test_suffix export-interface-no-properties-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DNO_PROPERTIES=1) - - set(test_suffix export-include-directories-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DINCLUDE_PROPERTIES=1) - - set(test_suffix export-bmi-and-interface-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_BMIS=1) - - set(test_suffix export-command-sepdir-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DEXPORT_COMMAND_SEPDIR=1) - - set(test_suffix export-transitive-targets-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_TARGETS=1) - - set(test_suffix export-transitive-modules-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_MODULES=1) - - set(test_suffix export-with-headers-install) - run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_HEADERS=1) - set(RunCMake_CXXModules_INSTALL 1) + run_cxx_module_import_test(install export-interface-install) + run_cxx_module_import_test(install export-interface-no-properties-install -DNO_PROPERTIES=1) + run_cxx_module_import_test(install export-include-directories-install -DINCLUDE_PROPERTIES=1) + run_cxx_module_import_test(install export-bmi-and-interface-install -DWITH_BMIS=1) + run_cxx_module_import_test(install export-command-sepdir-install -DEXPORT_COMMAND_SEPDIR=1) + run_cxx_module_import_test(install export-transitive-targets-install -DTRANSITIVE_TARGETS=1) + run_cxx_module_import_test(install export-transitive-modules-install -DTRANSITIVE_MODULES=1) + run_cxx_module_import_test(install export-with-headers-install -DWITH_HEADERS=1) endif () endif () endif () -- cgit v0.12 From 7b8b751637c4a2956ef9d899cf18302da038f4ed Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 8 Jun 2024 08:14:57 -0400 Subject: cmGlobalGenerator: add a method to make an output-formatted string This is needed to inject arguments through flag generation mechanisms so that they can all be unescaped uniformly. Eventually, these methods should go away and the escape/unescape dance be avoided completely. --- Source/cmGlobalGenerator.h | 12 ++++++++++++ Source/cmGlobalNinjaGenerator.cxx | 5 +++++ Source/cmGlobalNinjaGenerator.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 5011c17..85dec72 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -594,6 +594,18 @@ public: virtual bool SupportsCrossConfigs() const { return false; } virtual bool SupportsDefaultConfigs() const { return false; } + virtual std::string ConvertToOutputPath(std::string path) const + { + return path; + } + virtual std::string GetConfigDirectory(std::string const& config) const + { + if (!this->IsMultiConfig() || config.empty()) { + return {}; + } + return cmStrCat('/', config); + } + static std::string EscapeJSON(const std::string& s); void ProcessEvaluationFiles(); diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index b051d67..1a7327c 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -3149,6 +3149,11 @@ bool cmGlobalNinjaGenerator::IsSingleConfigUtility( !this->PerConfigUtilityTargets.count(target->GetName()); } +std::string cmGlobalNinjaGenerator::ConvertToOutputPath(std::string path) const +{ + return this->ConvertToNinjaPath(path); +} + const char* cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE = "CMakeFiles/common.ninja"; const char* cmGlobalNinjaMultiGenerator::NINJA_FILE_EXTENSION = ".ninja"; diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 6ad38fb..1cdcfb7 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -484,6 +484,8 @@ public: bool CheckCxxModuleSupport(CxxModuleSupportQuery query) override; + std::string ConvertToOutputPath(std::string path) const override; + protected: std::vector const& GetConfigNames() const; -- cgit v0.12 From 4df5a6fbb485e631d19ff6488e0cc41ded3a8be8 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 24 Sep 2023 15:35:43 -0400 Subject: cmBuildDatabase: add initial structures This class represents a build database as introduced by P2977R0. It includes support for reading, writing, and merging. See: http://wg21.link/p2977r0 --- Source/CMakeLists.txt | 2 + Source/cmBuildDatabase.cxx | 374 +++++++++++++++++++++++++++++++++++++++++++++ Source/cmBuildDatabase.h | 49 ++++++ bootstrap | 1 + 4 files changed, 426 insertions(+) create mode 100644 Source/cmBuildDatabase.cxx create mode 100644 Source/cmBuildDatabase.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 2dc3bcc..c4cd101 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -121,6 +121,8 @@ add_library( cmBinUtilsWindowsPELinker.h cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.cxx cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h + cmBuildDatabase.cxx + cmBuildDatabase.h cmBuildOptions.h cmCacheManager.cxx cmCacheManager.h diff --git a/Source/cmBuildDatabase.cxx b/Source/cmBuildDatabase.cxx new file mode 100644 index 0000000..52220f5 --- /dev/null +++ b/Source/cmBuildDatabase.cxx @@ -0,0 +1,374 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmBuildDatabase.h" + +#include + +#include +#include +#include + +#include +#include +#include + +#include "cmsys/FStream.hxx" + +#include "cmGeneratedFileStream.h" +#include "cmStringAlgorithms.h" +#include "cmSystemTools.h" + +cmBuildDatabase::cmBuildDatabase() = default; +cmBuildDatabase::cmBuildDatabase(cmBuildDatabase const&) = default; +cmBuildDatabase::~cmBuildDatabase() = default; + +void cmBuildDatabase::Write(std::string const& path) const +{ + Json::Value mcdb = Json::objectValue; + + mcdb["version"] = 1; + mcdb["revision"] = 0; + + Json::Value& sets = mcdb["sets"] = Json::arrayValue; + + for (auto const& Set_ : this->Sets) { + Json::Value set = Json::objectValue; + + set["name"] = Set_.Name; + set["family-name"] = Set_.FamilyName; + + Json::Value& visible_sets = set["visible-sets"] = Json::arrayValue; + for (auto const& VisibleSet : Set_.VisibleSets) { + visible_sets.append(VisibleSet); + } + + Json::Value& tus = set["translation-units"] = Json::arrayValue; + for (auto const& TranslationUnit_ : Set_.TranslationUnits) { + Json::Value tu = Json::objectValue; + + if (!TranslationUnit_.WorkDirectory.empty()) { + tu["work-directory"] = TranslationUnit_.WorkDirectory; + } + tu["source"] = TranslationUnit_.Source; + if (TranslationUnit_.Object) { + tu["object"] = *TranslationUnit_.Object; + } + tu["private"] = TranslationUnit_.Private; + + Json::Value& reqs = tu["requires"] = Json::arrayValue; + for (auto const& Require : TranslationUnit_.Requires) { + reqs.append(Require); + } + + Json::Value& provides = tu["provides"] = Json::objectValue; + for (auto const& Provide : TranslationUnit_.Provides) { + provides[Provide.first] = Provide.second; + } + + Json::Value& baseline_arguments = tu["baseline-arguments"] = + Json::arrayValue; + for (auto const& BaselineArgument : TranslationUnit_.BaselineArguments) { + baseline_arguments.append(BaselineArgument); + } + + Json::Value& local_arguments = tu["local-arguments"] = Json::arrayValue; + for (auto const& LocalArgument : TranslationUnit_.LocalArguments) { + local_arguments.append(LocalArgument); + } + + Json::Value& arguments = tu["arguments"] = Json::arrayValue; + for (auto const& Argument : TranslationUnit_.Arguments) { + arguments.append(Argument); + } + + tus.append(tu); + } + + sets.append(set); + } + + cmGeneratedFileStream mcdbf(path); + mcdbf << mcdb; +} + +static bool ParseFilename(Json::Value const& val, std::string& result) +{ + if (val.isString()) { + result = val.asString(); + } else { + return false; + } + + return true; +} + +#define PARSE_BLOB(val, res) \ + do { \ + if (!ParseFilename(val, res)) { \ + cmSystemTools::Error(cmStrCat("-E cmake_module_compile_db failed to ", \ + "parse ", path, ": invalid blob")); \ + return {}; \ + } \ + } while (0) + +#define PARSE_FILENAME(val, res, make_full) \ + do { \ + if (!ParseFilename(val, res)) { \ + cmSystemTools::Error(cmStrCat("-E cmake_module_compile_db failed to ", \ + "parse ", path, ": invalid filename")); \ + return {}; \ + } \ + \ + if (make_full && work_directory && !work_directory->empty() && \ + !cmSystemTools::FileIsFullPath(res)) { \ + res = cmStrCat(*work_directory, '/', res); \ + } \ + } while (0) + +std::unique_ptr cmBuildDatabase::Load(std::string const& path) +{ + Json::Value mcdb; + { + cmsys::ifstream mcdbf(path.c_str(), std::ios::in | std::ios::binary); + Json::Reader reader; + if (!reader.parse(mcdbf, mcdb, false)) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + reader.getFormattedErrorMessages())); + return {}; + } + } + + Json::Value const& version = mcdb["version"]; + if (version.asUInt() > 1) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": version ", version.asString())); + return {}; + } + + auto db = cm::make_unique(); + + Json::Value const& sets = mcdb["sets"]; + if (sets.isArray()) { + for (auto const& set : sets) { + Set Set_; + + Json::Value const& name = set["name"]; + if (!name.isString()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": name is not a string")); + return {}; + } + Set_.Name = name.asString(); + + Json::Value const& family_name = set["family-name"]; + if (!family_name.isString()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": family-name is not a string")); + return {}; + } + Set_.FamilyName = family_name.asString(); + + Json::Value const& visible_sets = set["visible-sets"]; + if (!visible_sets.isArray()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": visible-sets is not an array")); + return {}; + } + for (auto const& visible_set : visible_sets) { + if (!visible_set.isString()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": a visible-sets item is not a string")); + return {}; + } + + Set_.VisibleSets.emplace_back(visible_set.asString()); + } + + Json::Value const& translation_units = set["translation-units"]; + if (!translation_units.isArray()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": translation-units is not an array")); + return {}; + } + for (auto const& translation_unit : translation_units) { + if (!translation_unit.isObject()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": a translation-units item is not an object")); + return {}; + } + + TranslationUnit TranslationUnit_; + + cm::optional work_directory; + Json::Value const& workdir = translation_unit["work-directory"]; + if (workdir.isString()) { + PARSE_BLOB(workdir, TranslationUnit_.WorkDirectory); + work_directory = TranslationUnit_.WorkDirectory; + } else if (!workdir.isNull()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": work-directory is not a string")); + return {}; + } + + Json::Value const& source = translation_unit["source"]; + PARSE_FILENAME(source, TranslationUnit_.Source, true); + + if (translation_unit.isMember("object")) { + Json::Value const& object = translation_unit["object"]; + if (!object.isNull()) { + TranslationUnit_.Object = ""; + PARSE_FILENAME(object, *TranslationUnit_.Object, false); + } + } + + if (translation_unit.isMember("private")) { + Json::Value const& priv = translation_unit["private"]; + if (!priv.isBool()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": private is not a boolean")); + return {}; + } + TranslationUnit_.Private = priv.asBool(); + } + + if (translation_unit.isMember("requires")) { + Json::Value const& reqs = translation_unit["requires"]; + if (!reqs.isArray()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": requires is not an array")); + return {}; + } + + for (auto const& require : reqs) { + if (!require.isString()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": a requires item is not a string")); + return {}; + } + + TranslationUnit_.Requires.emplace_back(require.asString()); + } + } + + if (translation_unit.isMember("provides")) { + Json::Value const& provides = translation_unit["provides"]; + if (!provides.isObject()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": provides is not an object")); + return {}; + } + + for (auto i = provides.begin(); i != provides.end(); ++i) { + if (!i->isString()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": a provides value is not a string")); + return {}; + } + + TranslationUnit_.Provides[i.key().asString()] = i->asString(); + } + } + + if (translation_unit.isMember("baseline-arguments")) { + Json::Value const& baseline_arguments = + translation_unit["baseline-arguments"]; + if (!baseline_arguments.isArray()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": baseline_arguments is not an array")); + return {}; + } + + for (auto const& baseline_argument : baseline_arguments) { + if (baseline_argument.isString()) { + TranslationUnit_.BaselineArguments.emplace_back( + baseline_argument.asString()); + } else { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": a baseline argument is not a string")); + return {}; + } + } + } + + if (translation_unit.isMember("local-arguments")) { + Json::Value const& local_arguments = + translation_unit["local-arguments"]; + if (!local_arguments.isArray()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": local_arguments is not an array")); + return {}; + } + + for (auto const& local_argument : local_arguments) { + if (local_argument.isString()) { + TranslationUnit_.LocalArguments.emplace_back( + local_argument.asString()); + } else { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": a local argument is not a string")); + return {}; + } + } + } + + if (translation_unit.isMember("arguments")) { + Json::Value const& arguments = translation_unit["arguments"]; + if (!arguments.isArray()) { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": arguments is not an array")); + return {}; + } + + for (auto const& argument : arguments) { + if (argument.isString()) { + TranslationUnit_.Arguments.emplace_back(argument.asString()); + } else { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db failed to parse ", path, + ": an argument is not a string")); + return {}; + } + } + } + + Set_.TranslationUnits.emplace_back(std::move(TranslationUnit_)); + } + + db->Sets.emplace_back(std::move(Set_)); + } + } + + return db; +} + +cmBuildDatabase cmBuildDatabase::Merge( + std::vector const& components) +{ + cmBuildDatabase db; + + for (auto const& component : components) { + db.Sets.insert(db.Sets.end(), component.Sets.begin(), + component.Sets.end()); + } + + return db; +} diff --git a/Source/cmBuildDatabase.h b/Source/cmBuildDatabase.h new file mode 100644 index 0000000..0b87562 --- /dev/null +++ b/Source/cmBuildDatabase.h @@ -0,0 +1,49 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +#include +#include +#include +#include + +#include + +class cmBuildDatabase +{ +public: + struct TranslationUnit + { + std::string WorkDirectory; + std::string Source; + cm::optional Object; + std::vector Requires; + std::map Provides; + std::vector BaselineArguments; + std::vector LocalArguments; + std::vector Arguments; + bool Private = false; + }; + + struct Set + { + std::string Name; + std::string FamilyName; + std::vector VisibleSets; + std::vector TranslationUnits; + }; + + cmBuildDatabase(); + cmBuildDatabase(cmBuildDatabase const&); + ~cmBuildDatabase(); + + void Write(std::string const& path) const; + + static std::unique_ptr Load(std::string const& path); + static cmBuildDatabase Merge(std::vector const& components); + +private: + std::vector Sets; +}; diff --git a/bootstrap b/bootstrap index 96d331f..53358d5 100755 --- a/bootstrap +++ b/bootstrap @@ -306,6 +306,7 @@ CMAKE_CXX_SOURCES="\ cmBlockCommand \ cmBreakCommand \ cmBuildCommand \ + cmBuildDatabase \ cmCMakeLanguageCommand \ cmCMakeMinimumRequired \ cmList \ -- cgit v0.12 From c96ea5684de56dc8e85381a958ed33ebc782d852 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 24 Sep 2023 15:37:39 -0400 Subject: cmcmd: add a tool to manage module compilation databases Includes verification and merging subcommands to start with. --- Source/cmBuildDatabase.cxx | 87 ++++++++++++++++++++++++++++++++++++++++++++++ Source/cmcmd.cxx | 8 +++++ 2 files changed, 95 insertions(+) diff --git a/Source/cmBuildDatabase.cxx b/Source/cmBuildDatabase.cxx index 52220f5..b2d714f 100644 --- a/Source/cmBuildDatabase.cxx +++ b/Source/cmBuildDatabase.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmBuildDatabase.h" +#include #include #include @@ -372,3 +373,89 @@ cmBuildDatabase cmBuildDatabase::Merge( return db; } + +int cmcmd_cmake_module_compile_db( + std::vector::const_iterator argBeg, + std::vector::const_iterator argEnd) +{ + const std::string* command = nullptr; + const std::string* output = nullptr; + std::vector inputs; + + bool next_is_output = false; + for (auto i = argBeg; i != argEnd; ++i) { + // The first argument is always the command. + if (!command) { + command = &(*i); + continue; + } + + if (*i == "-o"_s) { + next_is_output = true; + continue; + } + if (next_is_output) { + if (output) { + cmSystemTools::Error( + "-E cmake_module_compile_db only supports one output file"); + return EXIT_FAILURE; + } + + output = &(*i); + next_is_output = false; + continue; + } + + inputs.emplace_back(&(*i)); + } + + if (!command) { + cmSystemTools::Error("-E cmake_module_compile_db requires a subcommand"); + return EXIT_FAILURE; + } + + int ret = EXIT_SUCCESS; + + if (*command == "verify"_s) { + if (output) { + cmSystemTools::Error( + "-E cmake_module_compile_db verify does not support an output"); + return EXIT_FAILURE; + } + + for (auto const* i : inputs) { + auto db = cmBuildDatabase::Load(*i); + if (!db) { + cmSystemTools::Error(cmStrCat("failed to verify ", *i)); + ret = EXIT_FAILURE; + } + } + } else if (*command == "merge"_s) { + if (!output) { + cmSystemTools::Error( + "-E cmake_module_compile_db verify requires an output"); + return EXIT_FAILURE; + } + + std::vector dbs; + + for (auto const* i : inputs) { + auto db = cmBuildDatabase::Load(*i); + if (!db) { + cmSystemTools::Error(cmStrCat("failed to read ", *i)); + return EXIT_FAILURE; + } + + dbs.emplace_back(std::move(*db)); + } + + auto db = cmBuildDatabase::Merge(dbs); + db.Write(*output); + } else { + cmSystemTools::Error( + cmStrCat("-E cmake_module_compile_db unknown subcommand ", *command)); + return EXIT_FAILURE; + } + + return ret; +} diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index eaff8ef..a23f34a 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -78,6 +78,9 @@ int cmcmd_cmake_ninja_depends(std::vector::const_iterator argBeg, std::vector::const_iterator argEnd); int cmcmd_cmake_ninja_dyndep(std::vector::const_iterator argBeg, std::vector::const_iterator argEnd); +int cmcmd_cmake_module_compile_db( + std::vector::const_iterator argBeg, + std::vector::const_iterator argEnd); namespace { // ATTENTION If you add new commands, change here, @@ -1394,6 +1397,11 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args, } #endif + // Internal CMake C++ module compilation database support. + if (args[1] == "cmake_module_compile_db") { + return cmcmd_cmake_module_compile_db(args.begin() + 2, args.end()); + } + // Internal CMake unimplemented feature notification. if (args[1] == "cmake_unimplemented_variable") { std::cerr << "Feature not implemented for this platform."; -- cgit v0.12 From cedfaa010fc7c084c676be079c9845c84ac302ce Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 6 May 2024 18:06:11 -0400 Subject: cmGeneratorTarget: add a method to build classified command lines This is essentially an extraction of the `Ninja` generator's command line building logic. Porting generators to reuse this construction is a task for the future. --- Source/cmGeneratorTarget.cxx | 420 +++++++++++++++++++++++++++++++++++++++++++ Source/cmGeneratorTarget.h | 59 ++++++ 2 files changed, 479 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 312f570..293a4b7 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -37,6 +37,7 @@ #include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPropertyMap.h" +#include "cmRulePlaceholderExpander.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmSourceFileLocationKind.h" @@ -2024,6 +2025,425 @@ std::vector cmGeneratorTarget::GetAppleArchs( return std::move(archList.data()); } +namespace { + +bool IsSupportedClassifiedFlagsLanguage(std::string const& lang) +{ + return lang == "CXX"_s; +} + +bool CanUseCompilerLauncher(std::string const& lang) +{ + // Also found in `cmCommonTargetGenerator::GetCompilerLauncher`. + return lang == "C"_s || lang == "CXX"_s || lang == "Fortran"_s || + lang == "CUDA"_s || lang == "HIP"_s || lang == "ISPC"_s || + lang == "OBJC"_s || lang == "OBJCXX"_s; +} + +// FIXME: return a vector of `cm::string_view` instead to avoid lots of tiny +// allocations. +std::vector SplitFlags(std::string const& flags) +{ + std::vector options; + +#ifdef _WIN32 + cmSystemTools::ParseWindowsCommandLine(flags.c_str(), options); +#else + cmSystemTools::ParseUnixCommandLine(flags.c_str(), options); +#endif + + return options; +} + +} + +cmGeneratorTarget::ClassifiedFlags +cmGeneratorTarget::GetClassifiedFlagsForSource(cmSourceFile const* sf, + std::string const& config) +{ + auto& sourceFlagsCache = this->Configs[config].SourceFlags; + auto cacheEntry = sourceFlagsCache.lower_bound(sf); + if (cacheEntry != sourceFlagsCache.end() && cacheEntry->first == sf) { + return cacheEntry->second; + } + + ClassifiedFlags flags; + std::string const& lang = sf->GetLanguage(); + + if (!IsSupportedClassifiedFlagsLanguage(lang)) { + return flags; + } + + auto* const lg = this->GetLocalGenerator(); + auto const* const mf = this->Makefile; + + // Compute the compiler launcher flags. + if (CanUseCompilerLauncher(lang)) { + // Compiler launchers are all execution flags and should not be relevant to + // the actual compilation. + FlagClassification cls = FlagClassification::ExecutionFlag; + FlagKind kind = FlagKind::NotAFlag; + + std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER"); + cmValue clauncher = this->GetProperty(clauncher_prop); + std::string const evaluatedClauncher = cmGeneratorExpression::Evaluate( + *clauncher, lg, config, this, nullptr, this, lang); + + for (auto const& flag : SplitFlags(evaluatedClauncher)) { + flags.emplace_back(cls, kind, flag); + } + } + + ClassifiedFlags define_flags; + ClassifiedFlags include_flags; + ClassifiedFlags compile_flags; + + SourceVariables sfVars = this->GetSourceVariables(sf, config); + + // Compute language flags. + { + FlagClassification cls = FlagClassification::BaselineFlag; + FlagKind kind = FlagKind::Compile; + + std::string mfFlags; + // Explicitly add the explicit language flag before any other flag + // so user flags can override it. + this->AddExplicitLanguageFlags(mfFlags, *sf); + + for (auto const& flag : SplitFlags(mfFlags)) { + flags.emplace_back(cls, kind, flag); + } + } + + std::unordered_map pchSources; + std::string filterArch; + + { + std::vector pchArchs = this->GetPchArchs(config, lang); + + for (const std::string& arch : pchArchs) { + const std::string pchSource = this->GetPchSource(config, lang, arch); + if (pchSource == sf->GetFullPath()) { + filterArch = arch; + } + if (!pchSource.empty()) { + pchSources.insert(std::make_pair(pchSource, arch)); + } + } + } + + // Compute target-wide flags. + { + FlagClassification cls = FlagClassification::BaselineFlag; + + // Compile flags + { + FlagKind kind = FlagKind::Compile; + std::string targetFlags; + + lg->GetTargetCompileFlags(this, config, lang, targetFlags, filterArch); + + for (auto&& flag : SplitFlags(targetFlags)) { + compile_flags.emplace_back(cls, kind, std::move(flag)); + } + } + + // Define flags + { + FlagKind kind = FlagKind::Definition; + std::set defines; + + lg->GetTargetDefines(this, config, lang, defines); + + std::string defineFlags; + lg->JoinDefines(defines, defineFlags, lang); + + for (auto&& flag : SplitFlags(defineFlags)) { + define_flags.emplace_back(cls, kind, std::move(flag)); + } + } + + // Include flags + { + FlagKind kind = FlagKind::Include; + std::vector includes; + + lg->GetIncludeDirectories(includes, this, lang, config); + auto includeFlags = + lg->GetIncludeFlags(includes, this, lang, config, false); + + for (auto&& flag : SplitFlags(includeFlags)) { + include_flags.emplace_back(cls, kind, std::move(flag)); + } + } + } + + const std::string COMPILE_FLAGS("COMPILE_FLAGS"); + const std::string COMPILE_OPTIONS("COMPILE_OPTIONS"); + + cmGeneratorExpressionInterpreter genexInterpreter(lg, config, this, lang); + + // Source-specific flags. + { + FlagClassification cls = FlagClassification::PrivateFlag; + FlagKind kind = FlagKind::Compile; + + std::string sourceFlags; + + if (cmValue cflags = sf->GetProperty(COMPILE_FLAGS)) { + lg->AppendFlags(sourceFlags, + genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS)); + } + + if (cmValue coptions = sf->GetProperty(COMPILE_OPTIONS)) { + lg->AppendCompileOptions( + sourceFlags, genexInterpreter.Evaluate(*coptions, COMPILE_OPTIONS)); + } + + for (auto&& flag : SplitFlags(sourceFlags)) { + compile_flags.emplace_back(cls, kind, std::move(flag)); + } + + // Dependency tracking flags. + { + if (!sfVars.DependencyFlags.empty()) { + cmRulePlaceholderExpander::RuleVariables vars; + auto rulePlaceholderExpander = lg->CreateRulePlaceholderExpander(); + + vars.DependencyFile = sfVars.DependencyFile.c_str(); + vars.DependencyTarget = sfVars.DependencyTarget.c_str(); + + std::string depfileFlags = sfVars.DependencyFlags; + rulePlaceholderExpander->ExpandRuleVariables(lg, depfileFlags, vars); + for (auto&& flag : SplitFlags(depfileFlags)) { + compile_flags.emplace_back(FlagClassification::LocationFlag, + FlagKind::BuildSystem, std::move(flag)); + } + } + } + } + + // Precompiled headers. + { + FlagClassification cls = FlagClassification::PrivateFlag; + FlagKind kind = FlagKind::Compile; + + std::string pchFlags; + + // Add precompile headers compile options. + if (!sf->GetProperty("SKIP_PRECOMPILE_HEADERS")) { + if (!pchSources.empty()) { + std::string pchOptions; + auto pchIt = pchSources.find(sf->GetFullPath()); + if (pchIt != pchSources.end()) { + pchOptions = + this->GetPchCreateCompileOptions(config, lang, pchIt->second); + } else { + pchOptions = this->GetPchUseCompileOptions(config, lang); + } + + this->LocalGenerator->AppendCompileOptions( + pchFlags, genexInterpreter.Evaluate(pchOptions, COMPILE_OPTIONS)); + } + } + + for (auto&& flag : SplitFlags(pchFlags)) { + compile_flags.emplace_back(cls, kind, std::move(flag)); + } + } + + // C++ module flags. + if (lang == "CXX"_s) { + FlagClassification cls = FlagClassification::LocationFlag; + FlagKind kind = FlagKind::BuildSystem; + + std::string bmiFlags; + + auto const* fs = this->GetFileSetForSource(config, sf); + if (fs && fs->GetType() == "CXX_MODULES"_s) { + if (lang != "CXX"_s) { + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat( + "Target \"", this->Target->GetName(), "\" contains the source\n ", + sf->GetFullPath(), "\nin a file set of type \"", fs->GetType(), + R"(" but the source is not classified as a "CXX" source.)")); + } + + if (!this->Target->IsNormal()) { + auto flag = mf->GetSafeDefinition("CMAKE_CXX_MODULE_BMI_ONLY_FLAG"); + cmRulePlaceholderExpander::RuleVariables compileObjectVars; + compileObjectVars.Object = sfVars.ObjectFileDir.c_str(); + auto rulePlaceholderExpander = lg->CreateRulePlaceholderExpander(); + rulePlaceholderExpander->ExpandRuleVariables(lg, flag, + compileObjectVars); + lg->AppendCompileOptions(bmiFlags, flag); + } + } + + for (auto&& flag : SplitFlags(bmiFlags)) { + compile_flags.emplace_back(cls, kind, std::move(flag)); + } + } + + cmRulePlaceholderExpander::RuleVariables vars; + vars.CMTargetName = this->GetName().c_str(); + vars.CMTargetType = cmState::GetTargetTypeName(this->GetType()).c_str(); + vars.Language = lang.c_str(); + auto const sfPath = this->LocalGenerator->ConvertToOutputFormat( + sf->GetFullPath(), cmOutputConverter::SHELL); + + // Compute the base compiler command line. We'll find placeholders and + // replace them with arguments later in this function. + { + FlagClassification cls = FlagClassification::ExecutionFlag; + FlagKind kind = FlagKind::NotAFlag; + + std::string const cmdVar = cmStrCat("CMAKE_", lang, "_COMPILE_OBJECT"); + std::string const& compileCmd = mf->GetRequiredDefinition(cmdVar); + cmList compileCmds(compileCmd); // FIXME: which command to use? + std::string& cmd = compileCmds[0]; + auto rulePlaceholderExpander = lg->CreateRulePlaceholderExpander(); + + static std::string const PlaceholderDefines = "__CMAKE_DEFINES"; + static std::string const PlaceholderIncludes = "__CMAKE_INCLUDES"; + static std::string const PlaceholderFlags = "__CMAKE_FLAGS"; + static std::string const PlaceholderSource = "__CMAKE_SOURCE"; + + vars.Defines = PlaceholderDefines.c_str(); + vars.Includes = PlaceholderIncludes.c_str(); + vars.TargetPDB = sfVars.TargetPDB.c_str(); + vars.TargetCompilePDB = sfVars.TargetCompilePDB.c_str(); + vars.Object = sfVars.ObjectFileDir.c_str(); + vars.ObjectDir = sfVars.ObjectDir.c_str(); + vars.ObjectFileDir = sfVars.ObjectFileDir.c_str(); + vars.Flags = PlaceholderFlags.c_str(); + vars.DependencyFile = sfVars.DependencyFile.c_str(); + vars.DependencyTarget = sfVars.DependencyTarget.c_str(); + vars.Source = PlaceholderSource.c_str(); + + rulePlaceholderExpander->ExpandRuleVariables(lg, cmd, vars); + for (auto&& flag : SplitFlags(cmd)) { + if (flag == PlaceholderDefines) { + flags.insert(flags.end(), define_flags.begin(), define_flags.end()); + } else if (flag == PlaceholderIncludes) { + flags.insert(flags.end(), include_flags.begin(), include_flags.end()); + } else if (flag == PlaceholderFlags) { + flags.insert(flags.end(), compile_flags.begin(), compile_flags.end()); + } else if (flag == PlaceholderSource) { + flags.emplace_back(FlagClassification::LocationFlag, + FlagKind::BuildSystem, sfPath); + } else { + flags.emplace_back(cls, kind, std::move(flag)); + // All remaining flags here are build system flags. + kind = FlagKind::BuildSystem; + } + } + } + + cacheEntry = sourceFlagsCache.emplace_hint(cacheEntry, sf, std::move(flags)); + return cacheEntry->second; +} + +cmGeneratorTarget::SourceVariables cmGeneratorTarget::GetSourceVariables( + cmSourceFile const* sf, std::string const& config) +{ + SourceVariables vars; + auto const language = sf->GetLanguage(); + auto const targetType = this->GetType(); + auto const* const lg = this->GetLocalGenerator(); + auto const* const gg = this->GetGlobalGenerator(); + auto const* const mf = this->Makefile; + + // PDB settings. + { + if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || + mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID") || + mf->GetDefinition("MSVC_CUDA_ARCHITECTURE_ID")) { + std::string pdbPath; + std::string compilePdbPath; + if (targetType <= cmStateEnums::OBJECT_LIBRARY) { + compilePdbPath = this->GetCompilePDBPath(config); + if (compilePdbPath.empty()) { + // Match VS default: `$(IntDir)vc$(PlatformToolsetVersion).pdb`. + // A trailing slash tells the toolchain to add its default file name. + compilePdbPath = this->GetSupportDirectory(); + if (gg->IsMultiConfig()) { + compilePdbPath = cmStrCat(compilePdbPath, '/', config); + } + compilePdbPath += '/'; + if (targetType == cmStateEnums::STATIC_LIBRARY) { + // Match VS default for static libs: `$(IntDir)$(ProjectName).pdb`. + compilePdbPath = cmStrCat(compilePdbPath, this->GetName(), ".pdb"); + } + } + } + + if (targetType == cmStateEnums::EXECUTABLE || + targetType == cmStateEnums::STATIC_LIBRARY || + targetType == cmStateEnums::SHARED_LIBRARY || + targetType == cmStateEnums::MODULE_LIBRARY) { + pdbPath = cmStrCat(this->GetPDBDirectory(config), '/', + this->GetPDBName(config)); + } + + vars.TargetPDB = lg->ConvertToOutputFormat( + gg->ConvertToOutputPath(std::move(pdbPath)), cmOutputConverter::SHELL); + vars.TargetCompilePDB = lg->ConvertToOutputFormat( + gg->ConvertToOutputPath(std::move(compilePdbPath)), + cmOutputConverter::SHELL); + } + } + + // Object settings. + { + std::string const objectDir = gg->ConvertToOutputPath( + cmStrCat(this->GetSupportDirectory(), gg->GetConfigDirectory(config))); + std::string const objectFileName = this->GetObjectName(sf); + std::string const objectFilePath = + cmStrCat(objectDir, '/', objectFileName); + + vars.ObjectDir = + lg->ConvertToOutputFormat(objectDir, cmOutputConverter::SHELL); + vars.ObjectFileDir = + lg->ConvertToOutputFormat(objectFilePath, cmOutputConverter::SHELL); + + // Dependency settings. + { + std::string const depfileFormatName = + cmStrCat("CMAKE_", language, "_DEPFILE_FORMAT"); + std::string const depfileFormat = + mf->GetSafeDefinition(depfileFormatName); + if (depfileFormat != "msvc"_s) { + std::string const flagsName = + cmStrCat("CMAKE_DEPFILE_FLAGS_", language); + std::string const depfileFlags = mf->GetSafeDefinition(flagsName); + if (!depfileFlags.empty()) { + bool replaceExt = false; + if (!language.empty()) { + std::string const repVar = + cmStrCat("CMAKE_", language, "_DEPFILE_EXTENSION_REPLACE"); + replaceExt = mf->IsOn(repVar); + } + std::string const depfilePath = cmStrCat( + objectDir, '/', + replaceExt + ? cmSystemTools::GetFilenameWithoutLastExtension(objectFileName) + : objectFileName, + ".d"); + + vars.DependencyFlags = depfileFlags; + vars.DependencyTarget = vars.ObjectFileDir; + vars.DependencyFile = + lg->ConvertToOutputFormat(depfilePath, cmOutputConverter::SHELL); + } + } + } + } + + return vars; +} + void cmGeneratorTarget::AddExplicitLanguageFlags(std::string& flags, cmSourceFile const& sf) const { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index dcd4955..210f0ab 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -517,6 +517,64 @@ public: std::vector GetAppleArchs(std::string const& config, cm::optional lang) const; + // The classification of the flag. + enum class FlagClassification + { + // The flag is for the execution of the tool (e.g., the compiler itself, + // any launchers, etc.). + ExecutionFlag, + // The flag is "baseline" and should be apply to TUs which may interact + // with this compilation (e.g., imported modules). + BaselineFlag, + // The flag is "private" and doesn't need to apply to interacting TUs. + PrivateFlag, + // Flags for the TU itself (e.g., output paths, dependency scanning, etc.). + LocationFlag, + }; + enum class FlagKind + { + // Not a flag (executable or other entries). + NotAFlag, + // Flags for support of the build system. + BuildSystem, + // A compilation flag. + Compile, + // An include flag. + Include, + // A compile definition. + Definition, + }; + struct ClassifiedFlag + { + ClassifiedFlag(FlagClassification cls, FlagKind kind, std::string flag) + : Classification(cls) + , Kind(kind) + , Flag(std::move(flag)) + { + } + + FlagClassification Classification; + FlagKind Kind; + std::string Flag; + }; + using ClassifiedFlags = std::vector; + ClassifiedFlags GetClassifiedFlagsForSource(cmSourceFile const* sf, + std::string const& config); + struct SourceVariables + { + std::string TargetPDB; + std::string TargetCompilePDB; + std::string ObjectDir; + std::string ObjectFileDir; + std::string DependencyFile; + std::string DependencyTarget; + + // Dependency flags (if used) + std::string DependencyFlags; + }; + SourceVariables GetSourceVariables(cmSourceFile const* sf, + std::string const& config); + void AddExplicitLanguageFlags(std::string& flags, cmSourceFile const& sf) const; @@ -1452,6 +1510,7 @@ private: std::map FileSetCache; std::map> SyntheticDeps; + std::map SourceFlags; }; mutable std::map Configs; }; -- cgit v0.12 From 48faa19c194364ab33a2a95ddc6a9f003e9d2e06 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 1 Oct 2023 10:23:00 -0400 Subject: cmBuildDatabase: support writing template files --- Source/cmBuildDatabase.cxx | 86 ++++++++++++++++++++++++++++++++++++++++++++++ Source/cmBuildDatabase.h | 4 +++ 2 files changed, 90 insertions(+) diff --git a/Source/cmBuildDatabase.cxx b/Source/cmBuildDatabase.cxx index b2d714f..fafcee1 100644 --- a/Source/cmBuildDatabase.cxx +++ b/Source/cmBuildDatabase.cxx @@ -3,6 +3,7 @@ #include "cmBuildDatabase.h" #include +#include #include #include @@ -15,10 +16,23 @@ #include "cmsys/FStream.hxx" +#include "cmComputeLinkInformation.h" +#include "cmFileSet.h" #include "cmGeneratedFileStream.h" +#include "cmGeneratorTarget.h" +#include "cmGlobalGenerator.h" +#include "cmListFileCache.h" +#include "cmLocalGenerator.h" +#include "cmSourceFile.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" +namespace { + +std::string PlaceholderName = "<__CMAKE_UNKNOWN>"; + +} + cmBuildDatabase::cmBuildDatabase() = default; cmBuildDatabase::cmBuildDatabase(cmBuildDatabase const&) = default; cmBuildDatabase::~cmBuildDatabase() = default; @@ -374,6 +388,78 @@ cmBuildDatabase cmBuildDatabase::Merge( return db; } +cmBuildDatabase cmBuildDatabase::ForTarget(cmGeneratorTarget* gt, + std::string const& config) +{ + cmBuildDatabase db; + + Set set; + set.Name = cmStrCat(gt->GetName(), '@', config); + set.FamilyName = gt->GetFamilyName(); + if (auto* cli = gt->GetLinkInformation(config)) { + std::set emitted; + std::vector targets; + for (auto const& item : cli->GetItems()) { + auto const* linkee = item.Target; + if (linkee && linkee->HaveCxx20ModuleSources() && + !linkee->IsImported() && emitted.insert(linkee).second) { + set.VisibleSets.push_back(cmStrCat(linkee->GetName(), '@', config)); + } + } + } + + for (auto const& sfbt : gt->GetSourceFiles(config)) { + auto const* sf = sfbt.Value; + + bool isCXXModule = false; + bool isPrivate = true; + if (sf->GetLanguage() != "CXX"_s) { + auto const* fs = gt->GetFileSetForSource(config, sf); + if (fs && fs->GetType() == "CXX_MODULES"_s) { + isCXXModule = true; + isPrivate = !cmFileSetVisibilityIsForInterface(fs->GetVisibility()); + } + } + + TranslationUnit tu; + + // FIXME: Makefiles will want this to be the current working directory. + tu.WorkDirectory = gt->GetLocalGenerator()->GetBinaryDirectory(); + tu.Source = sf->GetFullPath(); + if (!gt->IsSynthetic()) { + auto* gg = gt->GetGlobalGenerator(); + std::string const objectDir = gg->ConvertToOutputPath( + cmStrCat(gt->GetSupportDirectory(), gg->GetConfigDirectory(config))); + std::string const objectFileName = gt->GetObjectName(sf); + tu.Object = cmStrCat(objectDir, '/', objectFileName); + } + if (isCXXModule) { + tu.Provides[PlaceholderName] = PlaceholderName; + } + + cmGeneratorTarget::ClassifiedFlags classifiedFlags = + gt->GetClassifiedFlagsForSource(sf, config); + for (auto const& classifiedFlag : classifiedFlags) { + if (classifiedFlag.Classification == + cmGeneratorTarget::FlagClassification::BaselineFlag) { + tu.BaselineArguments.push_back(classifiedFlag.Flag); + tu.LocalArguments.push_back(classifiedFlag.Flag); + } else if (classifiedFlag.Classification == + cmGeneratorTarget::FlagClassification::PrivateFlag) { + tu.LocalArguments.push_back(classifiedFlag.Flag); + } + tu.Arguments.push_back(classifiedFlag.Flag); + } + tu.Private = isPrivate; + + set.TranslationUnits.emplace_back(std::move(tu)); + } + + db.Sets.emplace_back(std::move(set)); + + return db; +} + int cmcmd_cmake_module_compile_db( std::vector::const_iterator argBeg, std::vector::const_iterator argEnd) diff --git a/Source/cmBuildDatabase.h b/Source/cmBuildDatabase.h index 0b87562..8ed35ec 100644 --- a/Source/cmBuildDatabase.h +++ b/Source/cmBuildDatabase.h @@ -11,6 +11,8 @@ #include +class cmGeneratorTarget; + class cmBuildDatabase { public: @@ -43,6 +45,8 @@ public: static std::unique_ptr Load(std::string const& path); static cmBuildDatabase Merge(std::vector const& components); + static cmBuildDatabase ForTarget(cmGeneratorTarget* gt, + std::string const& config); private: std::vector Sets; -- cgit v0.12 From 9c0491a3e41a0232ae10d53c0e12921bf1be4880 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 25 Mar 2024 07:30:04 -0400 Subject: cmDyndepCollation: write out scanned source information too This is required to fill in the `requires` field for sources using modules that do not provide them. --- Source/cmDyndepCollation.cxx | 126 ++++++++++++++------- .../expect/NinjaDependInfoBMIInstall-private.json | 3 +- .../expect/NinjaDependInfoBMIInstall-public.json | 3 +- .../expect/NinjaDependInfoExport-private.json | 3 +- .../expect/NinjaDependInfoExport-public.json | 3 +- ...injaDependInfoExportFilesystemSafe-private.json | 3 +- ...NinjaDependInfoExportFilesystemSafe-public.json | 3 +- .../expect/NinjaDependInfoFileSet-private.json | 20 +++- .../expect/NinjaDependInfoFileSet-public.json | 20 +++- 9 files changed, 137 insertions(+), 47 deletions(-) diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx index bfe3a75..cbb0e34 100644 --- a/Source/cmDyndepCollation.cxx +++ b/Source/cmDyndepCollation.cxx @@ -39,13 +39,55 @@ namespace { -Json::Value CollationInformationCxxModules( - cmGeneratorTarget const* gt, std::string const& config, - cmDyndepGeneratorCallbacks const& cb) +struct TdiSourceInfo +{ + Json::Value Sources; + Json::Value CxxModules; +}; + +TdiSourceInfo CollationInformationSources(cmGeneratorTarget const* gt, + std::string const& config, + cmDyndepGeneratorCallbacks const& cb) { + TdiSourceInfo info; cmTarget const* tgt = gt->Target; auto all_file_sets = tgt->GetAllFileSetNames(); - Json::Value tdi_cxx_module_info = Json::objectValue; + Json::Value& tdi_sources = info.Sources = Json::objectValue; + Json::Value& tdi_cxx_module_info = info.CxxModules = Json::objectValue; + + enum class CompileType + { + ObjectAndBmi, + BmiOnly, + }; + std::map> sf_map; + { + auto fill_sf_map = [gt, tgt, &sf_map](cmSourceFile const* sf, + CompileType type) { + auto full_path = sf->GetFullPath(); + if (full_path.empty()) { + gt->Makefile->IssueMessage( + MessageType::INTERNAL_ERROR, + cmStrCat("Target \"", tgt->GetName(), + "\" has a full path-less source file.")); + return; + } + sf_map[full_path] = std::make_pair(sf, type); + }; + + std::vector objectSources; + gt->GetObjectSources(objectSources, config); + for (auto const* sf : objectSources) { + fill_sf_map(sf, CompileType::ObjectAndBmi); + } + + std::vector cxxModuleSources; + gt->GetCxxModuleSources(cxxModuleSources, config); + for (auto const* sf : cxxModuleSources) { + fill_sf_map(sf, CompileType::BmiOnly); + } + } + for (auto const& file_set_name : all_file_sets) { auto const* file_set = tgt->GetFileSet(file_set_name); if (!file_set) { @@ -73,39 +115,6 @@ Json::Value CollationInformationCxxModules( gt->LocalGenerator, config, gt); } - enum class CompileType - { - ObjectAndBmi, - BmiOnly, - }; - std::map> sf_map; - { - auto fill_sf_map = [gt, tgt, &sf_map](cmSourceFile const* sf, - CompileType type) { - auto full_path = sf->GetFullPath(); - if (full_path.empty()) { - gt->Makefile->IssueMessage( - MessageType::INTERNAL_ERROR, - cmStrCat("Target \"", tgt->GetName(), - "\" has a full path-less source file.")); - return; - } - sf_map[full_path] = std::make_pair(sf, type); - }; - - std::vector objectSources; - gt->GetObjectSources(objectSources, config); - for (auto const* sf : objectSources) { - fill_sf_map(sf, CompileType::ObjectAndBmi); - } - - std::vector cxxModuleSources; - gt->GetCxxModuleSources(cxxModuleSources, config); - for (auto const* sf : cxxModuleSources) { - fill_sf_map(sf, CompileType::BmiOnly); - } - } - Json::Value fs_dest = Json::nullValue; for (auto const& ig : gt->Makefile->GetInstallGenerators()) { if (auto const* fsg = @@ -134,6 +143,8 @@ Json::Value CollationInformationCxxModules( auto const* sf = lookup->second.first; CompileType const ct = lookup->second.second; + sf_map.erase(lookup); + if (!sf) { gt->Makefile->IssueMessage( MessageType::INTERNAL_ERROR, @@ -160,7 +171,26 @@ Json::Value CollationInformationCxxModules( } } - return tdi_cxx_module_info; + for (auto const& sf_entry : sf_map) { + CompileType const ct = sf_entry.second.second; + if (ct == CompileType::BmiOnly) { + continue; + } + + auto const* sf = sf_entry.second.first; + if (!gt->NeedDyndepForSource(sf->GetLanguage(), config, sf)) { + continue; + } + + auto full_file = cmSystemTools::CollapseFullPath(sf->GetFullPath()); + auto obj_path = cb.ObjectFilePath(sf, config); + Json::Value& tdi_source_info = tdi_sources[obj_path] = Json::objectValue; + + tdi_source_info["source"] = full_file; + tdi_source_info["language"] = sf->GetLanguage(); + } + + return info; } Json::Value CollationInformationBmiInstallation(cmGeneratorTarget const* gt, @@ -289,12 +319,20 @@ void cmDyndepCollation::AddCollationInformation( Json::Value& tdi, cmGeneratorTarget const* gt, std::string const& config, cmDyndepGeneratorCallbacks const& cb) { - tdi["cxx-modules"] = CollationInformationCxxModules(gt, config, cb); + auto sourcesInfo = CollationInformationSources(gt, config, cb); + tdi["sources"] = sourcesInfo.Sources; + tdi["cxx-modules"] = sourcesInfo.CxxModules; tdi["bmi-installation"] = CollationInformationBmiInstallation(gt, config); tdi["exports"] = CollationInformationExports(gt); tdi["config"] = config; } +struct SourceInfo +{ + std::string SourcePath; + std::string Language; +}; + struct CxxModuleFileSet { std::string Name; @@ -330,6 +368,7 @@ struct CxxModuleExport struct cmCxxModuleExportInfo { + std::map ObjectToSource; std::map ObjectToFileSet; cm::optional BmiInstallation; std::vector Exports; @@ -405,6 +444,15 @@ cmDyndepCollation::ParseExportInfo(Json::Value const& tdi) } } } + Json::Value const& tdi_sources = tdi["sources"]; + if (tdi_sources.isObject()) { + for (auto i = tdi_sources.begin(); i != tdi_sources.end(); ++i) { + SourceInfo& si = export_info->ObjectToSource[i.key().asString()]; + auto const& tdi_source = *i; + si.SourcePath = tdi_source["source"].asString(); + si.Language = tdi_source["language"].asString(); + } + } return export_info; } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json index 78f7928..4bb2455 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-private.json @@ -47,5 +47,6 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-bmi-install-private.dir" + "module-dir": "/CMakeFiles/ninja-bmi-install-private.dir", + "sources": {} } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json index 6c23354..364bce2 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoBMIInstall-public.json @@ -47,5 +47,6 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-bmi-install-public.dir" + "module-dir": "/CMakeFiles/ninja-bmi-install-public.dir", + "sources": {} } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json index 71b2b66..45cd8ab 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-private.json @@ -79,5 +79,6 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-exports-private.dir" + "module-dir": "/CMakeFiles/ninja-exports-private.dir", + "sources": {} } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json index a9cde99..43a4e4f 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExport-public.json @@ -79,5 +79,6 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-exports-public.dir" + "module-dir": "/CMakeFiles/ninja-exports-public.dir", + "sources": {} } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json index 7905c53..03e2018 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-private.json @@ -79,5 +79,6 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-exports-private.dir" + "module-dir": "/CMakeFiles/ninja-exports-private.dir", + "sources": {} } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json index 1734590..4128252 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoExportFilesystemSafe-public.json @@ -79,5 +79,6 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-exports-public.dir" + "module-dir": "/CMakeFiles/ninja-exports-public.dir", + "sources": {} } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json index ed61e0e..f4e19f4 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-private.json @@ -42,5 +42,23 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-file-sets-private.dir" + "module-dir": "/CMakeFiles/ninja-file-sets-private.dir", + "sources": { + "CMakeFiles/ninja-file-sets-private.dir/sources/module-impl.cxx" : { + "language" : "CXX", + "source" : "/sources/module-impl.cxx" + }, + "CMakeFiles/ninja-file-sets-private.dir/sources/module-internal-part-impl.cxx" : { + "language" : "CXX", + "source" : "/sources/module-internal-part-impl.cxx" + }, + "CMakeFiles/ninja-file-sets-private.dir/sources/module-part-impl.cxx" : { + "language" : "CXX", + "source" : "/sources/module-part-impl.cxx" + }, + "CMakeFiles/ninja-file-sets-private.dir/sources/module-use.cxx" : { + "language" : "CXX", + "source" : "/sources/module-use.cxx" + } + } } diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json index 171935f..9604ba2 100644 --- a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoFileSet-public.json @@ -42,5 +42,23 @@ "language": "CXX", "forward-modules-from-target-dirs": [], "linked-target-dirs": [], - "module-dir": "/CMakeFiles/ninja-file-sets-public.dir" + "module-dir": "/CMakeFiles/ninja-file-sets-public.dir", + "sources": { + "CMakeFiles/ninja-file-sets-public.dir/sources/module-impl.cxx" : { + "language" : "CXX", + "source" : "/sources/module-impl.cxx" + }, + "CMakeFiles/ninja-file-sets-public.dir/sources/module-internal-part-impl.cxx" : { + "language" : "CXX", + "source" : "/sources/module-internal-part-impl.cxx" + }, + "CMakeFiles/ninja-file-sets-public.dir/sources/module-part-impl.cxx" : { + "language" : "CXX", + "source" : "/sources/module-part-impl.cxx" + }, + "CMakeFiles/ninja-file-sets-public.dir/sources/module-use.cxx" : { + "language" : "CXX", + "source" : "/sources/module-use.cxx" + } + } } -- cgit v0.12 From bea4fb7cd6de1ae7c7ce399ee8b38cc435cf1395 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 24 Sep 2023 16:04:20 -0400 Subject: cmDyndepCollation: update template module database files if requested --- Source/cmBuildDatabase.cxx | 34 +++++++++++++++++++ Source/cmBuildDatabase.h | 8 +++++ Source/cmDyndepCollation.cxx | 77 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) diff --git a/Source/cmBuildDatabase.cxx b/Source/cmBuildDatabase.cxx index fafcee1..dc5f906 100644 --- a/Source/cmBuildDatabase.cxx +++ b/Source/cmBuildDatabase.cxx @@ -37,6 +37,40 @@ cmBuildDatabase::cmBuildDatabase() = default; cmBuildDatabase::cmBuildDatabase(cmBuildDatabase const&) = default; cmBuildDatabase::~cmBuildDatabase() = default; +cmBuildDatabase::LookupTable cmBuildDatabase::GenerateLookupTable() +{ + LookupTable lut; + + for (auto& Set_ : this->Sets) { + for (auto& TranslationUnit_ : Set_.TranslationUnits) { + // This table is from source path to TU instance. This is fine because a + // single target (where this is used) cannot contain the same source file + // multiple times. + lut[TranslationUnit_.Source] = &TranslationUnit_; + } + } + + return lut; +} + +bool cmBuildDatabase::HasPlaceholderNames() const +{ + for (auto const& Set_ : this->Sets) { + for (auto const& TranslationUnit_ : Set_.TranslationUnits) { + for (auto const& provide : TranslationUnit_.Provides) { + if (provide.first == PlaceholderName) { + return true; + } + if (provide.second == PlaceholderName) { + return true; + } + } + } + } + + return false; +} + void cmBuildDatabase::Write(std::string const& path) const { Json::Value mcdb = Json::objectValue; diff --git a/Source/cmBuildDatabase.h b/Source/cmBuildDatabase.h index 8ed35ec..a2733cb 100644 --- a/Source/cmBuildDatabase.h +++ b/Source/cmBuildDatabase.h @@ -41,6 +41,14 @@ public: cmBuildDatabase(cmBuildDatabase const&); ~cmBuildDatabase(); + using LookupTable = std::map; + // Generate a lookup table for the database. + // + // Only use when loading a single target's database in order to populate it. + LookupTable GenerateLookupTable(); + + bool HasPlaceholderNames() const; + void Write(std::string const& path) const; static std::unique_ptr Load(std::string const& path); diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx index cbb0e34..545782f 100644 --- a/Source/cmDyndepCollation.cxx +++ b/Source/cmDyndepCollation.cxx @@ -16,6 +16,7 @@ #include +#include "cmBuildDatabase.h" #include "cmExportBuildFileGenerator.h" #include "cmExportSet.h" #include "cmFileSet.h" @@ -344,6 +345,12 @@ struct CxxModuleFileSet cm::optional Destination; }; +struct CxxModuleDatabaseInfo +{ + std::string TemplatePath; + std::string Output; +}; + struct CxxModuleBmiInstall { std::string Component; @@ -370,6 +377,7 @@ struct cmCxxModuleExportInfo { std::map ObjectToSource; std::map ObjectToFileSet; + cm::optional DatabaseInfo; cm::optional BmiInstallation; std::vector Exports; std::string Config; @@ -494,6 +502,21 @@ bool cmDyndepCollation::WriteDyndepMetadata( exports.emplace_back(std::move(properties), &exp); } + std::unique_ptr module_database; + cmBuildDatabase::LookupTable build_database_lookup; + if (export_info.DatabaseInfo) { + module_database = + cmBuildDatabase::Load(export_info.DatabaseInfo->TemplatePath); + if (module_database) { + build_database_lookup = module_database->GenerateLookupTable(); + } else { + cmSystemTools::Error( + cmStrCat("Failed to read the template build database ", + export_info.DatabaseInfo->TemplatePath)); + result = false; + } + } + std::unique_ptr bmi_install_script; if (export_info.BmiInstallation) { bmi_install_script = cm::make_unique( @@ -523,6 +546,25 @@ bool cmDyndepCollation::WriteDyndepMetadata( #ifdef _WIN32 cmSystemTools::ConvertToUnixSlashes(output_path); #endif + + auto source_info_itr = export_info.ObjectToSource.find(output_path); + + // Update the module compilation database `requires` field if needed. + if (source_info_itr != export_info.ObjectToSource.end()) { + auto const& sourcePath = source_info_itr->second.SourcePath; + auto bdb_entry = build_database_lookup.find(sourcePath); + if (bdb_entry != build_database_lookup.end()) { + bdb_entry->second->Requires.clear(); + for (auto const& req : object.Requires) { + bdb_entry->second->Requires.push_back(req.LogicalName); + } + } else if (export_info.DatabaseInfo) { + cmSystemTools::Error( + cmStrCat("Failed to find module database entry for ", sourcePath)); + result = false; + } + } + // Find the fileset for this object. auto fileset_info_itr = export_info.ObjectToFileSet.find(output_path); bool const has_provides = !object.Provides.empty(); @@ -547,6 +589,31 @@ bool cmDyndepCollation::WriteDyndepMetadata( auto const& file_set = fileset_info_itr->second; + // Update the module compilation database `provides` field if needed. + { + auto bdb_entry = build_database_lookup.find(file_set.SourcePath); + if (bdb_entry != build_database_lookup.end()) { + // Clear the provides mapping; we will re-initialize it here. + if (!object.Provides.empty()) { + bdb_entry->second->Provides.clear(); + } + for (auto const& prov : object.Provides) { + auto bmiName = cb.ModuleFile(prov.LogicalName); + if (bmiName) { + bdb_entry->second->Provides[prov.LogicalName] = *bmiName; + } else { + cmSystemTools::Error( + cmStrCat("Failed to find BMI location for ", prov.LogicalName)); + result = false; + } + } + } else if (export_info.DatabaseInfo) { + cmSystemTools::Error(cmStrCat( + "Failed to find module database entry for ", file_set.SourcePath)); + result = false; + } + } + // Verify the fileset type for the object. if (file_set.Type == "CXX_MODULES"_s) { if (!has_provides) { @@ -708,6 +775,16 @@ bool cmDyndepCollation::WriteDyndepMetadata( } } + if (module_database) { + if (module_database->HasPlaceholderNames()) { + cmSystemTools::Error( + "Module compilation database still contains placeholders"); + result = false; + } else { + module_database->Write(export_info.DatabaseInfo->Output); + } + } + return result; } -- cgit v0.12 From dcf9a66ffe0b7f871b65df8477707facb55a6366 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 24 Sep 2023 18:57:53 -0400 Subject: cxxmodules: plumb control data for exporting build databases This includes the target property, its initializing variable, its initializing environment variable, and updating related docs to mention the new bits. --- Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst | 11 ++++ Help/guide/user-interaction/index.rst | 2 + Help/manual/cmake-env-variables.7.rst | 1 + Help/manual/cmake-properties.7.rst | 1 + Help/manual/cmake-variables.7.rst | 1 + Help/prop_tgt/EXPORT_BUILD_DATABASE.rst | 9 +++ Help/release/dev/module-cdb.rst | 8 +++ Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst | 80 +++++++++++++++++++++++ Modules/CMakeGenericSystem.cmake | 7 ++ Source/cmTarget.cxx | 5 ++ Tests/RunCMake/property_init/CompileSources.cmake | 1 + 11 files changed, 126 insertions(+) create mode 100644 Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst create mode 100644 Help/prop_tgt/EXPORT_BUILD_DATABASE.rst create mode 100644 Help/release/dev/module-cdb.rst create mode 100644 Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst diff --git a/Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst b/Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst new file mode 100644 index 0000000..ff0fec4 --- /dev/null +++ b/Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst @@ -0,0 +1,11 @@ +CMAKE_EXPORT_BUILD_DATABASE +--------------------------- + +.. versionadded:: 3.31 + +.. include:: ENV_VAR.txt + +The default value for :variable:`CMAKE_EXPORT_BUILD_DATABASE` when there is no +explicit configuration given on the first run while creating a new build tree. +On later runs in an existing build tree the value persists in the cache as +:variable:`CMAKE_EXPORT_BUILD_DATABASE`. diff --git a/Help/guide/user-interaction/index.rst b/Help/guide/user-interaction/index.rst index 3355992..0c3ef6a 100644 --- a/Help/guide/user-interaction/index.rst +++ b/Help/guide/user-interaction/index.rst @@ -300,6 +300,8 @@ the table below: commands used without a type :variable:`CMAKE_EXPORT_COMPILE_COMMANDS` Generate a ``compile_commands.json`` file for use with clang-based tools + :variable:`CMAKE_EXPORT_BUILD_DATABASE` Generate a ``build_database.json`` + file for use with clang-based tools ========================================== ============================================================ Other project-specific variables may be available diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst index b2ceeae..fd5935c 100644 --- a/Help/manual/cmake-env-variables.7.rst +++ b/Help/manual/cmake-env-variables.7.rst @@ -47,6 +47,7 @@ Environment Variables that Control the Build /envvar/CMAKE_CONFIG_TYPE /envvar/CMAKE_CONFIGURATION_TYPES /envvar/CMAKE_CROSSCOMPILING_EMULATOR + /envvar/CMAKE_EXPORT_BUILD_DATABASE /envvar/CMAKE_EXPORT_COMPILE_COMMANDS /envvar/CMAKE_GENERATOR /envvar/CMAKE_GENERATOR_INSTANCE diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index a195787..9ad856d 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -217,6 +217,7 @@ Properties on Targets /prop_tgt/EXCLUDE_FROM_ALL /prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD /prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG + /prop_tgt/EXPORT_BUILD_DATABASE /prop_tgt/EXPORT_COMPILE_COMMANDS /prop_tgt/EXPORT_FIND_PACKAGE_NAME /prop_tgt/EXPORT_NAME diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 1d6331e..3598ece 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -195,6 +195,7 @@ Variables that Change Behavior /variable/CMAKE_ERROR_DEPRECATED /variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION /variable/CMAKE_EXECUTE_PROCESS_COMMAND_ECHO + /variable/CMAKE_EXPORT_BUILD_DATABASE /variable/CMAKE_EXPORT_COMPILE_COMMANDS /variable/CMAKE_EXPORT_PACKAGE_REGISTRY /variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY diff --git a/Help/prop_tgt/EXPORT_BUILD_DATABASE.rst b/Help/prop_tgt/EXPORT_BUILD_DATABASE.rst new file mode 100644 index 0000000..6b2ad1b --- /dev/null +++ b/Help/prop_tgt/EXPORT_BUILD_DATABASE.rst @@ -0,0 +1,9 @@ +EXPORT_BUILD_DATABASE +--------------------- + +.. versionadded:: 3.31 + +Enable/Disable output of a build database for a target. + +This property is initialized by the value of the variable +:variable:`CMAKE_EXPORT_BUILD_DATABASE` if it is set when a target is created. diff --git a/Help/release/dev/module-cdb.rst b/Help/release/dev/module-cdb.rst new file mode 100644 index 0000000..6c28c79 --- /dev/null +++ b/Help/release/dev/module-cdb.rst @@ -0,0 +1,8 @@ +module-cdb +========== + +* Targets with C++ modules may now export their module compile commands using + the :prop_tgt:`EXPORT_BUILD_DATABASE` target property. This is initialized + with the :variable:`CMAKE_EXPORT_BUILD_DATABASE` variable which is itself + initialized using the :envvar:`CMAKE_EXPORT_BUILD_DATABASE` environment + variable. Only supported with the :ref:`Ninja Generators`. diff --git a/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst b/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst new file mode 100644 index 0000000..6b606a0 --- /dev/null +++ b/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst @@ -0,0 +1,80 @@ +CMAKE_EXPORT_BUILD_DATABASE +--------------------------- + +.. versionadded:: 3.31 + +Enable/Disable output of module compile commands during the build. + +If enabled, generates a ``build_database.json`` file containing the +information necessary to compile a target's C++ module sources with any +tooling. The format of the JSON file looks like: + +.. code-block:: javascript + + { + "version": 1, + "revision": 0, + "sets": [ + { + "family-name" : "export_build_database", + "name" : "export_build_database@Debug", + "translation-units" : [ + { + "arguments": [ + "/path/to/compiler", + "...", + ], + "baseline-arguments" : + [ + "...", + ], + "local-arguments" : + [ + "...", + ], + "object": "CMakeFiles/target.dir/source.cxx.o", + "private": true, + "provides": { + "importable": "path/to/bmi" + }, + "requires" : [], + "source": "path/to/source.cxx", + "work-directory": "/path/to/working/directory" + } + ], + "visible-sets" : [] + } + ] + } + +This is initialized by the :envvar:`CMAKE_EXPORT_BUILD_DATABASE` environment +variable, and initializes the :prop_tgt:`EXPORT_BUILD_DATABASE` target +property for all targets. + +.. note:: + This option is implemented only by the :ref:`Ninja Generators`. It is + ignored on other generators. + +When supported and enabled, numerous targets are created in order to make it +possible to build a file containing just the commands that are needed for the +tool in question. + +``cmake_build_database-`` + Writes ``build_database_.json``. Writes a build database for the + entire build for the given configuration and all languages. Not available if + the configuration name is the empty string. + +``cmake_build_database--`` + Writes ``build_database__.json``. Writes build database for + the entire build for the given configuration and language. Not available if + the configuration name is the empty string. + +``cmake_build_database-`` + Writes ``build_database_.json``. Writes build database for the entire + build for the given language and all configurations. In a multi-config + generator, other build configuration database may be assumed to exist. + +``cmake_build_database`` + Writes to ``build_database.json``. Writes build database for all languages + and configurations. In a multi-config generator, other build configuration + database may be assumed to exist. diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index ccfde60..88e3bfa 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -78,6 +78,13 @@ if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS AND CMAKE_GENERATOR MATCHES "Ninja| mark_as_advanced(CMAKE_EXPORT_COMPILE_COMMANDS) endif() +if(NOT DEFINED CMAKE_EXPORT_BUILD_DATABASE AND CMAKE_GENERATOR MATCHES "Ninja") + set(CMAKE_EXPORT_BUILD_DATABASE "$ENV{CMAKE_EXPORT_BUILD_DATABASE}" + CACHE BOOL "Enable/Disable output of build database during the build." + ) + mark_as_advanced(CMAKE_EXPORT_BUILD_DATABASE) +endif() + # GetDefaultWindowsPrefixBase # # Compute the base directory for CMAKE_INSTALL_PREFIX based on: diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 32fd16f..da0091b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -598,6 +598,7 @@ TargetProperty const StaticTargetProperties[] = { // Metadata { "CROSSCOMPILING_EMULATOR"_s, IC::ExecutableTarget }, + { "EXPORT_BUILD_DATABASE"_s, IC::CanCompileSources }, { "EXPORT_COMPILE_COMMANDS"_s, IC::CanCompileSources }, { "FOLDER"_s }, { "TEST_LAUNCHER"_s, IC::ExecutableTarget }, @@ -1895,6 +1896,10 @@ void cmTarget::CopyImportedCxxModulesProperties(cmTarget const* tgt) // Metadata "EchoString", "EXPORT_COMPILE_COMMANDS", + // Do *not* copy this property; it should be re-initialized at synthesis + // time from the `CMAKE_EXPORT_BUILD_DATABASE` variable as `IMPORTED` + // targets ignore the property initialization. + // "EXPORT_BUILD_DATABASE", "FOLDER", "LABELS", "PROJECT_LABEL", diff --git a/Tests/RunCMake/property_init/CompileSources.cmake b/Tests/RunCMake/property_init/CompileSources.cmake index 22b8f3f..eb0a77f 100644 --- a/Tests/RunCMake/property_init/CompileSources.cmake +++ b/Tests/RunCMake/property_init/CompileSources.cmake @@ -177,6 +177,7 @@ set(properties # Metadata "EXPORT_COMPILE_COMMANDS" "OFF" "" + "EXPORT_BUILD_DATABASE" "OFF" "" ) if (CMAKE_HOST_APPLE) # compile-guarded in CMake -- cgit v0.12 From 670f753f24fccaffee15c078e319ef2d85116ee3 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 24 Sep 2023 18:53:19 -0400 Subject: cmDyndepCollation: write build database metadata Generators will hook this up into the build graph as needed. --- Source/cmDyndepCollation.cxx | 24 ++++++++++++++++++++++ Source/cmGeneratorTarget.cxx | 21 +++++++++++++++++++ Source/cmGeneratorTarget.h | 3 +++ Source/cmGlobalGenerator.h | 2 ++ .../expect/NinjaDependInfoBMIInstall-private.json | 1 + .../expect/NinjaDependInfoBMIInstall-public.json | 1 + .../expect/NinjaDependInfoExport-private.json | 1 + .../expect/NinjaDependInfoExport-public.json | 1 + ...injaDependInfoExportFilesystemSafe-private.json | 1 + ...NinjaDependInfoExportFilesystemSafe-public.json | 1 + .../expect/NinjaDependInfoFileSet-private.json | 1 + .../expect/NinjaDependInfoFileSet-public.json | 1 + 12 files changed, 58 insertions(+) diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx index 545782f..1c05f25 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 293a4b7..ced18fd 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 210f0ab..b056733 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 85dec72..355cb80 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 4bb2455..dfca73e 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 364bce2..20f164a 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 45cd8ab..235e17d 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 43a4e4f..ed19dd8 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 03e2018..22005a2 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 4128252..e9d4852 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 f4e19f4..571998f 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 9604ba2..781b988 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": "", -- cgit v0.12 From 84bc710d84c912a8d5dc1a972ed9c021adda4c55 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 28 Sep 2023 13:30:43 -0400 Subject: cmGlobalGenerator: generate build database files for targets --- Source/cmGeneratorTarget.cxx | 14 +++ Source/cmGlobalGenerator.cxx | 216 ++++++++++++++++++++++++++++++++++++++ Source/cmGlobalGenerator.h | 12 +++ Source/cmGlobalNinjaGenerator.h | 1 + Source/cmNinjaTargetGenerator.cxx | 16 +++ 5 files changed, 259 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index ced18fd..fcf790f 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -139,6 +139,20 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) } else { this->LinkerLanguage = this->Target->GetSafeProperty("LINKER_LANGUAGE"); } + + auto configs = + this->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); + std::string build_db_languages[] = { "CXX" }; + for (auto const& language : build_db_languages) { + for (auto const& config : configs) { + auto bdb_path = this->BuildDatabasePath(language, config); + if (!bdb_path.empty()) { + this->Makefile->GetOrCreateGeneratedSource(bdb_path); + this->GetGlobalGenerator()->AddBuildDatabaseFile(language, config, + bdb_path); + } + } + } } cmGeneratorTarget::~cmGeneratorTarget() = default; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index aeebc6f..a38208c 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -32,6 +32,7 @@ #include "cmCryptoHash.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" +#include "cmCustomCommandTypes.h" #include "cmDuration.h" #include "cmExportBuildFileGenerator.h" #include "cmExternalMakefileProjectGenerator.h" @@ -68,6 +69,8 @@ # include "cmQtAutoGenGlobalInitializer.h" #endif +class cmListFileBacktrace; + const std::string kCMAKE_PLATFORM_INFO_INITIALIZED = "CMAKE_PLATFORM_INFO_INITIALIZED"; @@ -1569,6 +1572,10 @@ bool cmGlobalGenerator::Compute() } this->FinalizeTargetConfiguration(); + if (!this->AddBuildDatabaseTargets()) { + return false; + } + this->CreateGenerationObjects(); // at this point this->LocalGenerators has been filled, @@ -2834,6 +2841,20 @@ bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName, reason); } +bool cmGlobalGenerator::CheckCMP0037Prefix(std::string const& targetPrefix, + std::string const& reason) const +{ + bool ret = true; + for (auto const& tgtPair : this->TargetSearchIndex) { + if (cmHasPrefix(tgtPair.first, targetPrefix) && + !RaiseCMP0037Message(this->GetCMakeInstance(), tgtPair.second, + tgtPair.first, reason)) { + ret = false; + } + } + return ret; +} + void cmGlobalGenerator::CreateDefaultGlobalTargets( std::vector& targets) { @@ -3186,6 +3207,201 @@ void cmGlobalGenerator::AddGlobalTarget_Install( } } +class ModuleCompilationDatabaseCommandAction +{ +public: + ModuleCompilationDatabaseCommandAction( + std::string output, std::function()> inputs) + : Output(std::move(output)) + , Inputs(std::move(inputs)) + { + } + void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr cc); + +private: + std::string const Output; + std::function()> const Inputs; +}; + +void ModuleCompilationDatabaseCommandAction::operator()( + cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr cc) +{ + auto inputs = this->Inputs(); + + cmCustomCommandLines command_lines; + cmCustomCommandLine command_line; + { + command_line.emplace_back(cmSystemTools::GetCMakeCommand()); + command_line.emplace_back("-E"); + command_line.emplace_back("cmake_module_compile_db"); + command_line.emplace_back("merge"); + command_line.emplace_back("-o"); + command_line.emplace_back(this->Output); + for (auto const& input : inputs) { + command_line.emplace_back(input); + } + } + command_lines.emplace_back(std::move(command_line)); + + cc->SetBacktrace(lfbt); + cc->SetCommandLines(command_lines); + cc->SetWorkingDirectory(lg.GetBinaryDirectory().c_str()); + cc->SetDependsExplicitOnly(true); + cc->SetOutputs(this->Output); + if (!inputs.empty()) { + cc->SetMainDependency(inputs[0]); + } + cc->SetDepends(inputs); + detail::AddCustomCommandToOutput(lg, cmCommandOrigin::Generator, + std::move(cc), false); +} + +class ModuleCompilationDatabaseTargetAction +{ +public: + ModuleCompilationDatabaseTargetAction(std::string output, cmTarget* target) + : Output(std::move(output)) + , Target(target) + { + } + void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr cc); + +private: + std::string const Output; + cmTarget* const Target; +}; + +void ModuleCompilationDatabaseTargetAction::operator()( + cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr cc) +{ + cc->SetBacktrace(lfbt); + cc->SetWorkingDirectory(lg.GetBinaryDirectory().c_str()); + std::vector target_inputs; + target_inputs.emplace_back(this->Output); + cc->SetDepends(target_inputs); + detail::AddUtilityCommand(lg, cmCommandOrigin::Generator, this->Target, + std::move(cc)); +} + +void cmGlobalGenerator::AddBuildDatabaseFile(std::string const& lang, + std::string const& config, + std::string const& path) +{ + if (!config.empty()) { + this->PerConfigModuleDbs[config][lang].push_back(path); + } + this->PerLanguageModuleDbs[lang].push_back(path); +} + +bool cmGlobalGenerator::AddBuildDatabaseTargets() +{ + auto& mf = this->Makefiles[0]; + if (!mf->IsOn("CMAKE_EXPORT_BUILD_DATABASE")) { + return true; + } + + static const auto reservedTargets = { "cmake_build_database" }; + for (auto const& target : reservedTargets) { + if (!this->CheckCMP0037(target, + "when exporting build databases are enabled")) { + return false; + } + } + static const auto reservedPrefixes = { "cmake_build_database-" }; + for (auto const& prefix : reservedPrefixes) { + if (!this->CheckCMP0037Prefix( + prefix, "when exporting build databases are enabled")) { + return false; + } + } + + if (!this->SupportsBuildDatabase()) { + return true; + } + + auto configs = mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); + + static cm::static_string_view TargetPrefix = "cmake_build_database"_s; + auto AddMergeTarget = + [&mf](std::string const& name, const char* comment, + std::string const& output, + std::function()> inputs) { + // Add the custom command. + { + ModuleCompilationDatabaseCommandAction action{ output, + std::move(inputs) }; + auto cc = cm::make_unique(); + cc->SetComment(comment); + mf->AddGeneratorAction( + std::move(cc), action, + cmMakefile::GeneratorActionWhen::AfterGeneratorTargets); + } + + // Add a custom target with the given name. + { + cmTarget* target = mf->AddNewUtilityTarget(name, true); + ModuleCompilationDatabaseTargetAction action{ output, target }; + auto cc = cm::make_unique(); + mf->AddGeneratorAction(std::move(cc), action); + } + }; + + std::string module_languages[] = { "CXX" }; + + // Add per-configuration targets. + for (auto const& config : configs) { + // Add per-language targets. + std::vector all_config_paths; + for (auto const& lang : module_languages) { + auto comment = cmStrCat("Combining module command databases for ", lang, + " and ", config); + auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database_", + lang, '_', config, ".json"); + mf->GetOrCreateGeneratedSource(output); + AddMergeTarget(cmStrCat(TargetPrefix, '-', lang, '-', config), + comment.c_str(), output, [this, config, lang]() { + return this->PerConfigModuleDbs[config][lang]; + }); + all_config_paths.emplace_back(std::move(output)); + } + + // Add the overall target. + auto comment = cmStrCat("Combining module command databases for ", config); + auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database_", + config, ".json"); + mf->GetOrCreateGeneratedSource(output); + AddMergeTarget(cmStrCat(TargetPrefix, '-', config), comment.c_str(), + output, [all_config_paths]() { return all_config_paths; }); + } + + // NMC considerations + // Add per-language targets. + std::vector all_config_paths; + for (auto const& lang : module_languages) { + auto comment = cmStrCat("Combining module command databases for ", lang); + auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database_", + lang, ".json"); + mf->GetOrCreateGeneratedSource(output); + AddMergeTarget( + cmStrCat(TargetPrefix, '-', lang), comment.c_str(), output, + [this, lang]() { return this->PerLanguageModuleDbs[lang]; }); + all_config_paths.emplace_back(std::move(output)); + } + + // Add the overall target. + auto const* comment = "Combining all module command databases"; + auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database.json"); + mf->GetOrCreateGeneratedSource(output); + AddMergeTarget(std::string(TargetPrefix), comment, output, + [all_config_paths]() { return all_config_paths; }); + + return true; +} + std::string cmGlobalGenerator::GetPredefinedTargetsFolder() const { cmValue prop = this->GetCMakeInstance()->GetState()->GetGlobalProperty( diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 355cb80..a865adb 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -172,6 +172,9 @@ public: } virtual bool SupportsBuildDatabase() const { return false; } + bool AddBuildDatabaseTargets(); + void AddBuildDatabaseFile(std::string const& lang, std::string const& config, + std::string const& path); virtual bool IsGNUMakeJobServerAware() const { return false; } @@ -873,6 +876,8 @@ private: bool CheckCMP0037(std::string const& targetName, std::string const& reason) const; + bool CheckCMP0037Prefix(std::string const& targetPrefix, + std::string const& reason) const; void IndexMakefile(cmMakefile* mf); void IndexLocalGenerator(cmLocalGenerator* lg); @@ -918,6 +923,13 @@ private: cmFileLockPool FileLockPool; #endif + using PerLanguageModuleDatabases = + std::map>; + using PerConfigModuleDatabases = + std::map; + PerConfigModuleDatabases PerConfigModuleDbs; + PerLanguageModuleDatabases PerLanguageModuleDbs; + protected: float FirstTimeProgress; bool NeedSymbolicMark; diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 1cdcfb7..69b2361 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -483,6 +483,7 @@ public: bool IsSingleConfigUtility(cmGeneratorTarget const* target) const; bool CheckCxxModuleSupport(CxxModuleSupportQuery query) override; + bool SupportsBuildDatabase() const override { return true; } std::string ConvertToOutputPath(std::string path) const override; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index a10635a..90c395b 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -22,6 +22,7 @@ #include #include +#include "cmBuildDatabase.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommandGenerator.h" #include "cmDyndepCollation.h" @@ -1232,6 +1233,21 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( language, "Modules.json")); build.ImplicitDeps.emplace_back( this->GetTargetDependInfoPath(language, config)); + { + auto bdb_path = + this->GeneratorTarget->BuildDatabasePath(language, config); + if (!bdb_path.empty()) { + build.ImplicitOuts.emplace_back(this->ConvertToNinjaPath(bdb_path)); + } + } + auto bdb_path = this->GeneratorTarget->BuildDatabasePath(language, config); + if (!bdb_path.empty()) { + auto db = cmBuildDatabase::ForTarget(this->GeneratorTarget, config); + auto mcdb_template_path = cmStrCat(bdb_path, ".in"); + db.Write(mcdb_template_path); + build.ImplicitDeps.emplace_back(std::move(mcdb_template_path)); + build.ImplicitOuts.emplace_back(std::move(bdb_path)); + } for (auto const& scanFiles : scanningFiles) { if (!scanFiles.ScanningOutput.empty()) { build.ExplicitDeps.push_back(scanFiles.ScanningOutput); -- cgit v0.12 From 438038b5e1fb00669c54425853acdbe0e9e0d795 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 28 Sep 2023 11:52:15 -0400 Subject: Tests/CXXModules: support building specific targets of example trees This will be used to ensure that module command targets work as intended. --- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 5048d3e..1d9e508 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -162,6 +162,9 @@ function (run_cxx_module_test directory) run_cmake_command("examples/${test_name}-build" "${CMAKE_COMMAND}" --build . --config Debug --target "${RunCMake_CXXModules_TARGET}") else () run_cmake_command("examples/${test_name}-build" "${CMAKE_COMMAND}" --build . --config Debug) + foreach (RunCMake_CXXModules_TARGET IN LISTS RunCMake_CXXModules_TARGETS) + run_cmake_command("examples/${test_name}-target-${RunCMake_CXXModules_TARGET}" "${CMAKE_COMMAND}" --build . --target "${RunCMake_CXXModules_TARGET}" --config Debug) + endforeach () endif () if (RunCMake_CXXModules_INSTALL) run_cmake_command("examples/${test_name}-install" "${CMAKE_COMMAND}" --build . --target install --config Debug) -- cgit v0.12 From 123107c1a48c4e5e61ddb3718b5b429d9b909dca Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 19 Jul 2024 14:21:44 -0400 Subject: Tests/CXXModules: add support for running targets under a given config --- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 1d9e508..b7087de 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -163,7 +163,14 @@ function (run_cxx_module_test directory) else () run_cmake_command("examples/${test_name}-build" "${CMAKE_COMMAND}" --build . --config Debug) foreach (RunCMake_CXXModules_TARGET IN LISTS RunCMake_CXXModules_TARGETS) - run_cmake_command("examples/${test_name}-target-${RunCMake_CXXModules_TARGET}" "${CMAKE_COMMAND}" --build . --target "${RunCMake_CXXModules_TARGET}" --config Debug) + set(RunCMake_CXXModules_CONFIG "Debug") + set(RunCMake_CXXModules_NAME_SUFFIX "") + if (RunCMake_CXXModules_TARGET MATCHES "(.*)@(.*)") + set(RunCMake_CXXModules_TARGET "${CMAKE_MATCH_1}") + set(RunCMake_CXXModules_CONFIG "${CMAKE_MATCH_2}") + set(RunCMake_CXXModules_NAME_SUFFIX "-${RunCMake_CXXModules_CONFIG}") + endif () + run_cmake_command("examples/${test_name}-target-${RunCMake_CXXModules_TARGET}${RunCMake_CXXModules_NAME_SUFFIX}" "${CMAKE_COMMAND}" --build . --target "${RunCMake_CXXModules_TARGET}" --config "${RunCMake_CXXModules_CONFIG}") endforeach () endif () if (RunCMake_CXXModules_INSTALL) -- cgit v0.12 From 6863c1d823954bdc6f92352c209bb07a34c3a8c8 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 28 Sep 2023 11:53:35 -0400 Subject: Tests/CXXModules: add tests for module commands --- Tests/RunCMake/CXXModules/Inspect.cmake | 2 + .../NinjaDependInfoCompileDatabase-check.cmake | 39 +++ .../NinjaDependInfoCompileDatabase.cmake | 52 ++++ Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 41 +++ Tests/RunCMake/CXXModules/check-json.cmake | 66 ++++- .../CXXModules/examples/build-database-check.cmake | 81 ++++++ .../expect/export-build-database-all-multi.json | 300 +++++++++++++++++++++ .../examples/expect/export-build-database-all.json | 153 +++++++++++ .../expect/export-build-database-config.json | 153 +++++++++++ .../expect/export-build-database-cxx-config.json | 153 +++++++++++ .../expect/export-build-database-cxx-multi.json | 300 +++++++++++++++++++++ .../examples/expect/export-build-database-cxx.json | 153 +++++++++++ .../export-build-database-imported-all-multi.json | 278 +++++++++++++++++++ .../expect/export-build-database-imported-all.json | 142 ++++++++++ .../export-build-database-imported-config.json | 142 ++++++++++ .../export-build-database-imported-cxx-config.json | 142 ++++++++++ .../export-build-database-imported-cxx-multi.json | 278 +++++++++++++++++++ .../expect/export-build-database-imported-cxx.json | 142 ++++++++++ .../export-build-database-imported-target.json | 59 ++++ .../expect/export-build-database-target.json | 153 +++++++++++ .../export-build-database-build-check.cmake | 19 ++ .../examples/export-build-database-check.cmake | 19 ++ .../examples/export-build-database-setup.cmake | 37 +++ ...atabase-target-cmake_build_database-check.cmake | 21 ++ .../CXX-check.cmake | 21 ++ .../CXX/Debug-check.cmake | 14 + .../CXX/Release-Release-check.cmake | 14 + .../Debug-check.cmake | 14 + .../Release-Release-check.cmake | 14 + .../examples/export-build-database/CMakeLists.txt | 85 ++++++ .../dep_interface_include/anchor | 0 .../examples/export-build-database/importable.cxx | 6 + .../examples/export-build-database/lib.cxx | 6 + .../target_interface_include/anchor | 0 .../target_public_include/anchor | 0 ...modules-export-build-database-build-check.cmake | 18 ++ ...mport-modules-export-build-database-check.cmake | 18 ++ ...atabase-target-cmake_build_database-check.cmake | 22 ++ .../CXX-check.cmake | 22 ++ .../CXX/Debug-check.cmake | 19 ++ .../CXX/Release-Release-check.cmake | 19 ++ .../Debug-check.cmake | 19 ++ .../Release-check.cmake | 19 ++ .../examples/import-modules/CMakeLists.txt | 22 ++ .../NinjaDependInfoCompileDatabase-private.json | 51 ++++ .../NinjaDependInfoCompileDatabase-public.json | 51 ++++ 46 files changed, 3378 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-check.cmake create mode 100644 Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/build-database-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-all-multi.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-all.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-config.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-config.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-multi.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all-multi.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-config.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-config.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-multi.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-target.json create mode 100644 Tests/RunCMake/CXXModules/examples/expect/export-build-database-target.json create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-build-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Debug-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Debug-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Release-Release-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database/dep_interface_include/anchor create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database/importable.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database/lib.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database/target_interface_include/anchor create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database/target_public_include/anchor create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-build-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Debug-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Debug-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Release-check.cmake create mode 100644 Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-private.json create mode 100644 Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-public.json diff --git a/Tests/RunCMake/CXXModules/Inspect.cmake b/Tests/RunCMake/CXXModules/Inspect.cmake index e648e8c..2913c87 100644 --- a/Tests/RunCMake/CXXModules/Inspect.cmake +++ b/Tests/RunCMake/CXXModules/Inspect.cmake @@ -42,6 +42,8 @@ set(CMAKE_CXX_OUTPUT_EXTENSION \"${CMAKE_CXX_OUTPUT_EXTENSION}\") set(CXXModules_default_build_type \"${CMAKE_BUILD_TYPE}\") set(CMAKE_CXX_STANDARD_DEFAULT \"${CMAKE_CXX_STANDARD_DEFAULT}\") set(CMAKE_CXX20_STANDARD_COMPILE_OPTION \"${CMAKE_CXX20_STANDARD_COMPILE_OPTION}\") +set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT \"${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}\") +set(CMAKE_CXX_MODULE_MAP_FORMAT \"${CMAKE_CXX_MODULE_MAP_FORMAT}\") ") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}") diff --git a/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-check.cmake b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-check.cmake new file mode 100644 index 0000000..2fd33c6 --- /dev/null +++ b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-check.cmake @@ -0,0 +1,39 @@ +include("${CMAKE_CURRENT_LIST_DIR}/check-json.cmake") + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(have_file 0) + foreach (CXXModules_config IN ITEMS Release Debug RelWithDebInfo MinSizeRel) + if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-compiledb-public.dir/${CXXModules_config}/CXXDependInfo.json") + continue () + endif () + set(have_file 1) + + set(CMAKE_BUILD_TYPE "${CXXModules_config}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-compiledb-public.dir/${CXXModules_config}/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoCompileDatabase-public.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-compiledb-private.dir/${CXXModules_config}/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoCompileDatabase-private.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") + endforeach () + + if (NOT have_file) + list(APPEND RunCMake_TEST_FAILED + "No recognized build configurations found.") + endif () +else () + set(CXXModules_config "${CXXModules_default_build_type}") + set(CMAKE_BUILD_TYPE "${CXXModules_default_build_type}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-compiledb-public.dir/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoCompileDatabase-public.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") + + file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/ninja-compiledb-private.dir/CXXDependInfo.json" actual_contents) + file(READ "${CMAKE_CURRENT_LIST_DIR}/expect/NinjaDependInfoCompileDatabase-private.json" expect_contents) + check_json("${actual_contents}" "${expect_contents}") +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake new file mode 100644 index 0000000..1208279 --- /dev/null +++ b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake @@ -0,0 +1,52 @@ +# Fake out that we have dyndep; we only need to generate, not actually build +# here. +set(CMAKE_CXX_SCANDEP_SOURCE "") + +enable_language(CXX) + +if (NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "This test requires a 'Ninja' generator to be used.") +endif () + +add_library(ninja-compiledb-public) +target_sources(ninja-compiledb-public + PRIVATE + sources/module-impl.cxx + sources/module-internal-part-impl.cxx + sources/module-part-impl.cxx + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}/sources" + FILES + sources/module.cxx + sources/module-part.cxx + FILE_SET internal_partitions TYPE CXX_MODULES FILES + sources/module-internal-part.cxx) +target_compile_features(ninja-compiledb-public + PRIVATE + cxx_std_20) +set_property(TARGET ninja-compiledb-public + PROPERTY EXPORT_BUILD_DATABASE 1) + +add_library(ninja-compiledb-private) +target_sources(ninja-compiledb-private + PRIVATE + sources/module-impl.cxx + sources/module-internal-part-impl.cxx + sources/module-part-impl.cxx + PRIVATE + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}/sources" + FILES + sources/module.cxx + sources/module-part.cxx + FILE_SET internal_partitions TYPE CXX_MODULES FILES + sources/module-internal-part.cxx) +target_compile_features(ninja-compiledb-private + PRIVATE + cxx_std_20) +set_property(TARGET ninja-compiledb-private + PROPERTY EXPORT_BUILD_DATABASE 1) diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index b7087de..4ed79ef 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -119,6 +119,7 @@ if (RunCMake_GENERATOR MATCHES "Ninja") run_cmake(NinjaDependInfoExportFilesystemSafe) run_cmake(NinjaDependInfoBMIInstall) run_cmake(NinjaForceResponseFile) # issue#25367 + run_cmake(NinjaDependInfoCompileDatabase) elseif (RunCMake_GENERATOR MATCHES "Visual Studio") run_cmake(VisualStudioNoSyntheticTargets) else () @@ -286,6 +287,32 @@ if ("compile_commands" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-compile-commands) endif () +macro (setup_export_build_database_targets) + set(RunCMake_CXXModules_TARGETS + cmake_build_database-CXX + cmake_build_database) + + if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + list(INSERT RunCMake_CXXModules_TARGETS 0 + cmake_build_database-CXX-Debug + cmake_build_database-Debug + # Other config targets. + cmake_build_database-CXX-Release@Release + cmake_build_database-Release@Release) + endif () +endmacro () + +# Tests which require build database support. +if ("build_database" IN_LIST CMake_TEST_MODULE_COMPILATION) + setup_export_build_database_targets() + set(RunCMake_CXXModules_NO_TEST 1) + + run_cxx_module_test(export-build-database) + + unset(RunCMake_CXXModules_NO_TEST) + unset(RunCMake_CXXModules_TARGETS) +endif () + # Tests which require collation work. if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(public-req-private) @@ -316,6 +343,12 @@ endif () function (run_cxx_module_import_test type name) set(RunCMake_CXXModules_INSTALL 0) + + if ("EXPORT_BUILD_DATABASE" IN_LIST ARGN) + list(REMOVE_ITEM ARGN EXPORT_BUILD_DATABASE) + list(APPEND ARGN -DCMAKE_EXPORT_BUILD_DATABASE=1) + endif () + run_cxx_module_test(import-modules "import-modules-${name}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${name}-${type}" ${ARGN}) endfunction () @@ -343,6 +376,14 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_import_test(build export-transitive-targets-build -DTRANSITIVE_TARGETS=1) run_cxx_module_import_test(build export-transitive-modules-build -DTRANSITIVE_MODULES=1) run_cxx_module_import_test(build export-with-headers-build -DWITH_HEADERS=1) + + if ("build_database" IN_LIST CMake_TEST_MODULE_COMPILATION) + setup_export_build_database_targets() + + run_cxx_module_import_test(build export-build-database -DBUILD_DATABASE=1 EXPORT_BUILD_DATABASE) + + unset(RunCMake_CXXModules_TARGETS) + endif () endif () endif () diff --git a/Tests/RunCMake/CXXModules/check-json.cmake b/Tests/RunCMake/CXXModules/check-json.cmake index bb04b36..8d95973 100644 --- a/Tests/RunCMake/CXXModules/check-json.cmake +++ b/Tests/RunCMake/CXXModules/check-json.cmake @@ -3,19 +3,48 @@ cmake_policy(SET CMP0057 NEW) function (json_placeholders in out) string(REPLACE "" "${CXXModules_config}" in "${in}") + string(TOLOWER "${CXXModules_config}" config_lower) + string(REPLACE "" "${config_lower}" in "${in}") + string(REPLACE "" "${CXXModules_config_other}" in "${in}") + string(TOLOWER "${CXXModules_config_other}" config_lower) + string(REPLACE "" "${config_lower}" in "${in}") if (RunCMake_GENERATOR_IS_MULTI_CONFIG) string(REPLACE "" "/${CXXModules_config}" in "${in}") + string(REPLACE "" "/${CXXModules_config_other}" in "${in}") else () string(REPLACE "" "" in "${in}") + string(REPLACE "" "" in "${in}") endif () if (CMAKE_BUILD_TYPE) string(REPLACE "" "${CXXModules_config}" in "${in}") + string(REPLACE "" "${CXXModules_config_other}" in "${in}") else () string(REPLACE "" "noconfig" in "${in}") endif () string(REPLACE "" "${RunCMake_SOURCE_DIR}" in "${in}") string(REPLACE "" "${RunCMake_TEST_BINARY_DIR}" in "${in}") string(REPLACE "" "${CMAKE_CXX_OUTPUT_EXTENSION}" in "${in}") + if (CMAKE_CXX_MODULE_MAP_FORMAT STREQUAL "gcc") + set(bmiflag "-fmodule-only") + set(bmiext "gcm") + elseif (CMAKE_CXX_MODULE_MAP_FORMAT STREQUAL "clang") + set(bmiflag "--precompile") + set(bmiext "pcm") + elseif (CMAKE_CXX_MODULE_MAP_FORMAT STREQUAL "msvc") + set(bmiflag "-ifcOutput.*") + set(bmiext "ifc") + endif () + string(REPLACE "" "${bmiflag}" in "${in}") + string(REPLACE "" ".${bmiext}" in "${in}") + set(output_flag "-o") + if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + set(output_flag "-Fo") + endif () + string(REPLACE "" "${output_flag}" in "${in}") + string(REPLACE "" "${CMAKE_CXX20_STANDARD_COMPILE_OPTION}" in "${in}") + string(REPLACE "" "[0-9a-f]+" in "${in}") + string(REPLACE "REGEX:" "" in "${in}") + string(REPLACE "PATH:" "" in "${in}") set("${out}" "${in}" PARENT_SCOPE) endfunction () @@ -46,7 +75,26 @@ function (check_json_value path actual_type expect_type actual_value expect_valu endif () json_placeholders("${expect_value}" expect_value_expanded) - if (NOT actual_value STREQUAL expect_value_expanded) + if (expect_value MATCHES "^REGEX:PATH:") + string(REPLACE "\\" "/" actual_value_check "${actual_value}") + string(REGEX REPLACE "^\"(.*)\"$" "\\1" actual_value_check "${actual_value_check}") + if (NOT actual_value_check MATCHES "^${expect_value_expanded}$") + list(APPEND RunCMake_TEST_FAILED + "String mismatch (path regex) at ${path}: ${actual_value} vs. ^${expect_value_expanded}$") + endif () + elseif (expect_value MATCHES "^REGEX:") + if (NOT actual_value MATCHES "^${expect_value_expanded}$") + list(APPEND RunCMake_TEST_FAILED + "String mismatch (regex) at ${path}: ${actual_value} vs. ^${expect_value_expanded}$") + endif () + elseif (expect_value MATCHES "^PATH:") + string(REPLACE "\\" "/" actual_value_check "${actual_value}") + string(REGEX REPLACE "^\"(.*)\"$" "\\1" actual_value_check "${actual_value_check}") + if (NOT actual_value_check STREQUAL "${expect_value_expanded}") + list(APPEND RunCMake_TEST_FAILED + "String mismatch (path) at ${path}: ${actual_value} vs. ^${expect_value_expanded}$") + endif () + elseif (NOT actual_value STREQUAL expect_value_expanded) list(APPEND RunCMake_TEST_FAILED "String mismatch at ${path}: ${actual_value} vs. ${expect_value_expanded}") endif () @@ -61,6 +109,22 @@ endfunction () # Check that two arrays are the same. function (check_json_array path actual expect) + if (item_filter) + string(JSON iter_len LENGTH "${actual}") + set(idx 0) + while (idx LESS iter_len) + string(JSON type TYPE "${actual}" "${idx}") + string(JSON item GET "${actual}" "${idx}") + if (type STREQUAL "STRING" AND + item MATCHES "${item_filter}") + string(JSON actual REMOVE "${actual}" "${idx}") + math(EXPR iter_len "${iter_len} - 1") + else () + math(EXPR idx "${idx} + 1") + endif () + endwhile () + endif () + string(JSON actual_len LENGTH "${actual}") string(JSON expect_len LENGTH "${expect}") diff --git a/Tests/RunCMake/CXXModules/examples/build-database-check.cmake b/Tests/RunCMake/CXXModules/examples/build-database-check.cmake new file mode 100644 index 0000000..734b580 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/build-database-check.cmake @@ -0,0 +1,81 @@ +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) + +include("${CMAKE_CURRENT_LIST_DIR}/../check-json.cmake") + +function (check_build_database expect_basename fname component) + if (component STREQUAL "NO_EXIST") + if (EXISTS "${RunCMake_TEST_BINARY_DIR}/${fname}") + list(APPEND RunCMake_TEST_FAILED + "Build database detected before it is expected (${fname}).") + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE) + endif () + return () + endif () + + if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/${fname}") + list(APPEND RunCMake_TEST_FAILED + "No build database detected (${fname}).") + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE) + return () + endif () + + if (component STREQUAL "ALL") + set(CXXModules_config "Debug") + set(suffix "all") + elseif (component STREQUAL "ALL_MULTI") + set(CXXModules_config "Debug") + set(CXXModules_config_other "Release") + set(suffix "all-multi") + elseif (component STREQUAL "JUST_CXX") + set(CXXModules_config "Debug") + set(suffix "cxx") + elseif (component STREQUAL "JUST_CXX_MULTI") + set(CXXModules_config "Debug") + set(CXXModules_config_other "Release") + set(suffix "cxx-multi") + elseif (component STREQUAL "CXX_AND_DEBUG") + set(CXXModules_config "Debug") + set(suffix "cxx-config") + elseif (component STREQUAL "CXX_AND_RELEASE") + set(CXXModules_config "Release") + set(suffix "cxx-config") + elseif (component STREQUAL "JUST_DEBUG") + set(CXXModules_config "Debug") + set(suffix "config") + elseif (component STREQUAL "JUST_RELEASE") + set(CXXModules_config "Release") + set(suffix "config") + elseif (component STREQUAL "JUST_TARGET_DEBUG") + set(CXXModules_config "Debug") + set(suffix "target") + elseif (component STREQUAL "JUST_TARGET_RELEASE") + set(CXXModules_config "Release") + set(suffix "target") + elseif (component STREQUAL "JUST_TARGET") + set(CXXModules_config "Debug") + set(suffix "target") + else () + list(APPEND RunCMake_TEST_FAILED + "Unrecognized test component for ${fname}: ${component}") + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE) + return () + endif () + + set(expected_file "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/expect/${expect_basename}-${suffix}.json") + if (NOT EXISTS "${expected_file}") + list(APPEND RunCMake_TEST_FAILED + "No expected output JSON file found: ${expected_file}") + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE) + return () + endif () + + file(READ "${RunCMake_TEST_BINARY_DIR}/${fname}" actual) + file(READ "${expected_file}" expect) + + check_json("${actual}" "${expect}") + + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE) +endfunction () + +cmake_policy(POP) diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-all-multi.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-all-multi.json new file mode 100644 index 0000000..e1603be --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-all-multi.json @@ -0,0 +1,300 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "PATH:/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + }, + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-all.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-all.json new file mode 100644 index 0000000..440bc4e --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-all.json @@ -0,0 +1,153 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-config.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-config.json new file mode 100644 index 0000000..8877165 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-config.json @@ -0,0 +1,153 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "PATH:/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-config.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-config.json new file mode 100644 index 0000000..8877165 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-config.json @@ -0,0 +1,153 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "PATH:/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-multi.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-multi.json new file mode 100644 index 0000000..0a27fec --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx-multi.json @@ -0,0 +1,300 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "PATH:/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + }, + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "PATH:/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx.json new file mode 100644 index 0000000..8877165 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-cxx.json @@ -0,0 +1,153 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "PATH:/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all-multi.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all-multi.json new file mode 100644 index 0000000..2fdaef5 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all-multi.json @@ -0,0 +1,278 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all.json new file mode 100644 index 0000000..cb3b3a2 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-all.json @@ -0,0 +1,142 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-config.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-config.json new file mode 100644 index 0000000..cb3b3a2 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-config.json @@ -0,0 +1,142 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-config.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-config.json new file mode 100644 index 0000000..cb3b3a2 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-config.json @@ -0,0 +1,142 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-multi.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-multi.json new file mode 100644 index 0000000..2fdaef5 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx-multi.json @@ -0,0 +1,278 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx.json new file mode 100644 index 0000000..cb3b3a2 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-cxx.json @@ -0,0 +1,142 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + }, + { + "family-name": "REGEX:CXXModules::export_build_database@", + "name": "REGEX:CXXModules__export_build_database@synth_@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option", + "REGEX:PATH:-Ddepflag=\"CMakeFiles/CXXModules__export_build_database@synth_.dir/.d\"", + "REGEX:", + "REGEX:PATH:CMakeFiles/CXXModules__export_build_database@synth_.dir/", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_interface_define", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "PATH:-I/examples/export-build-database/target_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dtarget_interface_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": { + "importable": "" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-target.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-target.json new file mode 100644 index 0000000..d2d9752 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-imported-target.json @@ -0,0 +1,59 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "use_import_interfaces", + "name": "use_import_interfaces@", + "translation-units": [ + { + "arguments": [ + "", + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option", + "PATH:-Ddepflag=\"CMakeFiles/use_import_interfaces.dir/use.cxx.d\"", + "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "-c", + "PATH:/examples/import-modules/use.cxx" + ], + "baseline-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "local-arguments": [ + "-Dtarget_interface_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/target_interface_include", + "PATH:-I/examples/export-build-database/target_public_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dtarget_interface_option", + "-Dtarget_public_option" + ], + "object": "PATH:CMakeFiles/use_import_interfaces.dir/use.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/import-modules/use.cxx", + "work-directory": "" + } + ], + "visible-sets": ["REGEX:CXXModules__export_build_database@synth_@"] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/expect/export-build-database-target.json b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-target.json new file mode 100644 index 0000000..440bc4e --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/expect/export-build-database-target.json @@ -0,0 +1,153 @@ +{ + "version": 1, + "revision": 0, + "sets": [ + { + "family-name": "export_build_database", + "name": "export_build_database@", + "translation-units": [ + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/lib.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "-c", + "PATH:/examples/export-build-database/lib.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/lib.cxx", + "private": true, + "provides": {}, + "requires": ["importable"], + "source": "PATH:/examples/export-build-database/lib.cxx", + "work-directory": "" + }, + { + "arguments": [ + "", + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option", + "PATH:-Ddepflag=\"CMakeFiles/export_build_database.dir/importable.cxx.d\"", + "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "-c", + "PATH:/examples/export-build-database/importable.cxx" + ], + "baseline-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option" + ], + "local-arguments": [ + "-Ddep_interface_define", + "-Dfrom_compile_definitions", + "-Dtarget_private_define", + "-Dtarget_public_define", + "PATH:-I/examples/export-build-database/from_include_directories", + "PATH:-I/examples/export-build-database/target_private_include", + "PATH:-I/examples/export-build-database/target_public_include", + "PATH:-I/examples/export-build-database/dep_interface_include", + "-Dfrom_cmake_cxx_flags", + "-Dfrom_cmake_cxx__flags", + "", + "-Dfrom_compile_flags", + "-Dfrom_compile_options", + "-Dtarget_private_option", + "-Dtarget_public_option", + "-Ddep_interface_option", + "-Dfrom_source_flag", + "-Dfrom_source_option" + ], + "object": "PATH:CMakeFiles/export_build_database.dir/importable.cxx", + "private": true, + "provides": { + "importable": "/CMakeFiles/export_build_database.dir/importable" + }, + "requires": [], + "source": "PATH:/examples/export-build-database/importable.cxx", + "work-directory": "" + } + ], + "visible-sets": [] + } + ] +} diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-build-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-build-check.cmake new file mode 100644 index 0000000..131926b --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-build-check.cmake @@ -0,0 +1,19 @@ +include("${CMAKE_CURRENT_LIST_DIR}/build-database-check.cmake") + +check_build_database("export-build-database" "build_database.json" NO_EXIST) +check_build_database("export-build-database" "build_database_CXX.json" NO_EXIST) + +check_build_database("export-build-database" "build_database_CXX_Debug.json" NO_EXIST) +check_build_database("export-build-database" "build_database_Debug.json" NO_EXIST) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + # check_build_database("export-build-database" "build_database_CXX_Release.json" NO_EXIST) + # check_build_database("export-build-database" "build_database_Release.json" NO_EXIST) + # check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" NO_EXIST) +else () + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-check.cmake new file mode 100644 index 0000000..efa43d2 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-check.cmake @@ -0,0 +1,19 @@ +include("${CMAKE_CURRENT_LIST_DIR}/build-database-check.cmake") + +check_build_database("export-build-database" "build_database.json" NO_EXIST) +check_build_database("export-build-database" "build_database_CXX.json" NO_EXIST) + +check_build_database("export-build-database" "build_database_CXX_Debug.json" NO_EXIST) +check_build_database("export-build-database" "build_database_Debug.json" NO_EXIST) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" NO_EXIST) + + check_build_database("export-build-database" "build_database_CXX_Release.json" NO_EXIST) + check_build_database("export-build-database" "build_database_Release.json" NO_EXIST) + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" NO_EXIST) +else () + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/CXX_build_database.json" NO_EXIST) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake new file mode 100644 index 0000000..6a699c1 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake @@ -0,0 +1,37 @@ +get_property(is_multiconfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if (is_multiconfig) + set(CMAKE_CONFIGURATION_TYPES "Debug" "Release") +endif () + +set(CMAKE_EXPORT_BUILD_DATABASE 1) + +# Mock up depfile flags to keep things consistent; we don't need accurate +# dependency tracking for this test case anyways. +set(CMAKE_CXX_DEPFILE_FORMAT gcc) +set(CMAKE_DEPFILE_FLAGS_CXX "-Ddepflag=\\\"\\\"") +unset(CMAKE_CXX_DEPFILE_EXTENSION_REPLACE) + +# Disable MSVC flag injection from CMake abstractions. +set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "") +set(CMAKE_MSVC_RUNTIME_LIBRARY "") + +if (CMAKE_CXX_MODULE_BMI_ONLY_FLAG MATCHES "ifcOutput") + # Make a single flag for BMI-only to make the JSON expectations simpler. + set(CMAKE_CXX_MODULE_BMI_ONLY_FLAG + "-ifcOnly;-ifcOutput") +endif () + +# Disable extensions to keep flag selection simpler. +set(CMAKE_CXX_EXTENSIONS 0) + +if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + set(output_flag "-Fo") +else () + set(output_flag "-o") +endif () +set(CMAKE_CXX_COMPILE_OBJECT + " ${output_flag} -c ") + +set(CMAKE_CXX_FLAGS "-Dfrom_cmake_cxx_flags") +set(CMAKE_CXX_FLAGS_DEBUG "-Dfrom_cmake_cxx_debug_flags") +set(CMAKE_CXX_FLAGS_RELEASE "-Dfrom_cmake_cxx_release_flags") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database-check.cmake new file mode 100644 index 0000000..79db482 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database-check.cmake @@ -0,0 +1,21 @@ +include("${CMAKE_CURRENT_LIST_DIR}/build-database-check.cmake") + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database" "build_database.json" ALL_MULTI) + check_build_database("export-build-database" "build_database_CXX.json" JUST_CXX_MULTI) + + check_build_database("export-build-database" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database" "build_database_Debug.json" JUST_DEBUG) + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database" "build_database_CXX_Release.json" CXX_AND_RELEASE) + check_build_database("export-build-database" "build_database_Release.json" JUST_RELEASE) + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) +else () + check_build_database("export-build-database" "build_database.json" ALL) + check_build_database("export-build-database" "build_database_CXX.json" JUST_CXX) + + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX-check.cmake new file mode 100644 index 0000000..cf712ba --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX-check.cmake @@ -0,0 +1,21 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../build-database-check.cmake") + +check_build_database("export-build-database" "build_database.json" NO_EXIST) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database" "build_database_CXX.json" JUST_CXX_MULTI) + + check_build_database("export-build-database" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database" "build_database_Debug.json" JUST_DEBUG) + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database" "build_database_CXX_Release.json" CXX_AND_RELEASE) + check_build_database("export-build-database" "build_database_Release.json" JUST_RELEASE) + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) +else () + check_build_database("export-build-database" "build_database_CXX.json" JUST_CXX) + + check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Debug-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Debug-check.cmake new file mode 100644 index 0000000..6f60675 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Debug-check.cmake @@ -0,0 +1,14 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../../build-database-check.cmake") + +check_build_database("export-build-database" "build_database.json" NO_EXIST) +check_build_database("export-build-database" "build_database_CXX.json" NO_EXIST) + +check_build_database("export-build-database" "build_database_CXX_Debug.json" CXX_AND_DEBUG) +check_build_database("export-build-database" "build_database_Debug.json" NO_EXIST) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + +check_build_database("export-build-database" "build_database_CXX_Release.json" NO_EXIST) +check_build_database("export-build-database" "build_database_Release.json" NO_EXIST) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" NO_EXIST) + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake new file mode 100644 index 0000000..dcb36c9 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake @@ -0,0 +1,14 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../../build-database-check.cmake") + +check_build_database("export-build-database" "build_database.json" NO_EXIST) +check_build_database("export-build-database" "build_database_CXX.json" NO_EXIST) + +check_build_database("export-build-database" "build_database_CXX_Debug.json" CXX_AND_DEBUG) +check_build_database("export-build-database" "build_database_Debug.json" JUST_DEBUG) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + +check_build_database("export-build-database" "build_database_CXX_Release.json" CXX_AND_RELEASE) +check_build_database("export-build-database" "build_database_Release.json" NO_EXIST) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Debug-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Debug-check.cmake new file mode 100644 index 0000000..6868302 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Debug-check.cmake @@ -0,0 +1,14 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../build-database-check.cmake") + +check_build_database("export-build-database" "build_database.json" NO_EXIST) +check_build_database("export-build-database" "build_database_CXX.json" NO_EXIST) + +check_build_database("export-build-database" "build_database_CXX_Debug.json" CXX_AND_DEBUG) +check_build_database("export-build-database" "build_database_Debug.json" JUST_DEBUG) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + +check_build_database("export-build-database" "build_database_CXX_Release.json" NO_EXIST) +check_build_database("export-build-database" "build_database_Release.json" NO_EXIST) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" NO_EXIST) + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Release-Release-check.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Release-Release-check.cmake new file mode 100644 index 0000000..31da4be --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-target-cmake_build_database/Release-Release-check.cmake @@ -0,0 +1,14 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../build-database-check.cmake") + +check_build_database("export-build-database" "build_database.json" NO_EXIST) +check_build_database("export-build-database" "build_database_CXX.json" NO_EXIST) + +check_build_database("export-build-database" "build_database_CXX_Debug.json" CXX_AND_DEBUG) +check_build_database("export-build-database" "build_database_Debug.json" JUST_DEBUG) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + +check_build_database("export-build-database" "build_database_CXX_Release.json" CXX_AND_RELEASE) +check_build_database("export-build-database" "build_database_Release.json" JUST_RELEASE) +check_build_database("export-build-database" "CMakeFiles/export_build_database.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-build-database/CMakeLists.txt new file mode 100644 index 0000000..318f91c --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database/CMakeLists.txt @@ -0,0 +1,85 @@ +cmake_minimum_required(VERSION 3.29) +project(cxx_modules_export_build_database CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +include("${CMAKE_SOURCE_DIR}/../export-build-database-setup.cmake") + +add_compile_options(-Dfrom_compile_options) +add_compile_definitions(-Dfrom_compile_definitions) +include_directories(from_include_directories) + +add_library(provide_flags INTERFACE) +target_compile_options(provide_flags + INTERFACE + -Ddep_interface_option) +target_compile_definitions(provide_flags + INTERFACE + dep_interface_define) +target_include_directories(provide_flags + INTERFACE + dep_interface_include) + +add_library(export_build_database) +target_sources(export_build_database + PRIVATE + lib.cxx + PUBLIC + FILE_SET modules + TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx) +target_compile_features(export_build_database PUBLIC cxx_std_20) +target_link_libraries(export_build_database + PRIVATE + provide_flags) + +set_property(SOURCE importable.cxx APPEND + PROPERTY COMPILE_FLAGS "-Dfrom_source_flag") +set_property(SOURCE importable.cxx APPEND + PROPERTY COMPILE_OPTIONS "-Dfrom_source_option") +set_property(SOURCE importable.cxx APPEND + PROPERTY COMPILE_DEFINITIONS "from_source_define") + +set_property(TARGET export_build_database APPEND + PROPERTY COMPILE_FLAGS "-Dfrom_compile_flags") +target_compile_options(export_build_database + PRIVATE + -Dtarget_private_option + INTERFACE + -Dtarget_interface_option + PUBLIC + -Dtarget_public_option) +target_compile_definitions(export_build_database + PRIVATE + target_private_define + INTERFACE + target_interface_define + PUBLIC + target_public_define) +target_include_directories(export_build_database + PRIVATE + target_private_include + INTERFACE + target_interface_include + PUBLIC + target_public_include) + +install(TARGETS export_build_database + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +export(EXPORT CXXModules + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_build_database-targets.cmake") +install(TARGETS provide_flags + EXPORT CXXModulesDeps) +export(EXPORT CXXModulesDeps + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_build_database-dep-targets.cmake") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_build_database-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_build_database-dep-targets.cmake\") +include(\"\${CMAKE_CURRENT_LIST_DIR}/export_build_database-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database/dep_interface_include/anchor b/Tests/RunCMake/CXXModules/examples/export-build-database/dep_interface_include/anchor new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-build-database/importable.cxx new file mode 100644 index 0000000..607680a --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database/importable.cxx @@ -0,0 +1,6 @@ +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database/lib.cxx b/Tests/RunCMake/CXXModules/examples/export-build-database/lib.cxx new file mode 100644 index 0000000..b144b27 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database/lib.cxx @@ -0,0 +1,6 @@ +import importable; + +int f() +{ + return from_import(); +} diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database/target_interface_include/anchor b/Tests/RunCMake/CXXModules/examples/export-build-database/target_interface_include/anchor new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database/target_public_include/anchor b/Tests/RunCMake/CXXModules/examples/export-build-database/target_public_include/anchor new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-build-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-build-check.cmake new file mode 100644 index 0000000..21a29b6 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-build-check.cmake @@ -0,0 +1,18 @@ +include("${CMAKE_CURRENT_LIST_DIR}/build-database-check.cmake") +set(item_filter "-ifcOnly") + +check_build_database("export-build-database-imported" "build_database.json" NO_EXIST) +check_build_database("export-build-database-imported" "build_database_CXX.json" NO_EXIST) +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" NO_EXIST) + check_build_database("export-build-database-imported" "build_database_Debug.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/export-module-commands.dir/Debug/CXX_build_database.json" NO_EXIST) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "build_database_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/export-module-commands.dir/Release/CXX_build_database.json" NO_EXIST) +else () + check_build_database("export-build-database-imported" "CMakeFiles/export-module-commands.dir/CXX_build_database.json" NO_EXIST) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-check.cmake new file mode 100644 index 0000000..21a29b6 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-check.cmake @@ -0,0 +1,18 @@ +include("${CMAKE_CURRENT_LIST_DIR}/build-database-check.cmake") +set(item_filter "-ifcOnly") + +check_build_database("export-build-database-imported" "build_database.json" NO_EXIST) +check_build_database("export-build-database-imported" "build_database_CXX.json" NO_EXIST) +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" NO_EXIST) + check_build_database("export-build-database-imported" "build_database_Debug.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/export-module-commands.dir/Debug/CXX_build_database.json" NO_EXIST) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "build_database_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/export-module-commands.dir/Release/CXX_build_database.json" NO_EXIST) +else () + check_build_database("export-build-database-imported" "CMakeFiles/export-module-commands.dir/CXX_build_database.json" NO_EXIST) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database-check.cmake new file mode 100644 index 0000000..cfa3a3c --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database-check.cmake @@ -0,0 +1,22 @@ +include("${CMAKE_CURRENT_LIST_DIR}/build-database-check.cmake") +set(item_filter "-ifcOnly") + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database.json" ALL_MULTI) + check_build_database("export-build-database-imported" "build_database_CXX.json" JUST_CXX_MULTI) + + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database-imported" "build_database_Debug.json" JUST_DEBUG) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" CXX_AND_RELEASE) + check_build_database("export-build-database-imported" "build_database_Release.json" JUST_RELEASE) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) +else () + check_build_database("export-build-database-imported" "build_database.json" ALL) + check_build_database("export-build-database-imported" "build_database_CXX.json" JUST_CXX) + + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX-check.cmake new file mode 100644 index 0000000..39203d9 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX-check.cmake @@ -0,0 +1,22 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../build-database-check.cmake") +set(item_filter "-ifcOnly") + +check_build_database("export-build-database-imported" "build_database.json" NO_EXIST) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database_CXX.json" JUST_CXX_MULTI) + + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database-imported" "build_database_Debug.json" JUST_DEBUG) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" CXX_AND_RELEASE) + check_build_database("export-build-database-imported" "build_database_Release.json" JUST_RELEASE) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) +else () + check_build_database("export-build-database-imported" "build_database_CXX.json" JUST_CXX) + + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Debug-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Debug-check.cmake new file mode 100644 index 0000000..cf01237 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Debug-check.cmake @@ -0,0 +1,19 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../../build-database-check.cmake") +set(item_filter "-ifcOnly") + +check_build_database("export-build-database-imported" "build_database.json" NO_EXIST) +check_build_database("export-build-database-imported" "build_database_CXX.json" NO_EXIST) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database-imported" "build_database_Debug.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "build_database_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Release/CXX_build_database.json" NO_EXIST) +else () + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake new file mode 100644 index 0000000..7e231ea --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/CXX/Release-Release-check.cmake @@ -0,0 +1,19 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../../build-database-check.cmake") +set(item_filter "-ifcOnly") + +check_build_database("export-build-database-imported" "build_database.json" NO_EXIST) +check_build_database("export-build-database-imported" "build_database_CXX.json" NO_EXIST) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database-imported" "build_database_Debug.json" JUST_DEBUG) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" CXX_AND_RELEASE) + check_build_database("export-build-database-imported" "build_database_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) +else () + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Debug-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Debug-check.cmake new file mode 100644 index 0000000..876888c --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Debug-check.cmake @@ -0,0 +1,19 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../build-database-check.cmake") +set(item_filter "-ifcOnly") + +check_build_database("export-build-database-imported" "build_database.json" NO_EXIST) +check_build_database("export-build-database-imported" "build_database_CXX.json" NO_EXIST) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database-imported" "build_database_Debug.json" JUST_DEBUG) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "build_database_Release.json" NO_EXIST) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Release/CXX_build_database.json" NO_EXIST) +else () + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Release-check.cmake b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Release-check.cmake new file mode 100644 index 0000000..94edc3b --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-target-cmake_build_database/Release-check.cmake @@ -0,0 +1,19 @@ +include("${CMAKE_CURRENT_LIST_DIR}/../build-database-check.cmake") +set(item_filter "-ifcOnly") + +check_build_database("export-build-database-imported" "build_database.json" NO_EXIST) +check_build_database("export-build-database-imported" "build_database_CXX.json" JUST_CXX) + +if (RunCMake_GENERATOR_IS_MULTI_CONFIG) + check_build_database("export-build-database-imported" "build_database_CXX_Debug.json" CXX_AND_DEBUG) + check_build_database("export-build-database-imported" "build_database_Debug.json" JUST_DEBUG) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Debug/CXX_build_database.json" JUST_TARGET_DEBUG) + + check_build_database("export-build-database-imported" "build_database_CXX_Release.json" CXX_AND_RELEASE) + check_build_database("export-build-database-imported" "build_database_Release.json" JUST_RELEASE) + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/Release/CXX_build_database.json" JUST_TARGET_RELEASE) +else () + check_build_database("export-build-database-imported" "CMakeFiles/use_import_interfaces.dir/CXX_build_database.json" JUST_TARGET) +endif () + +string(REPLACE ";" "\n " RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}") diff --git a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt index 6796660..a12db0a 100644 --- a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt @@ -19,12 +19,25 @@ elseif (TRANSITIVE_MODULES) set(package_name "export_transitive_modules") elseif (WITH_HEADERS) set(package_name "export_with_headers") +elseif (BUILD_DATABASE) + include("${CMAKE_SOURCE_DIR}/../export-build-database-setup.cmake") + set(package_name "export_build_database") else () set(package_name "export_interfaces") endif () set(target_name "CXXModules::${package_name}") find_package("${package_name}" REQUIRED) +if (BUILD_DATABASE) + # Remove `-isystem` flags for better flag checking consistency. + set_property(TARGET "CXXModules::${package_name}" "CXXModules::provide_flags" + PROPERTY SYSTEM 0) + # Disable debug and runtime flag injection. + set_property(TARGET "CXXModules::${package_name}" + PROPERTY MSVC_DEBUG_INFORMATION_FORMAT "") + set_property(TARGET "CXXModules::${package_name}" + PROPERTY MSVC_RUNTIME_LIBRARY "") +endif () add_executable(use_import_interfaces) target_sources(use_import_interfaces @@ -32,5 +45,14 @@ target_sources(use_import_interfaces use.cxx) target_compile_features(use_import_interfaces PRIVATE cxx_std_20) target_link_libraries(use_import_interfaces PRIVATE "${target_name}") +if (BUILD_DATABASE AND + # Detect Clang targeting MSVC ABI. + CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") + # Link to `libcmt.lib`. Build database tests neuter the runtime library + # selection to make flag matching easier. Manually perform the "link the + # runtime library" injected into the object files by the runtime library + # flag. + target_link_libraries(use_import_interfaces PRIVATE libcmt) +endif () add_test(NAME use_import_interfaces COMMAND use_import_interfaces) diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-private.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-private.json new file mode 100644 index 0000000..a4131606 --- /dev/null +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-private.json @@ -0,0 +1,51 @@ +{ + "bmi-installation": null, + "compiler-id": "", + "compiler-frontend-variant": "", + "compiler-simulate-id": "", + "config": "", + "cxx-modules": { + "CMakeFiles/ninja-compiledb-private.dir/sources/module-internal-part.cxx": { + "bmi-only": false, + "destination": null, + "name": "internal_partitions", + "relative-directory": "sources", + "source": "/sources/module-internal-part.cxx", + "type": "CXX_MODULES", + "visibility": "PRIVATE" + }, + "CMakeFiles/ninja-compiledb-private.dir/sources/module-part.cxx": { + "bmi-only": false, + "destination": null, + "name": "modules", + "relative-directory": "", + "source": "/sources/module-part.cxx", + "type": "CXX_MODULES", + "visibility": "PRIVATE" + }, + "CMakeFiles/ninja-compiledb-private.dir/sources/module.cxx": { + "bmi-only": false, + "destination": null, + "name": "modules", + "relative-directory": "", + "source": "/sources/module.cxx", + "type": "CXX_MODULES", + "visibility": "PRIVATE" + } + }, + "database-info": { + "template-path": "/CMakeFiles/ninja-compiledb-private.dir/CXX_build_database.json.in", + "output": "/CMakeFiles/ninja-compiledb-private.dir/CXX_build_database.json" + }, + "dir-cur-bld": "", + "dir-cur-src": "", + "dir-top-bld": "", + "dir-top-src": "", + "exports": [], + "forward-modules-from-target-dirs": [], + "include-dirs": [], + "language": "CXX", + "linked-target-dirs": [], + "module-dir": "/CMakeFiles/ninja-compiledb-private.dir", + "sources": {} +} diff --git a/Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-public.json b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-public.json new file mode 100644 index 0000000..632d56b --- /dev/null +++ b/Tests/RunCMake/CXXModules/expect/NinjaDependInfoCompileDatabase-public.json @@ -0,0 +1,51 @@ +{ + "bmi-installation": null, + "compiler-id": "", + "compiler-frontend-variant": "", + "compiler-simulate-id": "", + "config": "", + "cxx-modules": { + "CMakeFiles/ninja-compiledb-public.dir/sources/module-internal-part.cxx": { + "bmi-only": false, + "destination": null, + "name": "internal_partitions", + "relative-directory": "sources", + "source": "/sources/module-internal-part.cxx", + "type": "CXX_MODULES", + "visibility": "PUBLIC" + }, + "CMakeFiles/ninja-compiledb-public.dir/sources/module-part.cxx": { + "bmi-only": false, + "destination": null, + "name": "modules", + "relative-directory": "", + "source": "/sources/module-part.cxx", + "type": "CXX_MODULES", + "visibility": "PUBLIC" + }, + "CMakeFiles/ninja-compiledb-public.dir/sources/module.cxx": { + "bmi-only": false, + "destination": null, + "name": "modules", + "relative-directory": "", + "source": "/sources/module.cxx", + "type": "CXX_MODULES", + "visibility": "PUBLIC" + } + }, + "database-info": { + "template-path": "/CMakeFiles/ninja-compiledb-public.dir/CXX_build_database.json.in", + "output": "/CMakeFiles/ninja-compiledb-public.dir/CXX_build_database.json" + }, + "dir-cur-bld": "", + "dir-cur-src": "", + "dir-top-bld": "", + "dir-top-src": "", + "exports": [], + "forward-modules-from-target-dirs": [], + "include-dirs": [], + "language": "CXX", + "linked-target-dirs": [], + "module-dir": "/CMakeFiles/ninja-compiledb-public.dir", + "sources": {} +} -- cgit v0.12 From 23cbeb5035910b65b758783d8750ecf99779ec5d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 8 Aug 2024 10:47:53 -0400 Subject: ci: enable `build_database` CXXModules tests --- .gitlab/ci/configure_fedora40_ninja.cmake | 2 +- .gitlab/ci/configure_fedora40_ninja_clang.cmake | 2 +- .gitlab/ci/configure_fedora40_ninja_multi.cmake | 2 +- .gitlab/ci/configure_fedora40_ninja_multi_clang.cmake | 2 +- .gitlab/ci/configure_windows_clang_ninja.cmake | 2 +- .gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab/ci/configure_fedora40_ninja.cmake b/.gitlab/ci/configure_fedora40_ninja.cmake index ae968a3..85c4614 100644 --- a/.gitlab/ci/configure_fedora40_ninja.cmake +++ b/.gitlab/ci/configure_fedora40_ninja.cmake @@ -2,7 +2,7 @@ set(CMake_TEST_GUI "ON" CACHE BOOL "") if (NOT "$ENV{CMAKE_CI_NIGHTLY}" STREQUAL "") set(CMake_TEST_ISPC "ON" CACHE STRING "") endif() -set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database" CACHE STRING "") set(CMake_TEST_TLS_VERIFY_URL "https://gitlab.kitware.com" CACHE STRING "") set(CMake_TEST_TLS_VERIFY_URL_BAD "https://badtls-expired.kitware.com" CACHE STRING "") set(CMake_TEST_TLS_VERSION "1.3" CACHE STRING "") diff --git a/.gitlab/ci/configure_fedora40_ninja_clang.cmake b/.gitlab/ci/configure_fedora40_ninja_clang.cmake index c760603..ee78d92 100644 --- a/.gitlab/ci/configure_fedora40_ninja_clang.cmake +++ b/.gitlab/ci/configure_fedora40_ninja_clang.cmake @@ -1,3 +1,3 @@ -set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database" CACHE STRING "") include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora40_common_clang.cmake") diff --git a/.gitlab/ci/configure_fedora40_ninja_multi.cmake b/.gitlab/ci/configure_fedora40_ninja_multi.cmake index f77606e..b4d9a70 100644 --- a/.gitlab/ci/configure_fedora40_ninja_multi.cmake +++ b/.gitlab/ci/configure_fedora40_ninja_multi.cmake @@ -1,6 +1,6 @@ if (NOT "$ENV{CMAKE_CI_NIGHTLY}" STREQUAL "") set(CMake_TEST_ISPC "ON" CACHE STRING "") endif() -set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database" CACHE STRING "") include("${CMAKE_CURRENT_LIST_DIR}/configure_external_test.cmake") diff --git a/.gitlab/ci/configure_fedora40_ninja_multi_clang.cmake b/.gitlab/ci/configure_fedora40_ninja_multi_clang.cmake index c760603..ee78d92 100644 --- a/.gitlab/ci/configure_fedora40_ninja_multi_clang.cmake +++ b/.gitlab/ci/configure_fedora40_ninja_multi_clang.cmake @@ -1,3 +1,3 @@ -set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database" CACHE STRING "") include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora40_common_clang.cmake") diff --git a/.gitlab/ci/configure_windows_clang_ninja.cmake b/.gitlab/ci/configure_windows_clang_ninja.cmake index fcb2d46..214c754 100644 --- a/.gitlab/ci/configure_windows_clang_ninja.cmake +++ b/.gitlab/ci/configure_windows_clang_ninja.cmake @@ -1,4 +1,4 @@ if("$ENV{CMAKE_CI_BUILD_NAME}" MATCHES "(^|_)gnu(_|$)") - set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly" CACHE STRING "") + set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database" CACHE STRING "") endif() include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_clang_common.cmake") diff --git a/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake b/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake index 207f2a5..89a5841 100644 --- a/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake +++ b/.gitlab/ci/configure_windows_msvc_cxx_modules_common.cmake @@ -1 +1 @@ -set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,shared,export_bmi,install_bmi,bmionly,import_std23" CACHE STRING "") +set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,shared,export_bmi,install_bmi,bmionly,import_std23,build_database" CACHE STRING "") -- cgit v0.12 From e77655555cd17b5b2d4adf86eeb013e49de35cce Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 7 Aug 2024 14:15:50 -0400 Subject: cmExperimental: gate build database support behind a flag Given that the feature currently only supports C++ sources and is not formally accepted by ISO yet, gate it behind a flag. --- Help/dev/experimental.rst | 21 +++++++++++++++++++++ Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst | 6 ++++++ Help/prop_tgt/EXPORT_BUILD_DATABASE.rst | 6 ++++++ Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst | 6 ++++++ Source/cmExperimental.cxx | 9 +++++++++ Source/cmExperimental.h | 1 + Source/cmGeneratorTarget.cxx | 4 ++++ Source/cmGlobalGenerator.cxx | 5 +++++ .../NinjaDependInfoCompileDatabase-stderr.txt | 4 ++++ .../CXXModules/NinjaDependInfoCompileDatabase.cmake | 2 ++ .../examples/export-build-database-setup.cmake | 2 ++ .../examples/export-build-database-stderr.txt | 4 ++++ .../import-modules-export-build-database-stderr.txt | 4 ++++ 13 files changed, 74 insertions(+) create mode 100644 Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-stderr.txt create mode 100644 Tests/RunCMake/CXXModules/examples/export-build-database-stderr.txt create mode 100644 Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-stderr.txt diff --git a/Help/dev/experimental.rst b/Help/dev/experimental.rst index fb33112..f5b9114 100644 --- a/Help/dev/experimental.rst +++ b/Help/dev/experimental.rst @@ -80,3 +80,24 @@ When activated, this experimental feature provides the following: .. _CPS: https://cps-org.github.io/cps/ .. |CPS| replace:: Common Package Specification + +Build database support +====================== + +In order to activate support for exporting build databases, set + +* variable ``CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE`` to +* value ``4bd552e2-b7fb-429a-ab23-c83ef53f3f13``. + +This UUID may change in future versions of CMake. Be sure to use the value +documented here by the source tree of the version of CMake with which you are +experimenting. + +When activated, this experimental feature provides the following: + +* The :prop_tgt:`EXPORT_BUILD_DATABASE` target property and its initializing + variable :variable:`CMAKE_EXPORT_BUILD_DATABASE` and environment variable + :envvar:`CMAKE_EXPORT_BUILD_DATABASE`. + +* Targets with the property set to a true value will have their C++ build + information exported to the build database. diff --git a/Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst b/Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst index ff0fec4..b6d004d 100644 --- a/Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst +++ b/Help/envvar/CMAKE_EXPORT_BUILD_DATABASE.rst @@ -9,3 +9,9 @@ The default value for :variable:`CMAKE_EXPORT_BUILD_DATABASE` when there is no explicit configuration given on the first run while creating a new build tree. On later runs in an existing build tree the value persists in the cache as :variable:`CMAKE_EXPORT_BUILD_DATABASE`. + +.. note :: + + This variable is meaningful only when experimental support for build + databases has been enabled by the + ``CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE`` gate. diff --git a/Help/prop_tgt/EXPORT_BUILD_DATABASE.rst b/Help/prop_tgt/EXPORT_BUILD_DATABASE.rst index 6b2ad1b..6f68b47 100644 --- a/Help/prop_tgt/EXPORT_BUILD_DATABASE.rst +++ b/Help/prop_tgt/EXPORT_BUILD_DATABASE.rst @@ -7,3 +7,9 @@ Enable/Disable output of a build database for a target. This property is initialized by the value of the variable :variable:`CMAKE_EXPORT_BUILD_DATABASE` if it is set when a target is created. + +.. note :: + + This property is meaningful only when experimental support for build + databases has been enabled by the + ``CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE`` gate. diff --git a/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst b/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst index 6b606a0..94d9842 100644 --- a/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst +++ b/Help/variable/CMAKE_EXPORT_BUILD_DATABASE.rst @@ -3,6 +3,12 @@ CMAKE_EXPORT_BUILD_DATABASE .. versionadded:: 3.31 +.. note :: + + This variable is meaningful only when experimental support for build + databases has been enabled by the + ``CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE`` gate. + Enable/Disable output of module compile commands during the build. If enabled, generates a ``build_database.json`` file containing the diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 4504c07..1bfd9b9 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -56,6 +56,15 @@ cmExperimental::FeatureData LookupTable[] = { {}, cmExperimental::TryCompileCondition::Always, false }, + // ExportBuildDatabase + { "ExportBuildDatabase", + "4bd552e2-b7fb-429a-ab23-c83ef53f3f13", + "CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE", + "CMake's support for exporting build databases is experimental. It is " + "meant only for experimentation and feedback to CMake developers.", + {}, + cmExperimental::TryCompileCondition::Never, + false }, }; static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) == static_cast(cmExperimental::Feature::Sentinel), diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h index 46a9bc4..875491c 100644 --- a/Source/cmExperimental.h +++ b/Source/cmExperimental.h @@ -21,6 +21,7 @@ public: WindowsKernelModeDriver, CxxImportStd, ExportPackageInfo, + ExportBuildDatabase, Sentinel, }; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index fcf790f..4b7e243 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5942,6 +5942,10 @@ std::string cmGeneratorTarget::BuildDatabasePath( if (!this->GetPropertyAsBool("EXPORT_BUILD_DATABASE")) { return {}; } + if (!cmExperimental::HasSupportEnabled( + *this->Makefile, cmExperimental::Feature::ExportBuildDatabase)) { + return {}; + } // Check to see if the generator supports it. if (!this->GetGlobalGenerator()->SupportsBuildDatabase()) { return {}; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index a38208c..d6d4653 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -34,6 +34,7 @@ #include "cmCustomCommandLines.h" #include "cmCustomCommandTypes.h" #include "cmDuration.h" +#include "cmExperimental.h" #include "cmExportBuildFileGenerator.h" #include "cmExternalMakefileProjectGenerator.h" #include "cmGeneratedFileStream.h" @@ -3303,6 +3304,10 @@ bool cmGlobalGenerator::AddBuildDatabaseTargets() if (!mf->IsOn("CMAKE_EXPORT_BUILD_DATABASE")) { return true; } + if (!cmExperimental::HasSupportEnabled( + *mf.get(), cmExperimental::Feature::ExportBuildDatabase)) { + return {}; + } static const auto reservedTargets = { "cmake_build_database" }; for (auto const& target : reservedTargets) { diff --git a/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-stderr.txt b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-stderr.txt new file mode 100644 index 0000000..b9886ad --- /dev/null +++ b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase-stderr.txt @@ -0,0 +1,4 @@ +CMake Warning \(dev\) in CMakeLists.txt: + CMake's support for exporting build databases is experimental. It is meant + only for experimentation and feedback to CMake developers. +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake index 1208279..91a6884 100644 --- a/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake +++ b/Tests/RunCMake/CXXModules/NinjaDependInfoCompileDatabase.cmake @@ -2,6 +2,8 @@ # here. set(CMAKE_CXX_SCANDEP_SOURCE "") +set(CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE "4bd552e2-b7fb-429a-ab23-c83ef53f3f13") + enable_language(CXX) if (NOT CMAKE_GENERATOR MATCHES "Ninja") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake b/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake index 6a699c1..20a9e90 100644 --- a/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-setup.cmake @@ -1,3 +1,5 @@ +set(CMAKE_EXPERIMENTAL_EXPORT_BUILD_DATABASE "4bd552e2-b7fb-429a-ab23-c83ef53f3f13") + get_property(is_multiconfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if (is_multiconfig) set(CMAKE_CONFIGURATION_TYPES "Debug" "Release") diff --git a/Tests/RunCMake/CXXModules/examples/export-build-database-stderr.txt b/Tests/RunCMake/CXXModules/examples/export-build-database-stderr.txt new file mode 100644 index 0000000..b9886ad --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-build-database-stderr.txt @@ -0,0 +1,4 @@ +CMake Warning \(dev\) in CMakeLists.txt: + CMake's support for exporting build databases is experimental. It is meant + only for experimentation and feedback to CMake developers. +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-stderr.txt new file mode 100644 index 0000000..b9886ad --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-build-database-stderr.txt @@ -0,0 +1,4 @@ +CMake Warning \(dev\) in CMakeLists.txt: + CMake's support for exporting build databases is experimental. It is meant + only for experimentation and feedback to CMake developers. +This warning is for project developers. Use -Wno-dev to suppress it. -- cgit v0.12