diff options
Diffstat (limited to 'Source')
27 files changed, 741 insertions, 311 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 46a7dee..163224c 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 20) -set(CMake_VERSION_PATCH 20210313) +set(CMake_VERSION_PATCH 20210318) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx index 051c117..af495bb 100644 --- a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx +++ b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.cxx @@ -16,7 +16,7 @@ bool cmCTestEmptyBinaryDirectoryCommand::InitialPass( return false; } - if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0].c_str())) { + if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0])) { std::ostringstream ostr; ostr << "problem removing the binary directory: " << args[0]; this->SetError(ostr.str()); diff --git a/Source/CTest/cmCTestRunScriptCommand.cxx b/Source/CTest/cmCTestRunScriptCommand.cxx index f59ca57..7661d4d 100644 --- a/Source/CTest/cmCTestRunScriptCommand.cxx +++ b/Source/CTest/cmCTestRunScriptCommand.cxx @@ -37,8 +37,8 @@ bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args, ++i; } else { int ret; - cmCTestScriptHandler::RunScript(this->CTest, this->Makefile, - args[i].c_str(), !np, &ret); + cmCTestScriptHandler::RunScript(this->CTest, this->Makefile, args[i], + !np, &ret); this->Makefile->AddDefinition(returnVariable, std::to_string(ret)); } } diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 4808c36..ff0b179 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -4,7 +4,6 @@ #include <cstdio> #include <cstdlib> -#include <cstring> #include <map> #include <ratio> #include <sstream> @@ -91,7 +90,7 @@ void cmCTestScriptHandler::Initialize() cmCTestScriptHandler::~cmCTestScriptHandler() = default; // just adds an argument to the vector -void cmCTestScriptHandler::AddConfigurationScript(const char* script, +void cmCTestScriptHandler::AddConfigurationScript(const std::string& script, bool pscope) { this->ConfigurationScripts.emplace_back(script); @@ -676,7 +675,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard() // clear the binary directory? if (this->EmptyBinDir) { - if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir.c_str())) { + if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir)) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem removing the binary directory" << std::endl); } @@ -724,8 +723,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard() // put the initial cache into the bin dir if (!this->InitialCache.empty()) { - if (!cmCTestScriptHandler::WriteInitialCache(this->BinaryDir.c_str(), - this->InitialCache.c_str())) { + if (!cmCTestScriptHandler::WriteInitialCache(this->BinaryDir, + this->InitialCache)) { this->RestoreBackupDirectories(); return 9; } @@ -812,8 +811,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard() return 0; } -bool cmCTestScriptHandler::WriteInitialCache(const char* directory, - const char* text) +bool cmCTestScriptHandler::WriteInitialCache(const std::string& directory, + const std::string& text) { std::string cacheFile = cmStrCat(directory, "/CMakeCache.txt"); cmGeneratedFileStream fout(cacheFile); @@ -821,9 +820,7 @@ bool cmCTestScriptHandler::WriteInitialCache(const char* directory, return false; } - if (text != nullptr) { - fout.write(text, strlen(text)); - } + fout.write(text.data(), text.size()); // Make sure the operating system has finished writing the file // before closing it. This will ensure the file is finished before @@ -852,7 +849,7 @@ void cmCTestScriptHandler::RestoreBackupDirectories() } bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf, - const char* sname, bool InProcess, + const std::string& sname, bool InProcess, int* returnValue) { auto sh = cm::make_unique<cmCTestScriptHandler>(); @@ -866,10 +863,10 @@ bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf, return true; } -bool cmCTestScriptHandler::EmptyBinaryDirectory(const char* sname) +bool cmCTestScriptHandler::EmptyBinaryDirectory(const std::string& sname) { // try to avoid deleting root - if (!sname || strlen(sname) < 2) { + if (sname.size() < 2) { return false; } diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h index 8eb9658..b7764b2 100644 --- a/Source/CTest/cmCTestScriptHandler.h +++ b/Source/CTest/cmCTestScriptHandler.h @@ -62,7 +62,7 @@ public: /** * Add a script to run, and if is should run in the current process */ - void AddConfigurationScript(const char*, bool pscope); + void AddConfigurationScript(const std::string&, bool pscope); /** * Run a dashboard using a specified confiuration script @@ -72,19 +72,21 @@ public: /* * Run a script */ - static bool RunScript(cmCTest* ctest, cmMakefile* mf, const char* script, - bool InProcess, int* returnValue); + static bool RunScript(cmCTest* ctest, cmMakefile* mf, + const std::string& script, bool InProcess, + int* returnValue); int RunCurrentScript(); /* * Empty Binary Directory */ - static bool EmptyBinaryDirectory(const char* dir); + static bool EmptyBinaryDirectory(const std::string& dir); /* * Write an initial CMakeCache.txt from the given contents. */ - static bool WriteInitialCache(const char* directory, const char* text); + static bool WriteInitialCache(const std::string& directory, + const std::string& text); /* * Some elapsed time handling functions diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 1cb5d00..42c4d5e 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1705,18 +1705,16 @@ bool cmCTestTestHandler::ParseResourceGroupsProperty( bool cmCTestTestHandler::GetListOfTests() { if (!this->IncludeLabelRegExp.empty()) { - this->IncludeLabelRegularExpression.compile( - this->IncludeLabelRegExp.c_str()); + this->IncludeLabelRegularExpression.compile(this->IncludeLabelRegExp); } if (!this->ExcludeLabelRegExp.empty()) { - this->ExcludeLabelRegularExpression.compile( - this->ExcludeLabelRegExp.c_str()); + this->ExcludeLabelRegularExpression.compile(this->ExcludeLabelRegExp); } if (!this->IncludeRegExp.empty()) { - this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str()); + this->IncludeTestsRegularExpression.compile(this->IncludeRegExp); } if (!this->ExcludeRegExp.empty()) { - this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str()); + this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp); } cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Constructing a list of tests" << std::endl, this->Quiet); diff --git a/Source/cmCMakePresetsFile.cxx b/Source/cmCMakePresetsFile.cxx index e9e8c4c..c73ca9a 100644 --- a/Source/cmCMakePresetsFile.cxx +++ b/Source/cmCMakePresetsFile.cxx @@ -9,6 +9,7 @@ #include <iterator> #include <utility> +#include <cm/string_view> #include <cmext/string_view> #include <cm3p/json/reader.h> @@ -28,9 +29,9 @@ return _result; \ } -#define CHECK_EXPAND(out, field, expanders) \ +#define CHECK_EXPAND(out, field, expanders, version) \ { \ - switch (ExpandMacros(field, expanders)) { \ + switch (ExpandMacros(field, expanders, version)) { \ case ExpandMacroResult::Error: \ return false; \ case ExpandMacroResult::Ignore: \ @@ -849,16 +850,19 @@ enum class ExpandMacroResult }; using MacroExpander = std::function<ExpandMacroResult( - const std::string&, const std::string&, std::string&)>; + const std::string&, const std::string&, std::string&, int version)>; ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status, - const std::vector<MacroExpander>& macroExpanders); + const std::vector<MacroExpander>& macroExpanders, + int version); ExpandMacroResult ExpandMacros( - std::string& out, const std::vector<MacroExpander>& macroExpanders); -ExpandMacroResult ExpandMacro( - std::string& out, const std::string& macroNamespace, - const std::string& macroName, - const std::vector<MacroExpander>& macroExpanders); + std::string& out, const std::vector<MacroExpander>& macroExpanders, + int version); +ExpandMacroResult ExpandMacro(std::string& out, + const std::string& macroNamespace, + const std::string& macroName, + const std::vector<MacroExpander>& macroExpanders, + int version); bool ExpandMacros(const cmCMakePresetsFile& file, const ConfigurePreset& preset, @@ -866,7 +870,7 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const std::vector<MacroExpander>& macroExpanders) { std::string binaryDir = preset.BinaryDir; - CHECK_EXPAND(out, binaryDir, macroExpanders) + CHECK_EXPAND(out, binaryDir, macroExpanders, file.GetVersion(preset)) if (!cmSystemTools::FileIsFullPath(binaryDir)) { binaryDir = cmStrCat(file.SourceDir, '/', binaryDir); @@ -876,7 +880,7 @@ bool ExpandMacros(const cmCMakePresetsFile& file, if (!preset.InstallDir.empty()) { std::string installDir = preset.InstallDir; - CHECK_EXPAND(out, installDir, macroExpanders) + CHECK_EXPAND(out, installDir, macroExpanders, file.GetVersion(preset)) if (!cmSystemTools::FileIsFullPath(installDir)) { installDir = cmStrCat(file.SourceDir, '/', installDir); @@ -887,67 +891,76 @@ bool ExpandMacros(const cmCMakePresetsFile& file, for (auto& variable : out->CacheVariables) { if (variable.second) { - CHECK_EXPAND(out, variable.second->Value, macroExpanders) + CHECK_EXPAND(out, variable.second->Value, macroExpanders, + file.GetVersion(preset)) } } return true; } -bool ExpandMacros(const cmCMakePresetsFile&, const BuildPreset&, +bool ExpandMacros(const cmCMakePresetsFile& file, const BuildPreset& preset, cm::optional<BuildPreset>& out, const std::vector<MacroExpander>& macroExpanders) { for (auto& target : out->Targets) { - CHECK_EXPAND(out, target, macroExpanders) + CHECK_EXPAND(out, target, macroExpanders, file.GetVersion(preset)) } for (auto& nativeToolOption : out->NativeToolOptions) { - CHECK_EXPAND(out, nativeToolOption, macroExpanders) + CHECK_EXPAND(out, nativeToolOption, macroExpanders, + file.GetVersion(preset)) } return true; } -bool ExpandMacros(const cmCMakePresetsFile&, const TestPreset&, +bool ExpandMacros(const cmCMakePresetsFile& file, const TestPreset& preset, cm::optional<TestPreset>& out, const std::vector<MacroExpander>& macroExpanders) { for (auto& overwrite : out->OverwriteConfigurationFile) { - CHECK_EXPAND(out, overwrite, macroExpanders); + CHECK_EXPAND(out, overwrite, macroExpanders, file.GetVersion(preset)); } if (out->Output) { - CHECK_EXPAND(out, out->Output->OutputLogFile, macroExpanders) + CHECK_EXPAND(out, out->Output->OutputLogFile, macroExpanders, + file.GetVersion(preset)) } if (out->Filter) { if (out->Filter->Include) { - CHECK_EXPAND(out, out->Filter->Include->Name, macroExpanders) - CHECK_EXPAND(out, out->Filter->Include->Label, macroExpanders) + CHECK_EXPAND(out, out->Filter->Include->Name, macroExpanders, + file.GetVersion(preset)) + CHECK_EXPAND(out, out->Filter->Include->Label, macroExpanders, + file.GetVersion(preset)) if (out->Filter->Include->Index) { CHECK_EXPAND(out, out->Filter->Include->Index->IndexFile, - macroExpanders); + macroExpanders, file.GetVersion(preset)); } } if (out->Filter->Exclude) { - CHECK_EXPAND(out, out->Filter->Exclude->Name, macroExpanders) - CHECK_EXPAND(out, out->Filter->Exclude->Label, macroExpanders) + CHECK_EXPAND(out, out->Filter->Exclude->Name, macroExpanders, + file.GetVersion(preset)) + CHECK_EXPAND(out, out->Filter->Exclude->Label, macroExpanders, + file.GetVersion(preset)) if (out->Filter->Exclude->Fixtures) { - CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Any, macroExpanders) + CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Any, macroExpanders, + file.GetVersion(preset)) CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Setup, - macroExpanders) + macroExpanders, file.GetVersion(preset)) CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Cleanup, - macroExpanders) + macroExpanders, file.GetVersion(preset)) } } } if (out->Execution) { - CHECK_EXPAND(out, out->Execution->ResourceSpecFile, macroExpanders) + CHECK_EXPAND(out, out->Execution->ResourceSpecFile, macroExpanders, + file.GetVersion(preset)) } return true; @@ -968,8 +981,8 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset, MacroExpander defaultMacroExpander = [&file, &preset](const std::string& macroNamespace, - const std::string& macroName, - std::string& macroOut) -> ExpandMacroResult { + const std::string& macroName, std::string& macroOut, + int version) -> ExpandMacroResult { if (macroNamespace.empty()) { if (macroName == "sourceDir") { macroOut += file.SourceDir; @@ -998,6 +1011,13 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset, macroOut += '$'; return ExpandMacroResult::Ok; } + if (macroName == "hostSystemName") { + if (version < 3) { + return ExpandMacroResult::Error; + } + macroOut += cmSystemTools::GetSystemName(); + return ExpandMacroResult::Ok; + } } return ExpandMacroResult::Ignore; @@ -1006,11 +1026,12 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset, MacroExpander environmentMacroExpander = [¯oExpanders, &out, &envCycles]( const std::string& macroNamespace, const std::string& macroName, - std::string& result) -> ExpandMacroResult { + std::string& result, int version) -> ExpandMacroResult { if (macroNamespace == "env" && !macroName.empty() && out) { auto v = out->Environment.find(macroName); if (v != out->Environment.end() && v->second) { - auto e = VisitEnv(*v->second, envCycles[macroName], macroExpanders); + auto e = + VisitEnv(*v->second, envCycles[macroName], macroExpanders, version); if (e != ExpandMacroResult::Ok) { return e; } @@ -1038,7 +1059,8 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset, for (auto& v : out->Environment) { if (v.second) { - switch (VisitEnv(*v.second, envCycles[v.first], macroExpanders)) { + switch (VisitEnv(*v.second, envCycles[v.first], macroExpanders, + file.GetVersion(preset))) { case ExpandMacroResult::Error: return false; case ExpandMacroResult::Ignore: @@ -1054,7 +1076,8 @@ bool ExpandMacros(const cmCMakePresetsFile& file, const T& preset, } ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status, - const std::vector<MacroExpander>& macroExpanders) + const std::vector<MacroExpander>& macroExpanders, + int version) { if (status == CycleStatus::Verified) { return ExpandMacroResult::Ok; @@ -1064,7 +1087,7 @@ ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status, } status = CycleStatus::InProgress; - auto e = ExpandMacros(value, macroExpanders); + auto e = ExpandMacros(value, macroExpanders, version); if (e != ExpandMacroResult::Ok) { return e; } @@ -1073,7 +1096,8 @@ ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status, } ExpandMacroResult ExpandMacros( - std::string& out, const std::vector<MacroExpander>& macroExpanders) + std::string& out, const std::vector<MacroExpander>& macroExpanders, + int version) { std::string result; std::string macroNamespace; @@ -1120,8 +1144,8 @@ ExpandMacroResult ExpandMacros( case State::MacroName: if (c == '}') { - auto e = - ExpandMacro(result, macroNamespace, macroName, macroExpanders); + auto e = ExpandMacro(result, macroNamespace, macroName, + macroExpanders, version); if (e != ExpandMacroResult::Ok) { return e; } @@ -1153,10 +1177,11 @@ ExpandMacroResult ExpandMacros( ExpandMacroResult ExpandMacro(std::string& out, const std::string& macroNamespace, const std::string& macroName, - const std::vector<MacroExpander>& macroExpanders) + const std::vector<MacroExpander>& macroExpanders, + int version) { for (auto const& macroExpander : macroExpanders) { - auto result = macroExpander(macroNamespace, macroName, out); + auto result = macroExpander(macroNamespace, macroName, out, version); if (result != ExpandMacroResult::Ignore) { return result; } @@ -1445,8 +1470,11 @@ cmCMakePresetsFile::ReadProjectPresetsInternal(bool allowNoFiles) if (!it.second.Unexpanded.Hidden) { const auto configurePreset = this->ConfigurePresets.find(it.second.Unexpanded.ConfigurePreset); - if (it.second.Unexpanded.InheritConfigureEnvironment.value_or(true) && - configurePreset != this->ConfigurePresets.end()) { + if (configurePreset == this->ConfigurePresets.end()) { + return ReadFileResult::INVALID_CONFIGURE_PRESET; + } + + if (it.second.Unexpanded.InheritConfigureEnvironment.value_or(true)) { it.second.Unexpanded.Environment.insert( configurePreset->second.Unexpanded.Environment.begin(), configurePreset->second.Unexpanded.Environment.end()); @@ -1462,8 +1490,11 @@ cmCMakePresetsFile::ReadProjectPresetsInternal(bool allowNoFiles) if (!it.second.Unexpanded.Hidden) { const auto configurePreset = this->ConfigurePresets.find(it.second.Unexpanded.ConfigurePreset); - if (it.second.Unexpanded.InheritConfigureEnvironment.value_or(true) && - configurePreset != this->ConfigurePresets.end()) { + if (configurePreset == this->ConfigurePresets.end()) { + return ReadFileResult::INVALID_CONFIGURE_PRESET; + } + + if (it.second.Unexpanded.InheritConfigureEnvironment.value_or(true)) { it.second.Unexpanded.Environment.insert( configurePreset->second.Unexpanded.Environment.begin(), configurePreset->second.Unexpanded.Environment.end()); @@ -1516,6 +1547,8 @@ const char* cmCMakePresetsFile::ResultToString(ReadFileResult result) case ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED: return "File version must be 2 or higher for build and test preset " "support."; + case ReadFileResult::INVALID_CONFIGURE_PRESET: + return "Invalid \"configurePreset\" field"; case ReadFileResult::INSTALL_PREFIX_UNSUPPORTED: return "File version must be 3 or higher for installDir preset " "support."; @@ -1549,6 +1582,11 @@ cmCMakePresetsFile::ReadFileResult cmCMakePresetsFile::ReadJSONFile( if (v < MIN_VERSION || v > MAX_VERSION) { return ReadFileResult::UNRECOGNIZED_VERSION; } + if (user) { + this->UserVersion = v; + } else { + this->Version = v; + } // Support for build and test presets added in version 2. if (v < 2 && diff --git a/Source/cmCMakePresetsFile.h b/Source/cmCMakePresetsFile.h index 517215d..02e6a32 100644 --- a/Source/cmCMakePresetsFile.h +++ b/Source/cmCMakePresetsFile.h @@ -32,6 +32,7 @@ public: USER_PRESET_INHERITANCE, INVALID_MACRO_EXPANSION, BUILD_TEST_PRESETS_UNSUPPORTED, + INVALID_CONFIGURE_PRESET, INSTALL_PREFIX_UNSUPPORTED, }; @@ -294,6 +295,13 @@ public: std::vector<std::string> TestPresetOrder; std::string SourceDir; + int Version; + int UserVersion; + + int GetVersion(const Preset& preset) const + { + return preset.User ? this->UserVersion : this->Version; + } static std::string GetFilename(const std::string& sourceDir); static std::string GetUserFilename(const std::string& sourceDir); diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 620ba19..77b4441 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2221,7 +2221,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args, cmCTestScriptHandler* ch = this->GetScriptHandler(); // -SR is an internal argument, -SP should be ignored when it is passed if (!SRArgumentSpecified) { - ch->AddConfigurationScript(args[i].c_str(), false); + ch->AddConfigurationScript(args[i], false); } } @@ -2231,7 +2231,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args, this->Impl->RunConfigurationScript = true; i++; cmCTestScriptHandler* ch = this->GetScriptHandler(); - ch->AddConfigurationScript(args[i].c_str(), true); + ch->AddConfigurationScript(args[i], true); } if (this->CheckArgument(arg, "-S"_s, "--script") && i < args.size() - 1) { @@ -2240,7 +2240,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args, cmCTestScriptHandler* ch = this->GetScriptHandler(); // -SR is an internal argument, -S should be ignored when it is passed if (!SRArgumentSpecified) { - ch->AddConfigurationScript(args[i].c_str(), true); + ch->AddConfigurationScript(args[i], true); } } } diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index d2a9bec..d529f52 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -686,7 +686,7 @@ std::string cmFileAPI::NoSupportedVersion( // The "codemodel" object kind. -static unsigned int const CodeModelV2Minor = 2; +static unsigned int const CodeModelV2Minor = 3; void cmFileAPI::BuildClientRequestCodeModel( ClientRequest& r, std::vector<RequestVersion> const& versions) diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 9061109..6b8757c 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -20,11 +20,16 @@ #include <cm3p/json/value.h> #include "cmCryptoHash.h" +#include "cmExportSet.h" #include "cmFileAPI.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmInstallDirectoryGenerator.h" +#include "cmInstallExportGenerator.h" +#include "cmInstallFilesGenerator.h" #include "cmInstallGenerator.h" +#include "cmInstallScriptGenerator.h" #include "cmInstallSubdirectoryGenerator.h" #include "cmInstallTargetGenerator.h" #include "cmLinkLineComputer.h" @@ -42,81 +47,13 @@ #include "cmSystemTools.h" #include "cmTarget.h" #include "cmTargetDepend.h" +#include "cmTargetExport.h" #include "cmake.h" namespace { -class Codemodel -{ - cmFileAPI& FileAPI; - unsigned long Version; - - Json::Value DumpPaths(); - Json::Value DumpConfigurations(); - Json::Value DumpConfiguration(std::string const& config); - -public: - Codemodel(cmFileAPI& fileAPI, unsigned long version); - Json::Value Dump(); -}; - -class CodemodelConfig -{ - cmFileAPI& FileAPI; - unsigned long Version; - std::string const& Config; - std::string TopSource; - std::string TopBuild; - - struct Directory - { - cmStateSnapshot Snapshot; - cmLocalGenerator const* LocalGenerator = nullptr; - Json::Value TargetIndexes = Json::arrayValue; - Json::ArrayIndex ProjectIndex; - bool HasInstallRule = false; - }; - std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder> - DirectoryMap; - std::vector<Directory> Directories; - - struct Project - { - cmStateSnapshot Snapshot; - static const Json::ArrayIndex NoParentIndex = - static_cast<Json::ArrayIndex>(-1); - Json::ArrayIndex ParentIndex = NoParentIndex; - Json::Value ChildIndexes = Json::arrayValue; - Json::Value DirectoryIndexes = Json::arrayValue; - Json::Value TargetIndexes = Json::arrayValue; - }; - std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder> - ProjectMap; - std::vector<Project> Projects; - - void ProcessDirectories(); - - Json::ArrayIndex GetDirectoryIndex(cmLocalGenerator const* lg); - Json::ArrayIndex GetDirectoryIndex(cmStateSnapshot s); - - Json::ArrayIndex AddProject(cmStateSnapshot s); - - Json::Value DumpTargets(); - Json::Value DumpTarget(cmGeneratorTarget* gt, Json::ArrayIndex ti); - - Json::Value DumpDirectories(); - Json::Value DumpDirectory(Directory& d); - - Json::Value DumpProjects(); - Json::Value DumpProject(Project& p); - - Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s); - -public: - CodemodelConfig(cmFileAPI& fileAPI, unsigned long version, - std::string const& config); - Json::Value Dump(); -}; +using TargetIndexMapType = + std::unordered_map<cmGeneratorTarget const*, Json::ArrayIndex>; std::string RelativeIfUnder(std::string const& top, std::string const& in) { @@ -131,16 +68,6 @@ std::string RelativeIfUnder(std::string const& top, std::string const& in) return out; } -std::string TargetId(cmGeneratorTarget const* gt, std::string const& topBuild) -{ - cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_256); - std::string path = RelativeIfUnder( - topBuild, gt->GetLocalGenerator()->GetCurrentBinaryDirectory()); - std::string hash = hasher.HashString(path); - hash.resize(20, '0'); - return gt->GetName() + CMAKE_DIRECTORY_ID_SEP + hash; -} - class JBTIndex { public: @@ -290,6 +217,91 @@ Json::Value BacktraceData::Dump() return backtraceGraph; } +class Codemodel +{ + cmFileAPI& FileAPI; + unsigned long Version; + + Json::Value DumpPaths(); + Json::Value DumpConfigurations(); + Json::Value DumpConfiguration(std::string const& config); + +public: + Codemodel(cmFileAPI& fileAPI, unsigned long version); + Json::Value Dump(); +}; + +class CodemodelConfig +{ + cmFileAPI& FileAPI; + unsigned long Version; + std::string const& Config; + std::string TopSource; + std::string TopBuild; + + struct Directory + { + cmStateSnapshot Snapshot; + cmLocalGenerator const* LocalGenerator = nullptr; + Json::Value TargetIndexes = Json::arrayValue; + Json::ArrayIndex ProjectIndex; + bool HasInstallRule = false; + }; + std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder> + DirectoryMap; + std::vector<Directory> Directories; + + struct Project + { + cmStateSnapshot Snapshot; + static const Json::ArrayIndex NoParentIndex = + static_cast<Json::ArrayIndex>(-1); + Json::ArrayIndex ParentIndex = NoParentIndex; + Json::Value ChildIndexes = Json::arrayValue; + Json::Value DirectoryIndexes = Json::arrayValue; + Json::Value TargetIndexes = Json::arrayValue; + }; + std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder> + ProjectMap; + std::vector<Project> Projects; + + TargetIndexMapType TargetIndexMap; + + void ProcessDirectories(); + + Json::ArrayIndex GetDirectoryIndex(cmLocalGenerator const* lg); + Json::ArrayIndex GetDirectoryIndex(cmStateSnapshot s); + + Json::ArrayIndex AddProject(cmStateSnapshot s); + + Json::Value DumpTargets(); + Json::Value DumpTarget(cmGeneratorTarget* gt, Json::ArrayIndex ti); + + Json::Value DumpDirectories(); + Json::Value DumpDirectory(Directory& d); + Json::Value DumpDirectoryObject(Directory& d); + + Json::Value DumpProjects(); + Json::Value DumpProject(Project& p); + + Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s); + +public: + CodemodelConfig(cmFileAPI& fileAPI, unsigned long version, + std::string const& config); + Json::Value Dump(); +}; + +std::string TargetId(cmGeneratorTarget const* gt, std::string const& topBuild) +{ + cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_256); + std::string path = RelativeIfUnder( + topBuild, gt->GetLocalGenerator()->GetCurrentBinaryDirectory()); + std::string hash = hasher.HashString(path); + hash.resize(20, '0'); + return gt->GetName() + CMAKE_DIRECTORY_ID_SEP + hash; +} + struct CompileData { struct IncludeEntry @@ -367,6 +379,31 @@ struct hash<CompileData> } // namespace std namespace { +class DirectoryObject +{ + cmLocalGenerator const* LG = nullptr; + std::string const& Config; + TargetIndexMapType& TargetIndexMap; + std::string TopSource; + std::string TopBuild; + BacktraceData Backtraces; + + void AddBacktrace(Json::Value& object, cmListFileBacktrace const& bt); + + Json::Value DumpPaths(); + Json::Value DumpInstallers(); + Json::Value DumpInstaller(cmInstallGenerator* gen); + Json::Value DumpInstallerExportTargets(cmExportSet* exp); + Json::Value DumpInstallerPath(std::string const& top, + std::string const& fromPathIn, + std::string const& toPath); + +public: + DirectoryObject(cmLocalGenerator const* lg, std::string const& config, + TargetIndexMapType& targetIndexMap); + Json::Value Dump(); +}; + class Target { cmGeneratorTarget* GT; @@ -663,6 +700,8 @@ Json::Value CodemodelConfig::DumpTarget(cmGeneratorTarget* gt, target["projectIndex"] = pi; this->Projects[pi].TargetIndexes.append(ti); + this->TargetIndexMap[gt] = ti; + return target; } @@ -677,7 +716,7 @@ Json::Value CodemodelConfig::DumpDirectories() Json::Value CodemodelConfig::DumpDirectory(Directory& d) { - Json::Value directory = Json::objectValue; + Json::Value directory = this->DumpDirectoryObject(d); std::string sourceDir = d.Snapshot.GetDirectory().GetCurrentSource(); directory["source"] = RelativeIfUnder(this->TopSource, sourceDir); @@ -717,6 +756,31 @@ Json::Value CodemodelConfig::DumpDirectory(Directory& d) return directory; } +Json::Value CodemodelConfig::DumpDirectoryObject(Directory& d) +{ + std::string prefix = "directory"; + std::string sourceDirRel = RelativeIfUnder( + this->TopSource, d.Snapshot.GetDirectory().GetCurrentSource()); + std::string buildDirRel = RelativeIfUnder( + this->TopBuild, d.Snapshot.GetDirectory().GetCurrentBinary()); + if (!cmSystemTools::FileIsFullPath(buildDirRel)) { + prefix = cmStrCat(prefix, '-', buildDirRel); + } else if (!cmSystemTools::FileIsFullPath(sourceDirRel)) { + prefix = cmStrCat(prefix, '-', sourceDirRel); + } + for (char& c : prefix) { + if (c == '/' || c == '\\') { + c = '.'; + } + } + if (!this->Config.empty()) { + prefix += "-" + this->Config; + } + + DirectoryObject dir(d.LocalGenerator, this->Config, this->TargetIndexMap); + return this->FileAPI.MaybeJsonFile(dir.Dump(), prefix); +} + Json::Value CodemodelConfig::DumpProjects() { Json::Value projects = Json::arrayValue; @@ -760,6 +824,246 @@ Json::Value CodemodelConfig::DumpMinimumCMakeVersion(cmStateSnapshot s) return minimumCMakeVersion; } +DirectoryObject::DirectoryObject(cmLocalGenerator const* lg, + std::string const& config, + TargetIndexMapType& targetIndexMap) + : LG(lg) + , Config(config) + , TargetIndexMap(targetIndexMap) + , TopSource(lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeDirectory()) + , TopBuild( + lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory()) + , Backtraces(this->TopSource) +{ +} + +Json::Value DirectoryObject::Dump() +{ + Json::Value directoryObject = Json::objectValue; + directoryObject["paths"] = this->DumpPaths(); + directoryObject["installers"] = this->DumpInstallers(); + directoryObject["backtraceGraph"] = this->Backtraces.Dump(); + return directoryObject; +} + +void DirectoryObject::AddBacktrace(Json::Value& object, + cmListFileBacktrace const& bt) +{ + if (JBTIndex backtrace = this->Backtraces.Add(bt)) { + object["backtrace"] = backtrace.Index; + } +} + +Json::Value DirectoryObject::DumpPaths() +{ + Json::Value paths = Json::objectValue; + + std::string const& sourceDir = this->LG->GetCurrentSourceDirectory(); + paths["source"] = RelativeIfUnder(this->TopSource, sourceDir); + + std::string const& buildDir = this->LG->GetCurrentBinaryDirectory(); + paths["build"] = RelativeIfUnder(this->TopBuild, buildDir); + + return paths; +} + +Json::Value DirectoryObject::DumpInstallers() +{ + Json::Value installers = Json::arrayValue; + for (const auto& gen : this->LG->GetMakefile()->GetInstallGenerators()) { + Json::Value installer = this->DumpInstaller(gen.get()); + if (!installer.empty()) { + installers.append(std::move(installer)); // NOLINT(*) + } + } + return installers; +} + +Json::Value DirectoryObject::DumpInstaller(cmInstallGenerator* gen) +{ + Json::Value installer = Json::objectValue; + + // Exclude subdirectory installers. They are implementation details. + if (dynamic_cast<cmInstallSubdirectoryGenerator*>(gen)) { + return installer; + } + + // Exclude installers not used in this configuration. + if (!gen->InstallsForConfig(this->Config)) { + return installer; + } + + // Add fields specific to each kind of install generator. + if (auto* installTarget = dynamic_cast<cmInstallTargetGenerator*>(gen)) { + cmInstallTargetGenerator::Files const& files = + installTarget->GetFiles(this->Config); + if (files.From.empty()) { + return installer; + } + + installer["type"] = "target"; + installer["destination"] = installTarget->GetDestination(this->Config); + installer["targetId"] = + TargetId(installTarget->GetTarget(), this->TopBuild); + installer["targetIndex"] = + this->TargetIndexMap[installTarget->GetTarget()]; + + std::string fromDir = files.FromDir; + if (!fromDir.empty()) { + fromDir.push_back('/'); + } + + std::string toDir = files.ToDir; + if (!toDir.empty()) { + toDir.push_back('/'); + } + + Json::Value paths = Json::arrayValue; + for (size_t i = 0; i < files.From.size(); ++i) { + std::string const& fromPath = cmStrCat(fromDir, files.From[i]); + std::string const& toPath = cmStrCat(toDir, files.To[i]); + paths.append(this->DumpInstallerPath(this->TopBuild, fromPath, toPath)); + } + installer["paths"] = std::move(paths); + + if (installTarget->GetOptional()) { + installer["isOptional"] = true; + } + + if (installTarget->IsImportLibrary()) { + installer["targetIsImportLibrary"] = true; + } + + switch (files.NamelinkMode) { + case cmInstallTargetGenerator::NamelinkModeNone: + break; + case cmInstallTargetGenerator::NamelinkModeOnly: + installer["targetInstallNamelink"] = "only"; + break; + case cmInstallTargetGenerator::NamelinkModeSkip: + installer["targetInstallNamelink"] = "skip"; + break; + } + + // FIXME: Parse FilePermissions to provide structured information. + // FIXME: Thread EXPORT name through from install() call. + } else if (auto* installFiles = + dynamic_cast<cmInstallFilesGenerator*>(gen)) { + std::vector<std::string> const& files = + installFiles->GetFiles(this->Config); + if (files.empty()) { + return installer; + } + + installer["type"] = "file"; + installer["destination"] = installFiles->GetDestination(this->Config); + Json::Value paths = Json::arrayValue; + std::string const& rename = installFiles->GetRename(this->Config); + if (!rename.empty() && files.size() == 1) { + paths.append(this->DumpInstallerPath(this->TopSource, files[0], rename)); + } else { + for (std::string const& file : installFiles->GetFiles(this->Config)) { + paths.append(RelativeIfUnder(this->TopSource, file)); + } + } + installer["paths"] = std::move(paths); + if (installFiles->GetOptional()) { + installer["isOptional"] = true; + } + // FIXME: Parse FilePermissions to provide structured information. + } else if (auto* installDir = + dynamic_cast<cmInstallDirectoryGenerator*>(gen)) { + std::vector<std::string> const& dirs = + installDir->GetDirectories(this->Config); + if (dirs.empty()) { + return installer; + } + + installer["type"] = "directory"; + installer["destination"] = installDir->GetDestination(this->Config); + Json::Value paths = Json::arrayValue; + for (std::string const& dir : dirs) { + if (cmHasLiteralSuffix(dir, "/")) { + paths.append(this->DumpInstallerPath( + this->TopSource, dir.substr(0, dir.size() - 1), ".")); + } else { + paths.append(this->DumpInstallerPath( + this->TopSource, dir, cmSystemTools::GetFilenameName(dir))); + } + } + installer["paths"] = std::move(paths); + if (installDir->GetOptional()) { + installer["isOptional"] = true; + } + // FIXME: Parse FilePermissions, DirPermissions, and LiteralArguments. + // to provide structured information. + } else if (auto* installExport = + dynamic_cast<cmInstallExportGenerator*>(gen)) { + installer["type"] = "export"; + installer["destination"] = installExport->GetDestination(); + cmExportSet* exportSet = installExport->GetExportSet(); + installer["exportName"] = exportSet->GetName(); + installer["exportTargets"] = this->DumpInstallerExportTargets(exportSet); + Json::Value paths = Json::arrayValue; + paths.append( + RelativeIfUnder(this->TopBuild, installExport->GetMainImportFile())); + installer["paths"] = std::move(paths); + } else if (auto* installScript = + dynamic_cast<cmInstallScriptGenerator*>(gen)) { + if (installScript->IsCode()) { + installer["type"] = "code"; + } else { + installer["type"] = "script"; + installer["scriptFile"] = RelativeIfUnder( + this->TopSource, installScript->GetScript(this->Config)); + } + } + + // Add fields common to all install generators. + installer["component"] = gen->GetComponent(); + if (gen->GetExcludeFromAll()) { + installer["isExcludeFromAll"] = true; + } + this->AddBacktrace(installer, gen->GetBacktrace()); + + return installer; +} + +Json::Value DirectoryObject::DumpInstallerExportTargets(cmExportSet* exp) +{ + Json::Value targets = Json::arrayValue; + for (auto const& targetExport : exp->GetTargetExports()) { + Json::Value target = Json::objectValue; + target["id"] = TargetId(targetExport->Target, this->TopBuild); + target["index"] = this->TargetIndexMap[targetExport->Target]; + targets.append(std::move(target)); // NOLINT(*) + } + return targets; +} + +Json::Value DirectoryObject::DumpInstallerPath(std::string const& top, + std::string const& fromPathIn, + std::string const& toPath) +{ + Json::Value installPath; + + std::string fromPath = RelativeIfUnder(top, fromPathIn); + + // If toPath is the last component of fromPath, use just fromPath. + if (toPath.find_first_of('/') == std::string::npos && + cmHasSuffix(fromPath, toPath) && + (fromPath.size() == toPath.size() || + fromPath[fromPath.size() - toPath.size() - 1] == '/')) { + installPath = fromPath; + } else { + installPath = Json::objectValue; + installPath["from"] = fromPath; + installPath["to"] = toPath; + } + + return installPath; +} + Target::Target(cmGeneratorTarget* gt, std::string const& config) : GT(gt) , Config(config) diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 49b1bd7..d85ba8f 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -374,7 +374,7 @@ void cmFindLibraryHelper::AddName(std::string const& name) regex += "(\\.[0-9]+\\.[0-9]+)?"; } regex += "$"; - entry.Regex.compile(regex.c_str()); + entry.Regex.compile(regex); this->Names.push_back(std::move(entry)); } diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 36be45c..6937639 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -630,8 +630,9 @@ void cmGlobalNinjaGenerator::CleanMetaData() // `build.ninja` to load for this in Ninja-Multi. This may be relaxed in the // future pending further investigation into how Ninja works upstream // (ninja#1721). - if (this->NinjaSupportsUnconditionalRecompactTool && expectBuildManifest && - !missingBuildManifest) { + if (this->NinjaSupportsUnconditionalRecompactTool && + !this->GetCMakeInstance()->GetRegenerateDuringBuild() && + expectBuildManifest && !missingBuildManifest) { run_ninja_tool({ "recompact" }); } if (this->NinjaSupportsRestatTool && this->OutputPathPrefix.empty()) { diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 8d68bf6..74d8135 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -3,6 +3,7 @@ #include "cmGlobalVisualStudio10Generator.h" #include <algorithm> +#include <utility> #include <cm/memory> @@ -302,16 +303,16 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( // If a specific minor version of the toolset was requested, verify that it // is compatible to the major version and that is exists on disk. // If not clear the value. - std::string version = this->GeneratorToolsetVersion; + std::string versionToolset = this->GeneratorToolsetVersion; cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9][0-9]"); - if (regex.find(version)) { - version = "v" + version.erase(2, 1); + if (regex.find(versionToolset)) { + versionToolset = "v" + versionToolset.erase(2, 1); } else { // Version not recognized. Clear it. - version.clear(); + versionToolset.clear(); } - if (!cmHasPrefix(version, this->GetPlatformToolsetString())) { + if (!cmHasPrefix(versionToolset, this->GetPlatformToolsetString())) { std::ostringstream e; /* clang-format off */ e << @@ -329,15 +330,20 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( this->GeneratorToolsetVersion.clear(); } - bool const isDefaultToolset = - this->IsDefaultToolset(this->GeneratorToolsetVersion); - if (isDefaultToolset) { - // If the given version is the default toolset, remove the setting - this->GeneratorToolsetVersion.clear(); - } else { - std::string const toolsetPath = this->GetAuxiliaryToolset(); - if (!toolsetPath.empty() && !cmSystemTools::FileExists(toolsetPath)) { - + std::string auxProps; + switch (this->FindAuxToolset(this->GeneratorToolsetVersion, auxProps)) { + case AuxToolset::None: + this->GeneratorToolsetVersionProps = {}; + break; + case AuxToolset::Default: + // The given version is the default toolset. Remove the setting. + this->GeneratorToolsetVersion.clear(); + this->GeneratorToolsetVersionProps = {}; + break; + case AuxToolset::PropsExist: + this->GeneratorToolsetVersionProps = std::move(auxProps); + break; + case AuxToolset::PropsMissing: { std::ostringstream e; /* clang-format off */ e << @@ -347,22 +353,24 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( " " << this->GetPlatformToolsetString() << ",version=" << this->GeneratorToolsetVersion << "\n" "does not seem to be installed at\n" << - " " << toolsetPath; + " " << auxProps; ; /* clang-format on */ mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); // Clear the configured tool-set this->GeneratorToolsetVersion.clear(); - } + this->GeneratorToolsetVersionProps = {}; + } break; } } if (const char* toolset = this->GetPlatformToolset()) { mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset); } - if (const char* version = this->GetPlatformToolsetVersion()) { - mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION", version); + if (!this->GeneratorToolsetVersion.empty()) { + mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION", + this->GeneratorToolsetVersion); } if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) { mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch); @@ -719,23 +727,10 @@ std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString() return empty; } -const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetVersion() const -{ - std::string const& version = this->GetPlatformToolsetVersionString(); - if (version.empty()) { - return nullptr; - } - return version.c_str(); -} - std::string const& -cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionString() const +cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionProps() const { - if (!this->GeneratorToolsetVersion.empty()) { - return this->GeneratorToolsetVersion; - } - static std::string const empty; - return empty; + return this->GeneratorToolsetVersionProps; } const char* @@ -792,15 +787,11 @@ cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaCustomDirString() const return this->GeneratorToolsetCudaCustomDir; } -bool cmGlobalVisualStudio10Generator::IsDefaultToolset( - const std::string&) const +cmGlobalVisualStudio10Generator::AuxToolset +cmGlobalVisualStudio10Generator::FindAuxToolset(std::string&, + std::string&) const { - return true; -} - -std::string cmGlobalVisualStudio10Generator::GetAuxiliaryToolset() const -{ - return {}; + return AuxToolset::None; } bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf) diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index df79ad7..5e42c17 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -63,9 +63,8 @@ public: const char* GetPlatformToolset() const; std::string const& GetPlatformToolsetString() const; - /** The toolset version. */ - const char* GetPlatformToolsetVersion() const; - std::string const& GetPlatformToolsetVersionString() const; + /** The toolset version props file, if any. */ + std::string const& GetPlatformToolsetVersionProps() const; /** The toolset host architecture name (e.g. x64 for 64-bit host tools). */ const char* GetPlatformToolsetHostArchitecture() const; @@ -122,9 +121,6 @@ public: std::string Encoding() override; const char* GetToolsVersion() const; - virtual bool IsDefaultToolset(const std::string& version) const; - virtual std::string GetAuxiliaryToolset() const; - bool GetSupportsUnityBuilds() const { return this->SupportsUnityBuilds; } bool FindMakeProgram(cmMakefile* mf) override; @@ -170,6 +166,16 @@ protected: virtual bool SelectWindowsPhoneToolset(std::string& toolset) const; virtual bool SelectWindowsStoreToolset(std::string& toolset) const; + enum class AuxToolset + { + None, + Default, + PropsExist, + PropsMissing + }; + virtual AuxToolset FindAuxToolset(std::string& version, + std::string& props) const; + std::string const& GetMSBuildCommand(); cmIDEFlagTable const* LoadFlagTable(std::string const& toolSpecificName, @@ -177,7 +183,7 @@ protected: std::string const& table) const; std::string GeneratorToolset; - std::string GeneratorToolsetVersion; + std::string GeneratorToolsetVersionProps; std::string GeneratorToolsetHostArchitecture; std::string GeneratorToolsetCustomVCTargetsDir; std::string GeneratorToolsetCuda; @@ -230,6 +236,8 @@ private: std::string FindDevEnvCommand() override; std::string GetVSMakeProgram() override { return this->GetMSBuildCommand(); } + std::string GeneratorToolsetVersion; + bool PlatformToolsetNeedsDebugEnum; bool ParseGeneratorToolset(std::string const& ts, cmMakefile* mf); diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index e6c65bb..9a9a465 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -2,6 +2,11 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGlobalVisualStudioVersionedGenerator.h" +#include <cmext/string_view> + +#include "cmsys/FStream.hxx" +#include "cmsys/Glob.hxx" + #include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmLocalVisualStudio10Generator.h" @@ -392,27 +397,6 @@ bool cmGlobalVisualStudioVersionedGenerator::GetVSInstanceVersion( return vsSetupAPIHelper.GetVSInstanceVersion(vsInstanceVersion); } -bool cmGlobalVisualStudioVersionedGenerator::IsDefaultToolset( - const std::string& version) const -{ - if (version.empty()) { - return true; - } - - std::string vcToolsetVersion; - if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) { - - cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9]+"); - if (regex.find(version) && regex.find(vcToolsetVersion)) { - const auto majorMinorEnd = vcToolsetVersion.find('.', 3); - const auto majorMinor = vcToolsetVersion.substr(0, majorMinorEnd); - return version == majorMinor; - } - } - - return false; -} - bool cmGlobalVisualStudioVersionedGenerator::IsStdOutEncodingSupported() const { // Supported from Visual Studio 16.7 Preview 3. @@ -447,29 +431,92 @@ cmGlobalVisualStudioVersionedGenerator::GetAndroidApplicationTypeRevision() return ""; } -std::string cmGlobalVisualStudioVersionedGenerator::GetAuxiliaryToolset() const +cmGlobalVisualStudioVersionedGenerator::AuxToolset +cmGlobalVisualStudioVersionedGenerator::FindAuxToolset( + std::string& version, std::string& props) const { - const char* version = this->GetPlatformToolsetVersion(); - if (version) { - std::string instancePath; - GetVSInstance(instancePath); - std::string toolsetDir = instancePath + "/VC/Auxiliary/Build"; - char sep = '/'; - if (cmSystemTools::VersionCompareGreaterEq(version, "14.20")) { - std::string toolsetDot = - cmStrCat(toolsetDir, '.', version, "/Microsoft.VCToolsVersion.", - version, ".props"); - if (cmSystemTools::PathExists(toolsetDot)) { - sep = '.'; + if (version.empty()) { + return AuxToolset::None; + } + + std::string instancePath; + this->GetVSInstance(instancePath); + cmSystemTools::ConvertToUnixSlashes(instancePath); + + // Translate three-component format accepted by "vcvarsall -vcvars_ver=". + cmsys::RegularExpression threeComponent( + "^([0-9]+\\.[0-9]+)\\.[0-9][0-9][0-9][0-9][0-9]$"); + if (threeComponent.find(version)) { + // Load "VC/Auxiliary/Build/*/Microsoft.VCToolsVersion.*.txt" files + // with two matching components to check their three-component version. + std::string const& twoComponent = threeComponent.match(1); + std::string pattern = + cmStrCat(instancePath, "/VC/Auxiliary/Build/"_s, twoComponent, + "*/Microsoft.VCToolsVersion."_s, twoComponent, "*.txt"_s); + cmsys::Glob glob; + glob.SetRecurseThroughSymlinks(false); + if (glob.FindFiles(pattern)) { + for (std::string const& txt : glob.GetFiles()) { + std::string ver; + cmsys::ifstream fin(txt.c_str()); + if (fin && std::getline(fin, ver)) { + // Strip trailing whitespace. + ver = ver.substr(0, ver.find_first_not_of("0123456789.")); + // If the three-component version matches, translate it to + // that used by the "Microsoft.VCToolsVersion.*.txt" file name. + if (ver == version) { + cmsys::RegularExpression extractVersion( + "VCToolsVersion\\.([0-9.]+)\\.txt$"); + if (extractVersion.find(txt)) { + version = extractVersion.match(1); + break; + } + } + } + } + } + } + + if (cmSystemTools::VersionCompareGreaterEq(version, "14.20")) { + props = cmStrCat(instancePath, "/VC/Auxiliary/Build."_s, version, + "/Microsoft.VCToolsVersion."_s, version, ".props"_s); + if (cmSystemTools::PathExists(props)) { + return AuxToolset::PropsExist; + } + } + props = cmStrCat(instancePath, "/VC/Auxiliary/Build/"_s, version, + "/Microsoft.VCToolsVersion."_s, version, ".props"_s); + if (cmSystemTools::PathExists(props)) { + return AuxToolset::PropsExist; + } + + // Accept the toolset version that is default in the current VS version + // by matching the name later VS versions will use for the SxS props files. + std::string vcToolsetVersion; + if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) { + // Accept an exact-match (three-component version). + if (version == vcToolsetVersion) { + return AuxToolset::Default; + } + + // Accept known SxS props file names using four version components + // in VS versions later than the current. + if (version == "14.28.16.9" && vcToolsetVersion == "14.28.29910") { + return AuxToolset::Default; + } + + // The first two components of the default toolset version typically + // match the name used by later VS versions for the SxS props files. + cmsys::RegularExpression twoComponent("^([0-9]+\\.[0-9]+)"); + if (twoComponent.find(version)) { + std::string const versionPrefix = cmStrCat(twoComponent.match(1), '.'); + if (cmHasPrefix(vcToolsetVersion, versionPrefix)) { + return AuxToolset::Default; } } - std::string toolsetPath = - cmStrCat(toolsetDir, sep, version, "/Microsoft.VCToolsVersion.", version, - ".props"); - cmSystemTools::ConvertToUnixSlashes(toolsetPath); - return toolsetPath; } - return {}; + + return AuxToolset::PropsMissing; } bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf) diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index 46a5f40..cee129e 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -30,8 +30,8 @@ public: bool GetVSInstanceVersion(unsigned long long& vsInstanceVersion) const; - bool IsDefaultToolset(const std::string& version) const override; - std::string GetAuxiliaryToolset() const override; + AuxToolset FindAuxToolset(std::string& version, + std::string& props) const override; bool IsStdOutEncodingSupported() const override; diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index bef785d..eb214fa 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -338,6 +338,7 @@ cmInstallTargetGenerator::Files cmInstallTargetGenerator::GetFiles( // Add the names based on the current namelink mode. if (haveNamelink) { + files.NamelinkMode = this->NamelinkMode; // With a namelink we need to check the mode. if (this->NamelinkMode == NamelinkModeOnly) { // Install the namelink only. diff --git a/Source/cmInstallTargetGenerator.h b/Source/cmInstallTargetGenerator.h index 8c5d444..84fce42 100644 --- a/Source/cmInstallTargetGenerator.h +++ b/Source/cmInstallTargetGenerator.h @@ -39,7 +39,6 @@ public: NamelinkModeSkip }; void SetNamelinkMode(NamelinkModeType mode) { this->NamelinkMode = mode; } - NamelinkModeType GetNamelinkMode() const { return this->NamelinkMode; } std::string GetInstallFilename(const std::string& config) const; @@ -82,6 +81,7 @@ public: // Prefix for all files in To. std::string ToDir; + NamelinkModeType NamelinkMode = NamelinkModeNone; bool NoTweak = false; bool UseSourcePermissions = false; cmInstallType Type = cmInstallType(); diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 1bafdf7..09cd88e 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -34,7 +34,7 @@ namespace { -bool GetIndexArg(char const* arg, int* idx, cmMakefile& mf) +bool GetIndexArg(const std::string& arg, int* idx, cmMakefile& mf) { long value; if (!cmStrToLong(arg, &value)) { @@ -189,7 +189,7 @@ bool HandleGetCommand(std::vector<std::string> const& args, size_t nitem = varArgsExpanded.size(); for (cc = 2; cc < args.size() - 1; cc++) { int item; - if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) { + if (!GetIndexArg(args[cc], &item, status.GetMakefile())) { status.SetError(cmStrCat("index: ", args[cc], " is not a valid index")); return false; } @@ -401,7 +401,7 @@ bool HandleInsertCommand(std::vector<std::string> const& args, // expand the variable int item; - if (!GetIndexArg(args[2].c_str(), &item, status.GetMakefile())) { + if (!GetIndexArg(args[2], &item, status.GetMakefile())) { status.SetError(cmStrCat("index: ", args[2], " is not a valid index")); return false; } @@ -1326,11 +1326,11 @@ bool HandleSublistCommand(std::vector<std::string> const& args, int start; int length; - if (!GetIndexArg(args[2].c_str(), &start, status.GetMakefile())) { + if (!GetIndexArg(args[2], &start, status.GetMakefile())) { status.SetError(cmStrCat("index: ", args[2], " is not a valid index")); return false; } - if (!GetIndexArg(args[3].c_str(), &length, status.GetMakefile())) { + if (!GetIndexArg(args[3], &length, status.GetMakefile())) { status.SetError(cmStrCat("index: ", args[3], " is not a valid index")); return false; } @@ -1389,7 +1389,7 @@ bool HandleRemoveAtCommand(std::vector<std::string> const& args, size_t nitem = varArgsExpanded.size(); for (cc = 2; cc < args.size(); ++cc) { int item; - if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) { + if (!GetIndexArg(args[cc], &item, status.GetMakefile())) { status.SetError(cmStrCat("index: ", args[cc], " is not a valid index")); return false; } diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx index 0369af0..68f40a9 100644 --- a/Source/cmOrderDirectories.cxx +++ b/Source/cmOrderDirectories.cxx @@ -359,7 +359,7 @@ void cmOrderDirectories::SetLinkExtensionInfo( std::string const& removeExtRegex) { this->LinkExtensions = linkExtensions; - this->RemoveLibraryExtension.compile(removeExtRegex.c_str()); + this->RemoveLibraryExtension.compile(removeExtRegex); } void cmOrderDirectories::CollectOriginalDirectories() diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 1e20abb..fbf47ef 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -16,16 +16,9 @@ #include "cmState.h" #include "cmStateDirectory.h" #include "cmStatePrivate.h" +#include "cmSystemTools.h" #include "cmVersion.h" -#if !defined(_WIN32) -# include <sys/utsname.h> -#endif - -#if defined(__CYGWIN__) -# include "cmSystemTools.h" -#endif - cmStateSnapshot::cmStateSnapshot(cmState* state) : State(state) { @@ -292,34 +285,26 @@ void InitializeContentFromParent(T& parentContent, T& thisContent, void cmStateSnapshot::SetDefaultDefinitions() { -/* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set. - With CMake must separate between target and host platform. In most cases - the tests for WIN32, UNIX and APPLE will be for the target system, so an - additional set of variables for the host system is required -> - CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE. - WIN32, UNIX and APPLE are now set in the platform files in - Modules/Platforms/. - To keep cmake scripts (-P) and custom language and compiler modules - working, these variables are still also set here in this place, but they - will be reset in CMakeSystemSpecificInformation.cmake before the platform - files are executed. */ -#if defined(_WIN32) - this->SetDefinition("WIN32", "1"); - this->SetDefinition("CMAKE_HOST_WIN32", "1"); - this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", "Windows"); -#else - this->SetDefinition("UNIX", "1"); - this->SetDefinition("CMAKE_HOST_UNIX", "1"); - -# if defined(__ANDROID__) - this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", "Android"); -# else - struct utsname uts_name; - if (uname(&uts_name) >= 0) { - this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", uts_name.sysname); + /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set. + With CMake must separate between target and host platform. In most cases + the tests for WIN32, UNIX and APPLE will be for the target system, so an + additional set of variables for the host system is required -> + CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE. + WIN32, UNIX and APPLE are now set in the platform files in + Modules/Platforms/. + To keep cmake scripts (-P) and custom language and compiler modules + working, these variables are still also set here in this place, but they + will be reset in CMakeSystemSpecificInformation.cmake before the platform + files are executed. */ + cm::string_view hostSystemName = cmSystemTools::GetSystemName(); + this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", hostSystemName); + if (hostSystemName == "Windows") { + this->SetDefinition("WIN32", "1"); + this->SetDefinition("CMAKE_HOST_WIN32", "1"); + } else { + this->SetDefinition("UNIX", "1"); + this->SetDefinition("CMAKE_HOST_UNIX", "1"); } -# endif -#endif #if defined(__CYGWIN__) std::string legacy; if (cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32", legacy) && diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 23fc3e0..5fa309d 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -241,7 +241,7 @@ bool RegexMatch(std::vector<std::string> const& args, status.GetMakefile().ClearMatches(); // Compile the regular expression. cmsys::RegularExpression re; - if (!re.compile(regex.c_str())) { + if (!re.compile(regex)) { std::string e = "sub-command REGEX, mode MATCH failed to compile regex \"" + regex + "\"."; @@ -283,7 +283,7 @@ bool RegexMatchAll(std::vector<std::string> const& args, status.GetMakefile().ClearMatches(); // Compile the regular expression. cmsys::RegularExpression re; - if (!re.compile(regex.c_str())) { + if (!re.compile(regex)) { std::string e = "sub-command REGEX, mode MATCHALL failed to compile regex \"" + regex + "\"."; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 87ba152..e8e1018 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -103,6 +103,10 @@ # include <malloc.h> /* for malloc/free on QNX */ #endif +#if !defined(_WIN32) && !defined(__ANDROID__) +# include <sys/utsname.h> +#endif + namespace { cmSystemTools::InterruptCallback s_InterruptCallback; @@ -3207,3 +3211,46 @@ bool cmSystemTools::CreateLink(const std::string& origName, return true; } + +cm::string_view cmSystemTools::GetSystemName() +{ +#if defined(_WIN32) + return "Windows"; +#elif defined(__ANDROID__) + return "Android"; +#else + static struct utsname uts_name; + static bool initialized = false; + static cm::string_view systemName; + if (initialized) { + return systemName; + } + if (uname(&uts_name) >= 0) { + initialized = true; + systemName = uts_name.sysname; + + if (cmIsOff(systemName)) { + systemName = "UnknownOS"; + } + + // fix for BSD/OS, remove the / + static const cmsys::RegularExpression bsdOsRegex("BSD.OS"); + cmsys::RegularExpressionMatch match; + if (bsdOsRegex.find(uts_name.sysname, match)) { + systemName = "BSDOS"; + } + + // fix for GNU/kFreeBSD, remove the GNU/ + if (systemName.find("kFreeBSD") != cm::string_view::npos) { + systemName = "kFreeBSD"; + } + + // fix for CYGWIN which has windows version in it + if (systemName.find("CYGWIN") != cm::string_view::npos) { + systemName = "CYGWIN"; + } + return systemName; + } + return ""; +#endif +} diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 2ff4c5d..5620899 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -498,6 +498,9 @@ public: const std::string& newName, std::string* errorMessage = nullptr); + /** Get the system name. */ + static cm::string_view GetSystemName(); + private: static bool s_ForceUnixPaths; static bool s_RunCommandHideConsole; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 6a90675..965ac3e 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -623,14 +623,14 @@ void cmVisualStudio10TargetGenerator::Generate() } switch (this->ProjectType) { - case vcxproj: - if (this->GlobalGenerator->GetPlatformToolsetVersion()) { - Elem(e0, "Import") - .Attribute("Project", - this->GlobalGenerator->GetAuxiliaryToolset()); + case vcxproj: { + std::string const& props = + this->GlobalGenerator->GetPlatformToolsetVersionProps(); + if (!props.empty()) { + Elem(e0, "Import").Attribute("Project", props); } Elem(e0, "Import").Attribute("Project", VS10_CXX_DEFAULT_PROPS); - break; + } break; case csproj: Elem(e0, "Import") .Attribute("Project", VS10_CSharp_DEFAULT_PROPS) diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 6713cc3..9ba4b93 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -74,7 +74,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, std::vector<std::string>::const_iterator argEnd); namespace { -void CMakeCommandUsage(const char* program) +void CMakeCommandUsage(std::string const& program) { std::ostringstream errorStream; @@ -704,7 +704,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, } else if (args[2] == "--ignore-eol") { filesDiffer = cmsys::SystemTools::TextFilesDiffer(args[3], args[4]); } else { - CMakeCommandUsage(args[0].c_str()); + CMakeCommandUsage(args[0]); return 2; } @@ -1085,7 +1085,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, std::string const& directory = args[2]; if (!cmSystemTools::FileExists(directory)) { cmSystemTools::Error("Directory does not exist for chdir command: " + - args[2]); + directory); return 1; } @@ -1152,7 +1152,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, << "\n"; return 1; } - if (!cmSystemTools::CreateSymlink(args[2], args[3])) { + if (!cmSystemTools::CreateSymlink(args[2], destinationFileName)) { return 1; } return 0; @@ -1161,12 +1161,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, // Command to create a hard link. Fails on platforms not // supporting them. if (args[1] == "create_hardlink" && args.size() == 4) { - const char* SouceFileName = args[2].c_str(); - const char* destinationFileName = args[3].c_str(); + std::string const& sourceFileName = args[2]; + std::string const& destinationFileName = args[3]; - if (!cmSystemTools::FileExists(SouceFileName)) { + if (!cmSystemTools::FileExists(sourceFileName)) { std::cerr << "failed to create hard link because source path '" - << SouceFileName << "' does not exist \n"; + << sourceFileName << "' does not exist \n"; return 1; } @@ -1180,7 +1180,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, return 1; } - if (!cmSystemTools::CreateLink(args[2], args[3])) { + if (!cmSystemTools::CreateLink(sourceFileName, destinationFileName)) { return 1; } return 0; @@ -1560,7 +1560,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, } } - CMakeCommandUsage(args[0].c_str()); + CMakeCommandUsage(args[0]); return 1; } |