diff options
Diffstat (limited to 'Source')
98 files changed, 1324 insertions, 926 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 8b8c711..58b8191 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 16) -set(CMake_VERSION_PATCH 20200101) +set(CMake_VERSION_PATCH 20200120) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index ea71007..3516235 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -775,6 +775,11 @@ std::string cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix( } } + std::string componentFileName = + "CPACK_DMG_" + cmSystemTools::UpperCase(componentName) + "_FILE_NAME"; + if (this->IsSet(componentFileName)) { + return this->GetOption(componentFileName); + } return GetComponentPackageFileName(package_file_name, componentName, false); } diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 9530227..712eb77 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -125,7 +125,7 @@ int cmCPackGenerator::PrepareNames() cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl); const char* descFileName = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE"); - if (descFileName) { + if (descFileName && !this->GetOption("CPACK_PACKAGE_DESCRIPTION")) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for: " << descFileName << std::endl); if (!cmSystemTools::FileExists(descFileName)) { @@ -149,7 +149,12 @@ int cmCPackGenerator::PrepareNames() while (ifs && cmSystemTools::GetLineFromStream(ifs, line)) { ostr << cmXMLSafe(line) << std::endl; } - this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str()); + this->SetOption("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str()); + const char* defFileName = + this->GetOption("CPACK_DEFAULT_PACKAGE_DESCRIPTION_FILE"); + if (defFileName && !strcmp(defFileName, descFileName)) { + this->SetOption("CPACK_USED_DEFAULT_PACKAGE_DESCRIPTION_FILE", "ON"); + } } if (!this->GetOption("CPACK_PACKAGE_DESCRIPTION")) { cmCPackLogger( @@ -616,9 +621,9 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( buildConfigs.emplace_back(); } - std::unique_ptr<cmGlobalGenerator> globalGenerator( + std::unique_ptr<cmGlobalGenerator> globalGenerator = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator( - cmakeGenerator)); + cmakeGenerator); if (!globalGenerator) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Specified package generator not found. " diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 4702639..363f536 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -139,10 +139,15 @@ int cmCPackNSISGenerator::PackageFiles() this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_ICON_CODE", installerIconCode.c_str()); } - if (this->IsSet("CPACK_PACKAGE_ICON")) { - std::string installerIconCode = - cmStrCat("!define MUI_HEADERIMAGE_BITMAP \"", - this->GetOption("CPACK_PACKAGE_ICON"), "\"\n"); + std::string installerHeaderImage; + if (this->IsSet("CPACK_NSIS_MUI_HEADERIMAGE")) { + installerHeaderImage = this->GetOption("CPACK_NSIS_MUI_HEADERIMAGE"); + } else if (this->IsSet("CPACK_PACKAGE_ICON")) { + installerHeaderImage = this->GetOption("CPACK_PACKAGE_ICON"); + } + if (!installerHeaderImage.empty()) { + std::string installerIconCode = cmStrCat( + "!define MUI_HEADERIMAGE_BITMAP \"", installerHeaderImage, "\"\n"); this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_ICON_CODE", installerIconCode.c_str()); } diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 2ad661c..5e29386 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -215,11 +215,11 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) if (this->BuildNoCMake) { // Make the generator available for the Build call below. - cmGlobalGenerator* gen = cm.CreateGlobalGenerator(this->BuildGenerator); - cm.SetGlobalGenerator(gen); + cm.SetGlobalGenerator(cm.CreateGlobalGenerator(this->BuildGenerator)); if (!this->BuildGeneratorPlatform.empty()) { - cmMakefile mf(gen, cm.GetCurrentSnapshot()); - if (!gen->SetGeneratorPlatform(this->BuildGeneratorPlatform, &mf)) { + cmMakefile mf(cm.GetGlobalGenerator(), cm.GetCurrentSnapshot()); + if (!cm.GetGlobalGenerator()->SetGeneratorPlatform( + this->BuildGeneratorPlatform, &mf)) { return 1; } } diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 18df214..d1b7701 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -29,13 +29,7 @@ void cmCTestBuildCommand::BindArguments() this->Bind("PROJECT_NAME"_s, this->ProjectName); } -cmCTestBuildCommand::~cmCTestBuildCommand() -{ - if (this->GlobalGenerator) { - delete this->GlobalGenerator; - this->GlobalGenerator = nullptr; - } -} +cmCTestBuildCommand::~cmCTestBuildCommand() = default; cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() { @@ -79,8 +73,7 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() } if (this->GlobalGenerator) { if (this->GlobalGenerator->GetName() != cmakeGeneratorName) { - delete this->GlobalGenerator; - this->GlobalGenerator = nullptr; + this->GlobalGenerator.reset(); } } if (!this->GlobalGenerator) { diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h index da00a43..0f82817 100644 --- a/Source/CTest/cmCTestBuildCommand.h +++ b/Source/CTest/cmCTestBuildCommand.h @@ -48,7 +48,7 @@ public: bool InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) override; - cmGlobalGenerator* GlobalGenerator = nullptr; + std::unique_ptr<cmGlobalGenerator> GlobalGenerator; protected: cmCTestBuildHandler* Handler; diff --git a/Source/CTest/cmCTestConfigureCommand.cxx b/Source/CTest/cmCTestConfigureCommand.cxx index f2f42b4..3854710 100644 --- a/Source/CTest/cmCTestConfigureCommand.cxx +++ b/Source/CTest/cmCTestConfigureCommand.cxx @@ -69,12 +69,11 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler() bool multiConfig = false; bool cmakeBuildTypeInOptions = false; - cmGlobalGenerator* gg = - this->Makefile->GetCMakeInstance()->CreateGlobalGenerator( - cmakeGeneratorName); + auto gg = this->Makefile->GetCMakeInstance()->CreateGlobalGenerator( + cmakeGeneratorName); if (gg) { multiConfig = gg->IsMultiConfig(); - delete gg; + gg.reset(); } std::string cmakeConfigureCommand = diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx index 46b00b1..acb75b2 100644 --- a/Source/CTest/cmCTestSubmitCommand.cxx +++ b/Source/CTest/cmCTestSubmitCommand.cxx @@ -7,6 +7,7 @@ #include <utility> #include <cm/memory> +#include <cm/vector> #include "cm_static_string_view.hxx" @@ -174,7 +175,7 @@ void cmCTestSubmitCommand::CheckArguments( this->PartsMentioned = !this->Parts.empty() || cmContains(keywords, "PARTS"); this->FilesMentioned = !this->Files.empty() || cmContains(keywords, "FILES"); - cmEraseIf(this->Parts, [this](std::string const& arg) -> bool { + cm::erase_if(this->Parts, [this](std::string const& arg) -> bool { cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str()); if (p == cmCTest::PartCount) { std::ostringstream e; @@ -185,7 +186,7 @@ void cmCTestSubmitCommand::CheckArguments( return false; }); - cmEraseIf(this->Files, [this](std::string const& arg) -> bool { + cm::erase_if(this->Files, [this](std::string const& arg) -> bool { if (!cmSystemTools::FileExists(arg)) { std::ostringstream e; e << "File \"" << arg << "\" does not exist. Cannot submit " diff --git a/Source/CTest/cmCTestUploadCommand.cxx b/Source/CTest/cmCTestUploadCommand.cxx index d0e3848..eaef1ca 100644 --- a/Source/CTest/cmCTestUploadCommand.cxx +++ b/Source/CTest/cmCTestUploadCommand.cxx @@ -4,11 +4,11 @@ #include <set> #include <sstream> -#include <vector> + +#include <cm/vector> #include "cm_static_string_view.hxx" -#include "cmAlgorithms.h" #include "cmCTest.h" #include "cmCTestUploadHandler.h" #include "cmMakefile.h" @@ -24,7 +24,7 @@ void cmCTestUploadCommand::BindArguments() void cmCTestUploadCommand::CheckArguments(std::vector<std::string> const&) { - cmEraseIf(this->Files, [this](std::string const& arg) -> bool { + cm::erase_if(this->Files, [this](std::string const& arg) -> bool { if (!cmSystemTools::FileExists(arg)) { std::ostringstream e; e << "File \"" << arg << "\" does not exist. Cannot submit " diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index 2ec9622..cdf899c 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -278,9 +278,6 @@ void cmProcess::OnTimeoutCB(uv_timer_t* timer) void cmProcess::OnTimeout() { - if (this->ProcessState != cmProcess::State::Executing) { - return; - } this->ProcessState = cmProcess::State::Expired; bool const was_still_reading = !this->ReadHandleClosed; if (!this->ReadHandleClosed) { diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index b608fcb..3b5dc04 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -6,6 +6,7 @@ #include <QDir> #include "cmExternalMakefileProjectGenerator.h" +#include "cmGlobalGenerator.h" #include "cmState.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 995088c..5deba8b 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -215,7 +215,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, } if (cmSystemTools::FileIsFullPath(filename)) { - filename = cmSystemTools::CollapseFullPath(filename); + filename = cmSystemTools::CollapseFullPath( + filename, status.GetMakefile().GetHomeOutputDirectory()); } switch (doing) { case doing_depfile: diff --git a/Source/cmAddSubDirectoryCommand.cxx b/Source/cmAddSubDirectoryCommand.cxx index 6a1a514..35eabaf 100644 --- a/Source/cmAddSubDirectoryCommand.cxx +++ b/Source/cmAddSubDirectoryCommand.cxx @@ -53,7 +53,8 @@ bool cmAddSubDirectoryCommand(std::vector<std::string> const& args, status.SetError(error); return false; } - srcPath = cmSystemTools::CollapseFullPath(srcPath); + srcPath = + cmSystemTools::CollapseFullPath(srcPath, mf.GetHomeOutputDirectory()); // Compute the full path to the binary directory. std::string binPath; diff --git a/Source/cmAddTestCommand.cxx b/Source/cmAddTestCommand.cxx index 8942113..205c1c7 100644 --- a/Source/cmAddTestCommand.cxx +++ b/Source/cmAddTestCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmAddTestCommand.h" +#include <cm/memory> + #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" @@ -44,7 +46,7 @@ bool cmAddTestCommand(std::vector<std::string> const& args, } else { test = mf.CreateTest(args[0]); test->SetOldStyle(true); - mf.AddTestGenerator(new cmTestGenerator(test)); + mf.AddTestGenerator(cm::make_unique<cmTestGenerator>(test)); } test->SetCommand(command); @@ -141,7 +143,7 @@ bool cmAddTestCommandHandleNameMode(std::vector<std::string> const& args, test->SetProperty("WORKING_DIRECTORY", working_directory.c_str()); } test->SetCommandExpandLists(command_expand_lists); - mf.AddTestGenerator(new cmTestGenerator(test, configurations)); + mf.AddTestGenerator(cm::make_unique<cmTestGenerator>(test, configurations)); return true; } diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index a179acb..19da2a0 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -37,12 +37,6 @@ FwdIt cmRotate(FwdIt first, FwdIt middle, FwdIt last) return first; } -template <typename Container, typename Predicate> -void cmEraseIf(Container& cont, Predicate pred) -{ - cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); -} - template <typename Range, typename Key> auto cmContainsImpl(Range const& range, Key const& key, cmOverloadPriority<2>) -> decltype(range.exists(key)) @@ -73,40 +67,6 @@ bool cmContains(Range const& range, Key const& key) namespace ContainerAlgorithms { -template <typename T> -struct cmIsPair -{ - enum - { - value = false - }; -}; - -template <typename K, typename V> -struct cmIsPair<std::pair<K, V>> -{ - enum - { - value = true - }; -}; - -template <typename Range, - bool valueTypeIsPair = cmIsPair<typename Range::value_type>::value> -struct DefaultDeleter -{ - void operator()(typename Range::value_type value) const { delete value; } -}; - -template <typename Range> -struct DefaultDeleter<Range, /* valueTypeIsPair = */ true> -{ - void operator()(typename Range::value_type value) const - { - delete value.second; - } -}; - template <typename FwdIt> FwdIt RemoveN(FwdIt i1, FwdIt i2, size_t n) { @@ -139,13 +99,6 @@ using cmBacktraceRange = cmRange<std::vector<cmListFileBacktrace>::const_iterator>; template <typename Range> -void cmDeleteAll(Range const& r) -{ - std::for_each(r.begin(), r.end(), - ContainerAlgorithms::DefaultDeleter<Range>()); -} - -template <typename Range> typename Range::const_iterator cmRemoveN(Range& r, size_t n) { return ContainerAlgorithms::RemoveN(r.begin(), r.end(), n); diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index d627465..265941a 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -190,7 +190,7 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey, if (entryKey.size() > plen && *(end - plen) == '-' && strcmp(end - plen + 1, *p) == 0) { std::string key = entryKey.substr(0, entryKey.size() - plen); - cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str()); + cmCacheManager::CacheIterator it = this->GetCacheIterator(key); if (it.IsAtEnd()) { // Create an entry and store the property. CacheEntry& ne = this->Cache[key]; @@ -497,9 +497,15 @@ cmCacheManager::CacheEntry* cmCacheManager::GetCacheEntry( return nullptr; } -cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char* key) +cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator( + const std::string& key) { - return { *this, key }; + return { *this, key.c_str() }; +} + +cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator() +{ + return { *this, nullptr }; } const std::string* cmCacheManager::GetInitializedCacheValue( @@ -617,7 +623,7 @@ const char* cmCacheManager::CacheEntry::GetProperty( const std::string& prop) const { if (prop == "TYPE") { - return cmState::CacheEntryTypeToString(this->Type); + return cmState::CacheEntryTypeToString(this->Type).c_str(); } if (prop == "VALUE") { return this->Value.c_str(); @@ -638,20 +644,21 @@ void cmCacheManager::CacheEntry::SetProperty(const std::string& prop, } void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop, - const char* value, + const std::string& value, bool asString) { if (prop == "TYPE") { - this->Type = cmState::StringToCacheEntryType(value ? value : "STRING"); + this->Type = cmState::StringToCacheEntryType(!value.empty() ? value.c_str() + : "STRING"); } else if (prop == "VALUE") { - if (value) { - if (!this->Value.empty() && *value && !asString) { + if (!value.empty()) { + if (!this->Value.empty() && !asString) { this->Value += ";"; } this->Value += value; } } else { - this->Properties.AppendProperty(prop, value, asString); + this->Properties.AppendProperty(prop, value.c_str(), asString); } } @@ -673,7 +680,7 @@ void cmCacheManager::CacheIterator::SetProperty(const std::string& p, } void cmCacheManager::CacheIterator::AppendProperty(const std::string& p, - const char* v, + const std::string& v, bool asString) { if (!this->IsAtEnd()) { diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index faa60c5..d8be991 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -39,7 +39,7 @@ private: std::vector<std::string> GetPropertyList() const; const char* GetProperty(const std::string&) const; void SetProperty(const std::string& property, const char* value); - void AppendProperty(const std::string& property, const char* value, + void AppendProperty(const std::string& property, const std::string& value, bool asString = false); bool Initialized = false; }; @@ -58,10 +58,10 @@ public: bool GetPropertyAsBool(const std::string&) const; bool PropertyExists(const std::string&) const; void SetProperty(const std::string& property, const char* value); - void AppendProperty(const std::string& property, const char* value, + void AppendProperty(const std::string& property, const std::string& value, bool asString = false); void SetProperty(const std::string& property, bool value); - const char* GetValue() const { return this->GetEntry().Value.c_str(); } + const std::string& GetValue() const { return this->GetEntry().Value; } bool GetValueAsBool() const; void SetValue(const char*); cmStateEnums::CacheEntryType GetType() const @@ -111,7 +111,8 @@ public: void PrintCache(std::ostream&) const; //! Get the iterator for an entry with a given key. - cmCacheManager::CacheIterator GetCacheIterator(const char* key = nullptr); + cmCacheManager::CacheIterator GetCacheIterator(const std::string& key); + cmCacheManager::CacheIterator GetCacheIterator(); //! Remove an entry from the cache void RemoveCacheEntry(const std::string& key); @@ -124,52 +125,52 @@ public: const char* GetCacheEntryValue(const std::string& key) { - cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str()); + cmCacheManager::CacheIterator it = this->GetCacheIterator(key); if (it.IsAtEnd()) { return nullptr; } - return it.GetValue(); + return it.GetValue().c_str(); } const char* GetCacheEntryProperty(std::string const& key, std::string const& propName) { - return this->GetCacheIterator(key.c_str()).GetProperty(propName); + return this->GetCacheIterator(key).GetProperty(propName); } cmStateEnums::CacheEntryType GetCacheEntryType(std::string const& key) { - return this->GetCacheIterator(key.c_str()).GetType(); + return this->GetCacheIterator(key).GetType(); } bool GetCacheEntryPropertyAsBool(std::string const& key, std::string const& propName) { - return this->GetCacheIterator(key.c_str()).GetPropertyAsBool(propName); + return this->GetCacheIterator(key).GetPropertyAsBool(propName); } void SetCacheEntryProperty(std::string const& key, std::string const& propName, std::string const& value) { - this->GetCacheIterator(key.c_str()).SetProperty(propName, value.c_str()); + this->GetCacheIterator(key).SetProperty(propName, value.c_str()); } void SetCacheEntryBoolProperty(std::string const& key, std::string const& propName, bool value) { - this->GetCacheIterator(key.c_str()).SetProperty(propName, value); + this->GetCacheIterator(key).SetProperty(propName, value); } void SetCacheEntryValue(std::string const& key, std::string const& value) { - this->GetCacheIterator(key.c_str()).SetValue(value.c_str()); + this->GetCacheIterator(key).SetValue(value.c_str()); } void RemoveCacheEntryProperty(std::string const& key, std::string const& propName) { - this->GetCacheIterator(key.c_str()).SetProperty(propName, nullptr); + this->GetCacheIterator(key).SetProperty(propName, nullptr); } void AppendCacheEntryProperty(std::string const& key, @@ -177,8 +178,7 @@ public: std::string const& value, bool asString = false) { - this->GetCacheIterator(key.c_str()) - .AppendProperty(propName, value.c_str(), asString); + this->GetCacheIterator(key).AppendProperty(propName, value, asString); } std::vector<std::string> GetCacheEntryKeys() diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index 645189a..47c821b 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -7,12 +7,11 @@ #include <map> #include <memory> +#include <queue> #include <set> #include <string> #include <vector> -#include <queue> - #include "cmGraphAdjacencyList.h" #include "cmLinkItem.h" #include "cmTargetLinkLibraryType.h" diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index c568253..34f815f 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -8,7 +8,6 @@ #include <cmext/algorithm> -#include "cmAlgorithms.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmGeneratorExpression.h" @@ -30,11 +29,9 @@ void AppendPaths(const std::vector<std::string>& inputs, cmExpandedList(cge->Evaluate(lg, config)); for (std::string& it : result) { cmSystemTools::ConvertToUnixSlashes(it); - if (cmContains(it, '/') && !cmSystemTools::FileIsFullPath(it)) { - it = cmStrCat(lg->GetMakefile()->GetCurrentBinaryDirectory(), '/', it); - } if (cmSystemTools::FileIsFullPath(it)) { - it = cmSystemTools::CollapseFullPath(it); + it = cmSystemTools::CollapseFullPath( + it, lg->GetMakefile()->GetHomeOutputDirectory()); } } cm::append(output, result); diff --git a/Source/cmDependsC.h b/Source/cmDependsC.h index 3bb6e36..868c94a 100644 --- a/Source/cmDependsC.h +++ b/Source/cmDependsC.h @@ -7,12 +7,11 @@ #include <iosfwd> #include <map> +#include <queue> #include <set> #include <string> #include <vector> -#include <queue> - #include "cmsys/RegularExpression.hxx" #include "cmDepends.h" diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index ee43587..3692202 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -33,6 +33,8 @@ static void cmFortranModuleAppendUpperLower(std::string const& mod, ext_len = 4; } else if (cmHasLiteralSuffix(mod, ".smod")) { ext_len = 5; + } else if (cmHasLiteralSuffix(mod, ".sub")) { + ext_len = 4; } std::string const& name = mod.substr(0, mod.size() - ext_len); std::string const& ext = mod.substr(mod.size() - ext_len); @@ -284,7 +286,8 @@ void cmDependsFortran::MatchRemoteModules(std::istream& fin, if (doing_provides) { std::string mod = line; if (!cmHasLiteralSuffix(mod, ".mod") && - !cmHasLiteralSuffix(mod, ".smod")) { + !cmHasLiteralSuffix(mod, ".smod") && + !cmHasLiteralSuffix(mod, ".sub")) { // Support fortran.internal files left by older versions of CMake. // They do not include the ".mod" extension. mod += ".mod"; @@ -470,7 +473,8 @@ bool cmDependsFortran::CopyModule(const std::vector<std::string>& args) if (args.size() >= 5) { compilerId = args[4]; } - if (!cmHasLiteralSuffix(mod, ".mod") && !cmHasLiteralSuffix(mod, ".smod")) { + if (!cmHasLiteralSuffix(mod, ".mod") && !cmHasLiteralSuffix(mod, ".smod") && + !cmHasLiteralSuffix(mod, ".sub")) { // Support depend.make files left by older versions of CMake. // They do not include the ".mod" extension. mod += ".mod"; diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index dbe5a5e..d22bd48 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -301,11 +301,10 @@ cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg, std::vector<std::string> exportFiles; std::string ns; - std::map<std::string, cmExportBuildFileGenerator*>& exportSets = - gg->GetBuildExportSets(); + auto& exportSets = gg->GetBuildExportSets(); for (auto const& exp : exportSets) { - const cmExportBuildFileGenerator* exportSet = exp.second; + const auto& exportSet = exp.second; std::vector<std::string> targets; exportSet->GetTargets(targets); if (cmContains(targets, name)) { diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 2a6bf5d..b7cc193 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -6,6 +6,8 @@ #include <sstream> #include <utility> +#include <cm/memory> + #include "cmsys/RegularExpression.hxx" #include "cm_static_string_view.hxx" @@ -182,11 +184,11 @@ bool cmExportCommand(std::vector<std::string> const& args, } // Setup export file generation. - cmExportBuildFileGenerator* ebfg = nullptr; + std::unique_ptr<cmExportBuildFileGenerator> ebfg = nullptr; if (android) { - ebfg = new cmExportBuildAndroidMKGenerator; + ebfg = cm::make_unique<cmExportBuildAndroidMKGenerator>(); } else { - ebfg = new cmExportBuildFileGenerator; + ebfg = cm::make_unique<cmExportBuildFileGenerator>(); } ebfg->SetExportFile(fname.c_str()); ebfg->SetNamespace(arguments.Namespace); @@ -196,7 +198,7 @@ bool cmExportCommand(std::vector<std::string> const& args, } else { ebfg->SetTargets(targets); } - mf.AddExportBuildFileGenerator(ebfg); + mf.AddExportBuildFileGenerator(ebfg.get()); ebfg->SetExportOld(arguments.ExportOld); // Compute the set of configurations exported. @@ -209,9 +211,9 @@ bool cmExportCommand(std::vector<std::string> const& args, ebfg->AddConfiguration(ct); } if (exportSet != nullptr) { - gg->AddBuildExportExportSet(ebfg); + gg->AddBuildExportExportSet(std::move(ebfg)); } else { - gg->AddBuildExportSet(ebfg); + gg->AddBuildExportSet(std::move(ebfg)); } return true; diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index aeef602..27e9906 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -14,6 +14,7 @@ #include "cmComputeLinkInformation.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" +#include "cmGlobalGenerator.h" #include "cmLinkItem.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" @@ -640,6 +641,9 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( std::string sep; input.clear(); for (std::string& li : parts) { + if (cmHasLiteralPrefix(li, CMAKE_DIRECTORY_ID_SEP)) { + continue; + } if (cmGeneratorExpression::Find(li) == std::string::npos) { this->AddTargetNamespace(li, target, missingTargets); } else { @@ -1062,6 +1066,12 @@ void cmExportFileGenerator::GenerateImportTargetCode( if (target->IsCFBundleOnApple()) { os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n"; } + + // generate DEPRECATION + if (target->IsDeprecated()) { + os << "set_property(TARGET " << targetName << " PROPERTY DEPRECATION " + << cmExportFileGeneratorEscape(target->GetDeprecation()) << ")\n"; + } os << "\n"; } diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx index dfc8de5..6011ba4 100644 --- a/Source/cmExportLibraryDependenciesCommand.cxx +++ b/Source/cmExportLibraryDependenciesCommand.cxx @@ -49,11 +49,11 @@ static void FinalAction(cmMakefile& makefile, std::string const& filename, // the project. cmake* cm = makefile.GetCMakeInstance(); cmGlobalGenerator* global = cm->GetGlobalGenerator(); - const std::vector<cmMakefile*>& locals = global->GetMakefiles(); + const auto& locals = global->GetMakefiles(); std::map<std::string, std::string> libDepsOld; std::map<std::string, std::string> libDepsNew; std::map<std::string, std::string> libTypes; - for (cmMakefile* local : locals) { + for (const auto& local : locals) { for (auto const& tgt : local->GetTargets()) { // Get the current target. cmTarget const& target = tgt.second; diff --git a/Source/cmExternalMakefileProjectGenerator.h b/Source/cmExternalMakefileProjectGenerator.h index a472a06..2b8d505 100644 --- a/Source/cmExternalMakefileProjectGenerator.h +++ b/Source/cmExternalMakefileProjectGenerator.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include <memory> #include <string> #include <vector> @@ -78,7 +79,7 @@ public: std::vector<std::string> GetSupportedGlobalGenerators() const; std::vector<std::string> Aliases; - virtual cmExternalMakefileProjectGenerator* + virtual std::unique_ptr<cmExternalMakefileProjectGenerator> CreateExternalMakefileProjectGenerator() const = 0; void AddSupportedGlobalGenerator(const std::string& base); @@ -100,10 +101,10 @@ public: { } - cmExternalMakefileProjectGenerator* CreateExternalMakefileProjectGenerator() - const override + std::unique_ptr<cmExternalMakefileProjectGenerator> + CreateExternalMakefileProjectGenerator() const override { - T* p = new T; + std::unique_ptr<cmExternalMakefileProjectGenerator> p(new T); p->SetName(GetName()); return p; } diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index e463420..3a22846 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -246,8 +246,7 @@ std::string cmExtraKateGenerator::GenerateFilesString( } } - const std::vector<cmSourceFile*>& sources = makefile->GetSourceFiles(); - for (cmSourceFile* sf : sources) { + for (const auto& sf : makefile->GetSourceFiles()) { if (sf->GetIsGenerated()) { continue; } diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 7a2d9d5..955195f 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -427,7 +427,7 @@ Json::Value Codemodel::DumpConfigurations() Json::Value configurations = Json::arrayValue; cmGlobalGenerator* gg = this->FileAPI.GetCMakeInstance()->GetGlobalGenerator(); - auto makefiles = gg->GetMakefiles(); + const auto& makefiles = gg->GetMakefiles(); if (!makefiles.empty()) { std::vector<std::string> const& configs = makefiles[0]->GetGeneratorConfigs(); @@ -493,8 +493,9 @@ void CodemodelConfig::ProcessDirectories() Directory& d = *di; // Accumulate the presence of install rules on the way up. - for (auto gen : d.LocalGenerator->GetMakefile()->GetInstallGenerators()) { - if (!dynamic_cast<cmInstallSubdirectoryGenerator*>(gen)) { + for (const auto& gen : + d.LocalGenerator->GetMakefile()->GetInstallGenerators()) { + if (!dynamic_cast<cmInstallSubdirectoryGenerator*>(gen.get())) { d.HasInstallRule = true; break; } diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 1fdfa87..d1775a7 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1707,7 +1707,8 @@ bool HandleDownloadCommand(std::vector<std::string> const& args, // as we receive downloaded bits from curl... // std::string dir = cmSystemTools::GetFilenamePath(file); - if (!cmSystemTools::FileExists(dir) && !cmSystemTools::MakeDirectory(dir)) { + if (!dir.empty() && !cmSystemTools::FileExists(dir) && + !cmSystemTools::MakeDirectory(dir)) { std::string errstring = "DOWNLOAD error: cannot create directory '" + dir + "' - Specify file by full path name and verify that you " "have directory creation and file write privileges."; diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 9eb256b..297c72b 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -161,6 +161,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) } this->DebugMode = ComputeIfDebugModeWanted(); + this->DebugBuffer.clear(); // Lookup target architecture, if any. if (const char* arch = @@ -575,6 +576,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) } this->AppendSuccessInformation(); + return loadedPackage; } @@ -708,7 +710,7 @@ bool cmFindPackageCommand::FindModule(bool& found) debugBuffer = cmStrCat(debugBuffer, "The file was found at\n ", mfile, "\n"); } - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } if (!mfile.empty()) { @@ -841,6 +843,11 @@ bool cmFindPackageCommand::HandlePackageMode( result = false; } + if (this->DebugMode) { + this->DebugMessage(this->DebugBuffer); + this->DebugBuffer.clear(); + } + // package not found if (result && !found) { // warn if package required or neither quiet nor in config mode @@ -1001,6 +1008,11 @@ bool cmFindPackageCommand::FindConfig() // Look for the project's configuration file. bool found = false; + if (this->DebugMode) { + this->DebugBuffer = cmStrCat(this->DebugBuffer, + "find_package considered the following " + "locations for the Config module:\n"); + } // Search for frameworks. if (!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly)) { @@ -1027,6 +1039,16 @@ bool cmFindPackageCommand::FindConfig() found = this->FindAppBundleConfig(); } + if (this->DebugMode) { + if (found) { + this->DebugBuffer = cmStrCat( + this->DebugBuffer, "The file was found at\n ", this->FileFound, "\n"); + } else { + this->DebugBuffer = + cmStrCat(this->DebugBuffer, "The file was not found.\n"); + } + } + // Store the entry in the cache so it can be set by the user. std::string init; if (found) { @@ -1040,6 +1062,7 @@ bool cmFindPackageCommand::FindConfig() // We force the value since we do not get here if it was already set. this->Makefile->AddCacheDefinition(this->Variable, init.c_str(), help.c_str(), cmStateEnums::PATH, true); + return found; } @@ -1244,7 +1267,7 @@ void cmFindPackageCommand::FillPrefixesPackageRoot() std::string debugBuffer = "<PackageName>_ROOT CMake variable " "[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1280,7 +1303,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment() "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env " "variables [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); collectPathsForDebug(debugBuffer, paths, debugOffset); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1304,7 +1327,7 @@ void cmFindPackageCommand::FillPrefixesCMakeVariable() "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables " "[CMAKE_FIND_USE_CMAKE_PATH].\n"); collectPathsForDebug(debugBuffer, paths, debugOffset); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1329,7 +1352,7 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment() std::string debugBuffer = "Standard system environment variables " "[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1359,7 +1382,7 @@ void cmFindPackageCommand::FillPrefixesUserRegistry() "CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n"; collectPathsForDebug(debugBuffer, this->LabeledPaths[PathLabel::UserRegistry]); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1379,7 +1402,7 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry() "[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n"; collectPathsForDebug(debugBuffer, this->LabeledPaths[PathLabel::SystemRegistry]); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1558,7 +1581,7 @@ void cmFindPackageCommand::FillPrefixesCMakeSystemVariable() std::string debugBuffer = "CMake variables defined in the Platform file " "[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1573,7 +1596,7 @@ void cmFindPackageCommand::FillPrefixesUserGuess() std::string debugBuffer = "Paths specified by the find_package PATHS option.\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1588,7 +1611,7 @@ void cmFindPackageCommand::FillPrefixesUserHints() std::string debugBuffer = "Paths specified by the find_package HINTS option.\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugMessage(debugBuffer); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); } } @@ -1634,8 +1657,7 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir, for (std::string const& c : this->Configs) { file = cmStrCat(dir, '/', c); if (this->DebugMode) { - std::string msg = "Checking file [" + file + "]\n"; - this->DebugMessage(msg); + this->DebugBuffer = cmStrCat(this->DebugBuffer, " ", file, "\n"); } if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) { // Allow resolving symlinks when the config file is found through a link diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index a65a292..ae9ade7 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -183,6 +183,7 @@ private: std::vector<std::string> Names; std::vector<std::string> Configs; std::set<std::string> IgnoredPaths; + std::string DebugBuffer; /*! the selected sortOrder (None by default)*/ SortOrderType SortOrder; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 19d5b4d..441515c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -10,6 +10,7 @@ #include <cstdlib> #include <cstring> #include <iterator> +#include <queue> #include <sstream> #include <unordered_set> #include <utility> @@ -17,8 +18,6 @@ #include <cm/memory> #include <cm/string_view> -#include <queue> - #include "cmsys/RegularExpression.hxx" #include "cmAlgorithms.h" @@ -2714,6 +2713,17 @@ void cmTargetTraceDependencies::FollowName(std::string const& name) if (i == this->NameMap.end() || i->first != name) { // Check if we know how to generate this file. cmSourcesWithOutput sources = this->Makefile->GetSourcesWithOutput(name); + // If we failed to find a target or source and we have a relative path, it + // might be a valid source if made relative to the current binary + // directory. + if (!sources.Target && !sources.Source && + !cmSystemTools::FileIsFullPath(name)) { + auto fullname = + cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', name); + fullname = cmSystemTools::CollapseFullPath( + fullname, this->Makefile->GetHomeOutputDirectory()); + sources = this->Makefile->GetSourcesWithOutput(fullname); + } i = this->NameMap.emplace_hint(i, name, sources); } if (cmTarget* t = i->second.Target) { @@ -3087,7 +3097,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories( cmLinkImplementationLibraries const* impl = this->GetLinkImplementationLibraries(config); for (cmLinkImplItem const& lib : impl->Libraries) { - std::string libDir = cmSystemTools::CollapseFullPath(lib.AsStr()); + std::string libDir = cmSystemTools::CollapseFullPath( + lib.AsStr(), this->Makefile->GetHomeOutputDirectory()); static cmsys::RegularExpression frameworkCheck( "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); @@ -5407,16 +5418,39 @@ void cmGeneratorTarget::ReportPropertyOrigin( areport); } +bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n, + cmLocalGenerator const*& lg) const +{ + if (cmHasLiteralPrefix(n, CMAKE_DIRECTORY_ID_SEP)) { + cmDirectoryId const dirId = n.substr(sizeof(CMAKE_DIRECTORY_ID_SEP) - 1); + if (dirId.String.empty()) { + lg = this->LocalGenerator; + return true; + } + if (cmLocalGenerator const* otherLG = + this->GlobalGenerator->FindLocalGenerator(dirId)) { + lg = otherLG; + return true; + } + } + return false; +} + void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names, cmListFileBacktrace const& bt, std::vector<cmLinkItem>& items) const { + cmLocalGenerator const* lg = this->LocalGenerator; for (std::string const& n : names) { + if (this->IsLinkLookupScope(n, lg)) { + continue; + } + std::string name = this->CheckCMP0004(n); if (name == this->GetName() || name.empty()) { continue; } - items.push_back(this->ResolveLinkItem(name, bt)); + items.push_back(this->ResolveLinkItem(name, bt, lg)); } } @@ -5425,6 +5459,7 @@ void cmGeneratorTarget::ExpandLinkItems( cmGeneratorTarget const* headTarget, bool usage_requirements_only, std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition) const { + // Keep this logic in sync with ComputeLinkImplementationLibraries. cmGeneratorExpression ge; cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr); // The $<LINK_ONLY> expression may be in a link interface to specify private @@ -6354,6 +6389,21 @@ std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const return lib; } +bool cmGeneratorTarget::IsDeprecated() const +{ + const char* deprecation = this->GetProperty("DEPRECATION"); + return deprecation && *deprecation; +} + +std::string cmGeneratorTarget::GetDeprecation() const +{ + // find DEPRECATION property + if (const char* deprecation = this->GetProperty("DEPRECATION")) { + return deprecation; + } + return std::string(); +} + void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages, const std::string& config) const { @@ -6485,6 +6535,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( const std::string& config, cmOptionalLinkImplementation& impl, cmGeneratorTarget const* head) const { + cmLocalGenerator const* lg = this->LocalGenerator; cmStringRange entryRange = this->Target->GetLinkImplementationEntries(); cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces(); cmBacktraceRange::const_iterator btIt = btRange.begin(); @@ -6493,6 +6544,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( end = entryRange.end(); le != end; ++le, ++btIt) { std::vector<std::string> llibs; + // Keep this logic in sync with ExpandLinkItems. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr, nullptr); cmGeneratorExpression ge(*btIt); @@ -6505,6 +6557,10 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( } for (std::string const& lib : llibs) { + if (this->IsLinkLookupScope(lib, lg)) { + continue; + } + // Skip entries that resolve to the target itself or are empty. std::string name = this->CheckCMP0004(lib); if (name == this->GetName() || name.empty()) { @@ -6539,7 +6595,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( } // The entry is meant for this configuration. - impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt), + impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt, lg), evaluated != *le); } @@ -6576,38 +6632,16 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference( std::string const& name) const { - cmLocalGenerator const* lg = this->LocalGenerator; - std::string const* lookupName = &name; - - // When target_link_libraries() is called with a LHS target that is - // not created in the calling directory it adds a directory id suffix - // that we can use to look up the calling directory. It is that scope - // in which the item name is meaningful. This case is relatively rare - // so we allocate a separate string only when the directory id is present. - std::string::size_type pos = name.find(CMAKE_DIRECTORY_ID_SEP); - std::string plainName; - if (pos != std::string::npos) { - // We will look up the plain name without the directory id suffix. - plainName = name.substr(0, pos); - - // We will look up in the scope of the directory id. - // If we do not recognize the id then leave the original - // syntax in place to produce an indicative error later. - cmDirectoryId const dirId = - name.substr(pos + sizeof(CMAKE_DIRECTORY_ID_SEP) - 1); - if (cmLocalGenerator const* otherLG = - this->GlobalGenerator->FindLocalGenerator(dirId)) { - lg = otherLG; - lookupName = &plainName; - } - } + return this->ResolveTargetReference(name, this->LocalGenerator); +} +cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference( + std::string const& name, cmLocalGenerator const* lg) const +{ TargetOrString resolved; - if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(*lookupName)) { + if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(name)) { resolved.Target = tgt; - } else if (lookupName == &plainName) { - resolved.String = std::move(plainName); } else { resolved.String = name; } @@ -6618,12 +6652,32 @@ cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference( cmLinkItem cmGeneratorTarget::ResolveLinkItem( std::string const& name, cmListFileBacktrace const& bt) const { - TargetOrString resolved = this->ResolveTargetReference(name); + return this->ResolveLinkItem(name, bt, this->LocalGenerator); +} + +cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name, + cmListFileBacktrace const& bt, + cmLocalGenerator const* lg) const +{ + TargetOrString resolved = this->ResolveTargetReference(name, lg); if (!resolved.Target) { return cmLinkItem(resolved.String, bt); } + // Check deprecation, issue message with `bt` backtrace. + if (resolved.Target->IsDeprecated()) { + std::ostringstream w; + /* clang-format off */ + w << + "The library that is being linked to, " << resolved.Target->GetName() << + ", is marked as being deprecated by the owner. The message provided by " + "the developer is: \n" << resolved.Target->GetDeprecation() << "\n"; + /* clang-format on */ + this->LocalGenerator->GetCMakeInstance()->IssueMessage( + MessageType::AUTHOR_WARNING, w.str(), bt); + } + // Skip targets that will not really be linked. This is probably a // name conflict between an external library and an executable // within the project. diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index eabd3fa9..9d06104 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -250,6 +250,13 @@ public: std::string GetAppBundleDirectory(const std::string& config, BundleDirectoryLevel level) const; + /** Return whether this target is marked as deprecated by the + maintainer */ + bool IsDeprecated() const; + + /** Returns the deprecation message provided by the maintainer */ + std::string GetDeprecation() const; + /** Return whether this target is an executable Bundle, a framework or CFBundle on Apple. */ bool IsBundleOnApple() const; @@ -371,9 +378,14 @@ public: cmGeneratorTarget* Target = nullptr; }; TargetOrString ResolveTargetReference(std::string const& name) const; + TargetOrString ResolveTargetReference(std::string const& name, + cmLocalGenerator const* lg) const; cmLinkItem ResolveLinkItem(std::string const& name, cmListFileBacktrace const& bt) const; + cmLinkItem ResolveLinkItem(std::string const& name, + cmListFileBacktrace const& bt, + cmLocalGenerator const* lg) const; // Compute the set of languages compiled by the target. This is // computed every time it is called because the languages can change @@ -912,6 +924,9 @@ private: std::unordered_set<std::string> UnityBatchedSourceFiles; + bool IsLinkLookupScope(std::string const& n, + cmLocalGenerator const*& lg) const; + void ExpandLinkItems(std::string const& prop, std::string const& value, std::string const& config, const cmGeneratorTarget* headTarget, diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index f7c542f..5e2248e 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -279,10 +279,10 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout, std::string frameworkPath; std::string linkPath; - std::unique_ptr<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer = this->GetGlobalGenerator()->CreateLinkLineComputer( this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory())); + this->LocalGenerator->GetStateSnapshot().GetDirectory()); this->LocalGenerator->GetTargetFlags( linkLineComputer.get(), config, linkLibraries, flags, linkFlags, diff --git a/Source/cmGlobalBorlandMakefileGenerator.h b/Source/cmGlobalBorlandMakefileGenerator.h index 291220c..9af0eac 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.h +++ b/Source/cmGlobalBorlandMakefileGenerator.h @@ -17,10 +17,10 @@ class cmGlobalBorlandMakefileGenerator : public cmGlobalUnixMakefileGenerator3 { public: cmGlobalBorlandMakefileGenerator(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory< - cmGlobalBorlandMakefileGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalBorlandMakefileGenerator>()); } //! Get the name for the generator. diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index c189ea5..38ff3ae 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -262,16 +262,17 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, } } -void cmGlobalGenerator::AddBuildExportSet(cmExportBuildFileGenerator* gen) +void cmGlobalGenerator::AddBuildExportSet( + std::unique_ptr<cmExportBuildFileGenerator> gen) { - this->BuildExportSets[gen->GetMainExportFileName()] = gen; + this->BuildExportSets[gen->GetMainExportFileName()] = std::move(gen); } void cmGlobalGenerator::AddBuildExportExportSet( - cmExportBuildFileGenerator* gen) + std::unique_ptr<cmExportBuildFileGenerator> gen) { - this->BuildExportSets[gen->GetMainExportFileName()] = gen; - this->BuildExportExportSets[gen->GetMainExportFileName()] = gen; + this->BuildExportExportSets[gen->GetMainExportFileName()] = gen.get(); + this->AddBuildExportSet(std::move(gen)); } bool cmGlobalGenerator::GenerateImportFile(const std::string& file) @@ -281,13 +282,11 @@ bool cmGlobalGenerator::GenerateImportFile(const std::string& file) bool result = it->second->GenerateImportFile(); if (!this->ConfigureDoneCMP0026AndCMP0024) { - for (cmMakefile* m : this->Makefiles) { - m->RemoveExportBuildFileGeneratorCMP0024(it->second); + for (const auto& m : this->Makefiles) { + m->RemoveExportBuildFileGeneratorCMP0024(it->second.get()); } } - delete it->second; - it->second = nullptr; this->BuildExportSets.erase(it); return result; } @@ -1207,8 +1206,8 @@ void cmGlobalGenerator::CreateLocalGenerators() this->LocalGeneratorSearchIndex.clear(); this->LocalGenerators.clear(); this->LocalGenerators.reserve(this->Makefiles.size()); - for (cmMakefile* m : this->Makefiles) { - auto lg = this->CreateLocalGenerator(m); + for (const auto& m : this->Makefiles) { + auto lg = this->CreateLocalGenerator(m.get()); this->IndexLocalGenerator(lg.get()); this->LocalGenerators.push_back(std::move(lg)); } @@ -1226,9 +1225,10 @@ void cmGlobalGenerator::Configure() snapshot.GetDirectory().SetCurrentBinary( this->CMakeInstance->GetHomeOutputDirectory()); - cmMakefile* dirMf = new cmMakefile(this, snapshot); + auto dirMfu = cm::make_unique<cmMakefile>(this, snapshot); + auto dirMf = dirMfu.get(); + this->Makefiles.push_back(std::move(dirMfu)); dirMf->SetRecursionDepth(this->RecursionDepth); - this->Makefiles.push_back(dirMf); this->IndexMakefile(dirMf); this->BinaryDirectories.insert( @@ -1246,11 +1246,11 @@ void cmGlobalGenerator::Configure() std::vector<GlobalTargetInfo> globalTargets; this->CreateDefaultGlobalTargets(globalTargets); - for (cmMakefile* mf : this->Makefiles) { + for (const auto& mf : this->Makefiles) { auto& targets = mf->GetTargets(); for (GlobalTargetInfo const& globalTarget : globalTargets) { targets.emplace(globalTarget.Name, - this->CreateGlobalTarget(globalTarget, mf)); + this->CreateGlobalTarget(globalTarget, mf.get())); } } } @@ -1299,7 +1299,10 @@ void cmGlobalGenerator::CreateImportedGenerationObjects( { this->CreateGenerationObjects(ImportedOnly); auto const mfit = - std::find(this->Makefiles.begin(), this->Makefiles.end(), mf); + std::find_if(this->Makefiles.begin(), this->Makefiles.end(), + [mf](const std::unique_ptr<cmMakefile>& item) { + return item.get() == mf; + }); auto& lg = this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)]; for (std::string const& t : targets) { @@ -1314,7 +1317,7 @@ cmExportBuildFileGenerator* cmGlobalGenerator::GetExportedTargetsFile( const std::string& filename) const { auto const it = this->BuildExportSets.find(filename); - return it == this->BuildExportSets.end() ? nullptr : it->second; + return it == this->BuildExportSets.end() ? nullptr : it->second.get(); } void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target) @@ -1410,7 +1413,7 @@ bool cmGlobalGenerator::Compute() for (const auto& localGen : this->LocalGenerators) { cmMakefile* mf = localGen->GetMakefile(); - for (cmInstallGenerator* g : mf->GetInstallGenerators()) { + for (const auto& g : mf->GetInstallGenerators()) { if (!g->Compute(localGen.get())) { return false; } @@ -1587,16 +1590,18 @@ bool cmGlobalGenerator::AddAutomaticSources() return true; } -cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer( +std::unique_ptr<cmLinkLineComputer> cmGlobalGenerator::CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const { - return new cmLinkLineComputer(outputConverter, stateDir); + return cm::make_unique<cmLinkLineComputer>(outputConverter, stateDir); } -cmLinkLineComputer* cmGlobalGenerator::CreateMSVC60LinkLineComputer( +std::unique_ptr<cmLinkLineComputer> +cmGlobalGenerator::CreateMSVC60LinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const { - return new cmMSVC60LinkLineComputer(outputConverter, stateDir); + return std::unique_ptr<cmLinkLineComputer>( + cm::make_unique<cmMSVC60LinkLineComputer>(outputConverter, stateDir)); } void cmGlobalGenerator::FinalizeTargetCompileInfo() @@ -1605,7 +1610,7 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() this->CMakeInstance->GetState()->GetEnabledLanguages(); // Construct per-target generator information. - for (cmMakefile* mf : this->Makefiles) { + for (const auto& mf : this->Makefiles) { const cmStringRange noconfig_compile_definitions = mf->GetCompileDefinitionsEntries(); const cmBacktraceRange noconfig_compile_definitions_bts = @@ -1682,28 +1687,26 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes) { std::map<cmTarget*, cmGeneratorTarget*> importedMap; for (unsigned int i = 0; i < this->Makefiles.size(); ++i) { - cmMakefile* mf = this->Makefiles[i]; - for (cmTarget* ownedImpTgt : mf->GetOwnedImportedTargets()) { + auto& mf = this->Makefiles[i]; + for (const auto& ownedImpTgt : mf->GetOwnedImportedTargets()) { cmLocalGenerator* lg = this->LocalGenerators[i].get(); - auto gt = cm::make_unique<cmGeneratorTarget>(ownedImpTgt, lg); - importedMap[ownedImpTgt] = gt.get(); + auto gt = cm::make_unique<cmGeneratorTarget>(ownedImpTgt.get(), lg); + importedMap[ownedImpTgt.get()] = gt.get(); lg->AddOwnedImportedGeneratorTarget(std::move(gt)); } } // Construct per-target generator information. for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - this->CreateGeneratorTargets(targetTypes, this->Makefiles[i], + this->CreateGeneratorTargets(targetTypes, this->Makefiles[i].get(), this->LocalGenerators[i].get(), importedMap); } } void cmGlobalGenerator::ClearGeneratorMembers() { - cmDeleteAll(this->BuildExportSets); this->BuildExportSets.clear(); - cmDeleteAll(this->Makefiles); this->Makefiles.clear(); this->LocalGenerators.clear(); @@ -2000,10 +2003,10 @@ std::string cmGlobalGenerator::GenerateCMakeBuildCommand( return makeCommand; } -void cmGlobalGenerator::AddMakefile(cmMakefile* mf) +void cmGlobalGenerator::AddMakefile(std::unique_ptr<cmMakefile> mf) { - this->Makefiles.push_back(mf); - this->IndexMakefile(mf); + this->IndexMakefile(mf.get()); + this->Makefiles.push_back(std::move(mf)); // update progress // estimate how many lg there will be @@ -2355,7 +2358,7 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets( void cmGlobalGenerator::AddGlobalTarget_Package( std::vector<GlobalTargetInfo>& targets) { - cmMakefile* mf = this->Makefiles[0]; + auto& mf = this->Makefiles[0]; std::string configFile = cmStrCat(mf->GetCurrentBinaryDirectory(), "/CPackConfig.cmake"); if (!cmSystemTools::FileExists(configFile)) { @@ -2404,7 +2407,7 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource( return; } - cmMakefile* mf = this->Makefiles[0]; + auto& mf = this->Makefiles[0]; std::string configFile = cmStrCat(mf->GetCurrentBinaryDirectory(), "/CPackSourceConfig.cmake"); if (!cmSystemTools::FileExists(configFile)) { @@ -2436,7 +2439,7 @@ void cmGlobalGenerator::AddGlobalTarget_PackageSource( void cmGlobalGenerator::AddGlobalTarget_Test( std::vector<GlobalTargetInfo>& targets) { - cmMakefile* mf = this->Makefiles[0]; + auto& mf = this->Makefiles[0]; if (!mf->IsOn("CMAKE_TESTING_ENABLED")) { return; } @@ -2456,6 +2459,13 @@ void cmGlobalGenerator::AddGlobalTarget_Test( cmCustomCommandLine singleLine; singleLine.push_back(cmSystemTools::GetCTestCommand()); singleLine.push_back("--force-new-ctest-process"); + if (auto testArgs = mf->GetDefinition("CMAKE_CTEST_ARGUMENTS")) { + std::vector<std::string> args; + cmExpandList(testArgs, args); + for (auto const& arg : args) { + singleLine.push_back(arg); + } + } if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') { singleLine.push_back("-C"); singleLine.push_back(cmakeCfgIntDir); @@ -2524,7 +2534,7 @@ void cmGlobalGenerator::AddGlobalTarget_RebuildCache( void cmGlobalGenerator::AddGlobalTarget_Install( std::vector<GlobalTargetInfo>& targets) { - cmMakefile* mf = this->Makefiles[0]; + auto& mf = this->Makefiles[0]; const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES"); if (this->InstallTargetEnabled && skipInstallRules) { @@ -2574,7 +2584,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install( singleLine.push_back(cmd); if (cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') { std::string cfgArg = "-DBUILD_TYPE="; - bool useEPN = this->UseEffectivePlatformName(mf); + bool useEPN = this->UseEffectivePlatformName(mf.get()); if (useEPN) { cfgArg += "$(CONFIGURATION)"; singleLine.push_back(cfgArg); @@ -2741,9 +2751,9 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name) } void cmGlobalGenerator::SetExternalMakefileProjectGenerator( - cmExternalMakefileProjectGenerator* extraGenerator) + std::unique_ptr<cmExternalMakefileProjectGenerator> extraGenerator) { - this->ExtraGenerator.reset(extraGenerator); + this->ExtraGenerator = std::move(extraGenerator); if (this->ExtraGenerator) { this->ExtraGenerator->SetGlobalGenerator(this); } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 4794853..51c8d06 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -162,11 +162,11 @@ public: */ virtual void Generate(); - virtual cmLinkLineComputer* CreateLinkLineComputer( + virtual std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const; - cmLinkLineComputer* CreateMSVC60LinkLineComputer( + std::unique_ptr<cmLinkLineComputer> CreateMSVC60LinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const; @@ -249,7 +249,7 @@ public: cmake* GetCMakeInstance() const { return this->CMakeInstance; } void SetConfiguredFilesPath(cmGlobalGenerator* gen); - const std::vector<cmMakefile*>& GetMakefiles() const + const std::vector<std::unique_ptr<cmMakefile>>& GetMakefiles() const { return this->Makefiles; } @@ -268,11 +268,11 @@ public: this->CurrentConfigureMakefile = mf; } - void AddMakefile(cmMakefile* mf); + void AddMakefile(std::unique_ptr<cmMakefile> mf); //! Set an generator for an "external makefile based project" void SetExternalMakefileProjectGenerator( - cmExternalMakefileProjectGenerator* extraGenerator); + std::unique_ptr<cmExternalMakefileProjectGenerator> extraGenerator); std::string GetExtraGeneratorName() const; @@ -445,12 +445,13 @@ public: void ProcessEvaluationFiles(); - std::map<std::string, cmExportBuildFileGenerator*>& GetBuildExportSets() + std::map<std::string, std::unique_ptr<cmExportBuildFileGenerator>>& + GetBuildExportSets() { return this->BuildExportSets; } - void AddBuildExportSet(cmExportBuildFileGenerator*); - void AddBuildExportExportSet(cmExportBuildFileGenerator*); + void AddBuildExportSet(std::unique_ptr<cmExportBuildFileGenerator>); + void AddBuildExportExportSet(std::unique_ptr<cmExportBuildFileGenerator>); bool IsExportedTargetsFile(const std::string& filename) const; bool GenerateImportFile(const std::string& file); cmExportBuildFileGenerator* GetExportedTargetsFile( @@ -551,7 +552,7 @@ protected: std::string FindMakeProgramFile; std::string ConfiguredFilesPath; cmake* CMakeInstance; - std::vector<cmMakefile*> Makefiles; + std::vector<std::unique_ptr<cmMakefile>> Makefiles; LocalGeneratorVector LocalGenerators; cmMakefile* CurrentConfigureMakefile; // map from project name to vector of local generators in that project @@ -561,7 +562,8 @@ protected: std::set<std::string> InstallComponents; // Sets of named target exports cmExportSetMap ExportSets; - std::map<std::string, cmExportBuildFileGenerator*> BuildExportSets; + std::map<std::string, std::unique_ptr<cmExportBuildFileGenerator>> + BuildExportSets; std::map<std::string, cmExportBuildFileGenerator*> BuildExportExportSets; std::map<std::string, std::string> AliasTargets; diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h index bb5f74c..3709365 100644 --- a/Source/cmGlobalGeneratorFactory.h +++ b/Source/cmGlobalGeneratorFactory.h @@ -8,6 +8,8 @@ #include <string> #include <vector> +#include <cm/memory> + class cmGlobalGenerator; class cmake; struct cmDocumentationEntry; @@ -23,8 +25,8 @@ public: virtual ~cmGlobalGeneratorFactory() = default; /** Create a GlobalGenerator */ - virtual cmGlobalGenerator* CreateGlobalGenerator(const std::string& n, - cmake* cm) const = 0; + virtual std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& n, cmake* cm) const = 0; /** Get the documentation entry for this factory */ virtual void GetDocumentation(cmDocumentationEntry& entry) const = 0; @@ -51,13 +53,13 @@ class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory { public: /** Create a GlobalGenerator */ - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { if (name != T::GetActualName()) { - return nullptr; + return std::unique_ptr<cmGlobalGenerator>(); } - return new T(cm); + return std::unique_ptr<cmGlobalGenerator>(cm::make_unique<T>(cm)); } /** Get the documentation entry for this factory */ diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index 989b12c..b82e9f5 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -29,9 +29,10 @@ public: cmGlobalGhsMultiGenerator(cmake* cm); ~cmGlobalGhsMultiGenerator() override; - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory<cmGlobalGhsMultiGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalGhsMultiGenerator>()); } //! create the correct local generator diff --git a/Source/cmGlobalJOMMakefileGenerator.h b/Source/cmGlobalJOMMakefileGenerator.h index fc39ddf..9f1ec8b 100644 --- a/Source/cmGlobalJOMMakefileGenerator.h +++ b/Source/cmGlobalJOMMakefileGenerator.h @@ -4,6 +4,7 @@ #define cmGlobalJOMMakefileGenerator_h #include <iosfwd> +#include <memory> #include "cmGlobalUnixMakefileGenerator3.h" @@ -16,9 +17,10 @@ class cmGlobalJOMMakefileGenerator : public cmGlobalUnixMakefileGenerator3 { public: cmGlobalJOMMakefileGenerator(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory<cmGlobalJOMMakefileGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalJOMMakefileGenerator>()); } //! Get the name for the generator. std::string GetName() const override diff --git a/Source/cmGlobalMSYSMakefileGenerator.h b/Source/cmGlobalMSYSMakefileGenerator.h index d6e4847..b2de4ff 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.h +++ b/Source/cmGlobalMSYSMakefileGenerator.h @@ -3,6 +3,8 @@ #ifndef cmGlobalMSYSMakefileGenerator_h #define cmGlobalMSYSMakefileGenerator_h +#include <memory> + #include "cmGlobalUnixMakefileGenerator3.h" /** \class cmGlobalMSYSMakefileGenerator @@ -14,9 +16,10 @@ class cmGlobalMSYSMakefileGenerator : public cmGlobalUnixMakefileGenerator3 { public: cmGlobalMSYSMakefileGenerator(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory<cmGlobalMSYSMakefileGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalMSYSMakefileGenerator>()); } //! Get the name for the generator. diff --git a/Source/cmGlobalMinGWMakefileGenerator.h b/Source/cmGlobalMinGWMakefileGenerator.h index 15297e3..a9f92a1 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.h +++ b/Source/cmGlobalMinGWMakefileGenerator.h @@ -3,6 +3,8 @@ #ifndef cmGlobalMinGWMakefileGenerator_h #define cmGlobalMinGWMakefileGenerator_h +#include <memory> + #include "cmGlobalUnixMakefileGenerator3.h" /** \class cmGlobalMinGWMakefileGenerator @@ -14,10 +16,10 @@ class cmGlobalMinGWMakefileGenerator : public cmGlobalUnixMakefileGenerator3 { public: cmGlobalMinGWMakefileGenerator(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory< - cmGlobalMinGWMakefileGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalMinGWMakefileGenerator>()); } //! Get the name for the generator. virtual std::string GetName() const diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h index 4586b77..fdf6006 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.h +++ b/Source/cmGlobalNMakeMakefileGenerator.h @@ -4,6 +4,7 @@ #define cmGlobalNMakeMakefileGenerator_h #include <iosfwd> +#include <memory> #include "cmGlobalUnixMakefileGenerator3.h" @@ -16,10 +17,10 @@ class cmGlobalNMakeMakefileGenerator : public cmGlobalUnixMakefileGenerator3 { public: cmGlobalNMakeMakefileGenerator(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory< - cmGlobalNMakeMakefileGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalNMakeMakefileGenerator>()); } //! Get the name for the generator. std::string GetName() const override diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 2a59708..0487ad1 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -25,6 +25,7 @@ #include "cmGeneratorExpressionEvaluationFile.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmLinkLineComputer.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmLocalNinjaGenerator.h" @@ -44,8 +45,6 @@ #include "cmVersion.h" #include "cmake.h" -class cmLinkLineComputer; - const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja"; const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja"; const char* cmGlobalNinjaGenerator::INDENT = " "; @@ -85,13 +84,15 @@ void cmGlobalNinjaGenerator::WriteComment(std::ostream& os, os << "# " << comment.substr(lpos) << "\n\n"; } -cmLinkLineComputer* cmGlobalNinjaGenerator::CreateLinkLineComputer( +std::unique_ptr<cmLinkLineComputer> +cmGlobalNinjaGenerator::CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& /* stateDir */) const { - return new cmNinjaLinkLineComputer( - outputConverter, - this->LocalGenerators[0]->GetStateSnapshot().GetDirectory(), this); + return std::unique_ptr<cmLinkLineComputer>( + cm::make_unique<cmNinjaLinkLineComputer>( + outputConverter, + this->LocalGenerators[0]->GetStateSnapshot().GetDirectory(), this)); } std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name) @@ -529,6 +530,35 @@ void cmGlobalNinjaGenerator::Generate() if (!this->WriteDefaultBuildFile()) { return; } + + auto run_ninja_tool = [this](char const* tool) { + std::vector<std::string> command; + command.push_back(this->NinjaCommand); + command.emplace_back("-t"); + command.emplace_back(tool); + std::string error; + if (!cmSystemTools::RunSingleCommand(command, nullptr, &error, nullptr, + nullptr, + cmSystemTools::OUTPUT_NONE)) { + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + "Running\n '" + + cmJoin(command, "' '") + + "'\n" + "failed with:\n " + + error); + cmSystemTools::SetFatalErrorOccured(); + } + }; + + if (this->NinjaSupportsCleanDeadTool) { + run_ninja_tool("cleandead"); + } + if (this->NinjaSupportsUnconditionalRecompactTool) { + run_ninja_tool("recompact"); + } + if (this->NinjaSupportsRestatTool) { + run_ninja_tool("restat"); + } } bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf) @@ -592,6 +622,16 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures() } } } + this->NinjaSupportsCleanDeadTool = !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForCleanDeadTool().c_str()); + this->NinjaSupportsUnconditionalRecompactTool = + !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForUnconditionalRecompactTool().c_str()); + this->NinjaSupportsRestatTool = !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForRestatTool().c_str()); } bool cmGlobalNinjaGenerator::CheckLanguages( @@ -1152,7 +1192,10 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) this->AppendTargetOutputs(ta.second.GeneratorTarget, build.ExplicitDeps, ta.second.Config); } - this->WriteBuild(os, build); + this->WriteBuild(this->EnableCrossConfigBuild() + ? os + : *this->GetConfigFileStream(ta.second.Config), + build); } if (this->IsMultiConfig()) { @@ -1219,7 +1262,10 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) } } // Write target - this->WriteBuild(os, build); + this->WriteBuild(this->EnableCrossConfigBuild() + ? os + : *this->GetConfigFileStream(config), + build); } // Add shortcut target @@ -1234,7 +1280,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) } // Add target for all configs - if (this->IsMultiConfig()) { + if (this->EnableCrossConfigBuild()) { build.ExplicitDeps.clear(); for (auto const& config : configs) { build.ExplicitDeps.push_back(this->BuildAlias( @@ -1242,7 +1288,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) } build.Outputs.front() = this->BuildAlias( this->ConvertToNinjaPath(currentBinaryDir + "/all"), "all"); - this->WriteBuild(*this->GetCommonFileStream(), build); + this->WriteBuild(os, build); } } } @@ -1290,8 +1336,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) knownDependencies.insert(this->ConvertToNinjaPath(j)); } } - for (cmGeneratorExpressionEvaluationFile* li : - lg->GetMakefile()->GetEvaluationFiles()) { + for (const auto& li : lg->GetMakefile()->GetEvaluationFiles()) { // get all the files created by generator expressions and convert them // to ninja paths for (std::string const& evaluationFile : li->GetFiles()) { @@ -1670,6 +1715,9 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) config)); } for (auto const& fileConfig : configs) { + if (fileConfig != config && !this->EnableCrossConfigBuild()) { + continue; + } if (this->IsMultiConfig()) { build.Variables["FILE_ARG"] = cmStrCat( "-f ", cmGlobalNinjaMultiGenerator::GetNinjaFilename(fileConfig)); @@ -1678,7 +1726,7 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) } } - if (this->IsMultiConfig()) { + if (this->EnableCrossConfigBuild()) { build.Outputs.front() = this->BuildAlias( this->NinjaOutputPath(this->GetCleanTargetName()), "all"); build.ExplicitDeps.clear(); @@ -2044,7 +2092,7 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( snapshot.GetDirectory().SetRelativePathTopBinary(dir_top_bld.c_str()); auto mfd = cm::make_unique<cmMakefile>(this, snapshot); auto lgd = this->CreateLocalGenerator(mfd.get()); - this->Makefiles.push_back(mfd.release()); + this->Makefiles.push_back(std::move(mfd)); this->LocalGenerators.push_back(std::move(lgd)); } @@ -2152,6 +2200,12 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( return true; } +bool cmGlobalNinjaGenerator::EnableCrossConfigBuild() const +{ + return this->IsMultiConfig() && + this->Makefiles.front()->IsOn("CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE"); +} + int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, std::vector<std::string>::const_iterator argEnd) { @@ -2222,12 +2276,11 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg, cmake cm(cmake::RoleInternal, cmState::Unknown); cm.SetHomeDirectory(dir_top_src); cm.SetHomeOutputDirectory(dir_top_bld); - std::unique_ptr<cmGlobalNinjaGenerator> ggd( - static_cast<cmGlobalNinjaGenerator*>(cm.CreateGlobalGenerator("Ninja"))); + auto ggd = cm.CreateGlobalGenerator("Ninja"); if (!ggd || - !ggd->WriteDyndepFile(dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld, - arg_dd, arg_ddis, module_dir, linked_target_dirs, - arg_lang)) { + !cm::static_reference_cast<cmGlobalNinjaGenerator>(ggd).WriteDyndepFile( + dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld, arg_dd, arg_ddis, + module_dir, linked_target_dirs, arg_lang)) { return 1; } return 0; diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 6ebb31d..3545f1e 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -77,7 +77,7 @@ public: std::string EncodeLiteral(const std::string& lit); std::string EncodePath(const std::string& path); - cmLinkLineComputer* CreateLinkLineComputer( + std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const override; @@ -153,9 +153,10 @@ public: public: cmGlobalNinjaGenerator(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaGenerator>()); } std::unique_ptr<cmLocalGenerator> CreateLocalGenerator( @@ -348,6 +349,12 @@ public: return "1.9"; } static std::string RequiredNinjaVersionForDyndeps() { return "1.10"; } + static std::string RequiredNinjaVersionForRestatTool() { return "1.10"; } + static std::string RequiredNinjaVersionForUnconditionalRecompactTool() + { + return "1.10"; + } + static std::string RequiredNinjaVersionForCleanDeadTool() { return "1.10"; } bool SupportsConsolePool() const; bool SupportsImplicitOuts() const; bool SupportsManifestRestat() const; @@ -388,6 +395,8 @@ public: return this->Configs[config].ByproductsForCleanTarget; } + bool EnableCrossConfigBuild() const; + protected: void Generate() override; @@ -488,6 +497,9 @@ private: bool NinjaSupportsManifestRestat = false; bool NinjaSupportsMultilineDepfile = false; bool NinjaSupportsDyndeps = false; + bool NinjaSupportsRestatTool = false; + bool NinjaSupportsUnconditionalRecompactTool = false; + bool NinjaSupportsCleanDeadTool = false; private: void InitOutputPathPrefix(); @@ -524,9 +536,10 @@ public: cmGlobalNinjaMultiGenerator(cmake* cm); bool IsMultiConfig() const override { return true; } - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaMultiGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaMultiGenerator>()); } static void GetDocumentation(cmDocumentationEntry& entry); diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index f2595ea..0591758 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -492,7 +492,7 @@ cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( std::unique_ptr<cmMakefile> mfu; cmMakefile* mf; if (!this->Makefiles.empty()) { - mf = this->Makefiles[0]; + mf = this->Makefiles[0].get(); } else { cmStateSnapshot snapshot = this->CMakeInstance->GetCurrentSnapshot(); snapshot.GetDirectory().SetCurrentSource( diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 5608baf..340a7ef 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -62,10 +62,10 @@ class cmGlobalUnixMakefileGenerator3 : public cmGlobalCommonGenerator { public: cmGlobalUnixMakefileGenerator3(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory< - cmGlobalUnixMakefileGenerator3>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalUnixMakefileGenerator3>()); } //! Get the name for the generator. diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index bdf4cf2..a720cc3 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -57,27 +57,30 @@ class cmGlobalVisualStudio10Generator::Factory : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { std::string genName; const char* p = cmVS10GenName(name, genName); if (!p) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (!*p) { - return new cmGlobalVisualStudio10Generator(cm, genName, ""); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio10Generator(cm, genName, "")); } if (*p++ != ' ') { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (strcmp(p, "Win64") == 0) { - return new cmGlobalVisualStudio10Generator(cm, genName, "x64"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio10Generator(cm, genName, "x64")); } if (strcmp(p, "IA64") == 0) { - return new cmGlobalVisualStudio10Generator(cm, genName, "Itanium"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio10Generator(cm, genName, "Itanium")); } - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } void GetDocumentation(cmDocumentationEntry& entry) const override @@ -117,9 +120,10 @@ public: std::string GetDefaultPlatformName() const override { return "Win32"; } }; -cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory() +std::unique_ptr<cmGlobalGeneratorFactory> +cmGlobalVisualStudio10Generator::NewFactory() { - return new Factory; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory); } cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator( diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index c991c76..2120785 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -16,7 +16,7 @@ class cmGlobalVisualStudio10Generator : public cmGlobalVisualStudio8Generator { public: - static cmGlobalGeneratorFactory* NewFactory(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx index 4b74ef1..a385375 100644 --- a/Source/cmGlobalVisualStudio11Generator.cxx +++ b/Source/cmGlobalVisualStudio11Generator.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGlobalVisualStudio11Generator.h" +#include <utility> + #include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmLocalVisualStudio10Generator.h" @@ -28,38 +30,41 @@ class cmGlobalVisualStudio11Generator::Factory : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { std::string genName; const char* p = cmVS11GenName(name, genName); if (!p) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (!*p) { - return new cmGlobalVisualStudio11Generator(cm, genName, ""); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio11Generator(cm, genName, "")); } if (*p++ != ' ') { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (strcmp(p, "Win64") == 0) { - return new cmGlobalVisualStudio11Generator(cm, genName, "x64"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio11Generator(cm, genName, "x64")); } if (strcmp(p, "ARM") == 0) { - return new cmGlobalVisualStudio11Generator(cm, genName, "ARM"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio11Generator(cm, genName, "ARM")); } std::set<std::string> installedSDKs = cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs(); if (installedSDKs.find(p) == installedSDKs.end()) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } - cmGlobalVisualStudio11Generator* ret = - new cmGlobalVisualStudio11Generator(cm, name, p); + auto ret = std::unique_ptr<cmGlobalVisualStudio11Generator>( + new cmGlobalVisualStudio11Generator(cm, name, p)); ret->WindowsCEVersion = "8.00"; - return ret; + return std::unique_ptr<cmGlobalGenerator>(std::move(ret)); } void GetDocumentation(cmDocumentationEntry& entry) const override @@ -113,9 +118,10 @@ public: std::string GetDefaultPlatformName() const override { return "Win32"; } }; -cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory() +std::unique_ptr<cmGlobalGeneratorFactory> +cmGlobalVisualStudio11Generator::NewFactory() { - return new Factory; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory); } cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator( diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h index f8cce18..5f1ff73 100644 --- a/Source/cmGlobalVisualStudio11Generator.h +++ b/Source/cmGlobalVisualStudio11Generator.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <memory> #include <set> #include <string> @@ -20,7 +21,7 @@ class cmake; class cmGlobalVisualStudio11Generator : public cmGlobalVisualStudio10Generator { public: - static cmGlobalGeneratorFactory* NewFactory(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index d9702c9..5a27994 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -28,27 +28,30 @@ class cmGlobalVisualStudio12Generator::Factory : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { std::string genName; const char* p = cmVS12GenName(name, genName); if (!p) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (!*p) { - return new cmGlobalVisualStudio12Generator(cm, genName, ""); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio12Generator(cm, genName, "")); } if (*p++ != ' ') { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (strcmp(p, "Win64") == 0) { - return new cmGlobalVisualStudio12Generator(cm, genName, "x64"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio12Generator(cm, genName, "x64")); } if (strcmp(p, "ARM") == 0) { - return new cmGlobalVisualStudio12Generator(cm, genName, "ARM"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio12Generator(cm, genName, "ARM")); } - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } void GetDocumentation(cmDocumentationEntry& entry) const override @@ -88,9 +91,10 @@ public: std::string GetDefaultPlatformName() const override { return "Win32"; } }; -cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory() +std::unique_ptr<cmGlobalGeneratorFactory> +cmGlobalVisualStudio12Generator::NewFactory() { - return new Factory; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory); } cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator( diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h index 53b7091..bdd40ff 100644 --- a/Source/cmGlobalVisualStudio12Generator.h +++ b/Source/cmGlobalVisualStudio12Generator.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <memory> #include <string> #include "cmGlobalVisualStudio11Generator.h" @@ -18,7 +19,7 @@ class cmake; class cmGlobalVisualStudio12Generator : public cmGlobalVisualStudio11Generator { public: - static cmGlobalGeneratorFactory* NewFactory(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index cd48474..f549b6a 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -2,7 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGlobalVisualStudio14Generator.h" -#include "cmAlgorithms.h" +#include <cm/vector> + #include "cmDocumentationEntry.h" #include "cmLocalVisualStudio10Generator.h" #include "cmMakefile.h" @@ -28,27 +29,30 @@ class cmGlobalVisualStudio14Generator::Factory : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { std::string genName; const char* p = cmVS14GenName(name, genName); if (!p) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (!*p) { - return new cmGlobalVisualStudio14Generator(cm, genName, ""); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio14Generator(cm, genName, "")); } if (*p++ != ' ') { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (strcmp(p, "Win64") == 0) { - return new cmGlobalVisualStudio14Generator(cm, genName, "x64"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio14Generator(cm, genName, "x64")); } if (strcmp(p, "ARM") == 0) { - return new cmGlobalVisualStudio14Generator(cm, genName, "ARM"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio14Generator(cm, genName, "ARM")); } - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } void GetDocumentation(cmDocumentationEntry& entry) const override @@ -88,9 +92,10 @@ public: std::string GetDefaultPlatformName() const override { return "Win32"; } }; -cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory() +std::unique_ptr<cmGlobalGeneratorFactory> +cmGlobalVisualStudio14Generator::NewFactory() { - return new Factory; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory); } cmGlobalVisualStudio14Generator::cmGlobalVisualStudio14Generator( @@ -299,7 +304,7 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion() // Skip SDKs that do not contain <um/windows.h> because that indicates that // only the UCRT MSIs were installed for them. - cmEraseIf(sdks, NoWindowsH()); + cm::erase_if(sdks, NoWindowsH()); // Only use the filename, which will be the SDK version. for (std::string& i : sdks) { @@ -309,7 +314,7 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion() // Skip SDKs that cannot be used with our toolset. std::string maxVersion = this->GetWindows10SDKMaxVersion(); if (!maxVersion.empty()) { - cmEraseIf(sdks, WindowsSDKTooRecent(maxVersion)); + cm::erase_if(sdks, WindowsSDKTooRecent(maxVersion)); } // Sort the results to make sure we select the most recent one. diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index 6e12d3e..ccc2917 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <memory> #include <string> #include "cmGlobalVisualStudio12Generator.h" @@ -18,7 +19,7 @@ class cmake; class cmGlobalVisualStudio14Generator : public cmGlobalVisualStudio12Generator { public: - static cmGlobalGeneratorFactory* NewFactory(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx index 6e61d26..9f73c15 100644 --- a/Source/cmGlobalVisualStudio9Generator.cxx +++ b/Source/cmGlobalVisualStudio9Generator.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGlobalVisualStudio9Generator.h" +#include <utility> + #include "cmDocumentationEntry.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" @@ -13,43 +15,46 @@ static const char vs9generatorName[] = "Visual Studio 9 2008"; class cmGlobalVisualStudio9Generator::Factory : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { if (strncmp(name.c_str(), vs9generatorName, sizeof(vs9generatorName) - 1) != 0) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } const char* p = name.c_str() + sizeof(vs9generatorName) - 1; if (p[0] == '\0') { - return new cmGlobalVisualStudio9Generator(cm, name, ""); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio9Generator(cm, name, "")); } if (p[0] != ' ') { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } ++p; if (!strcmp(p, "IA64")) { - return new cmGlobalVisualStudio9Generator(cm, name, "Itanium"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio9Generator(cm, name, "Itanium")); } if (!strcmp(p, "Win64")) { - return new cmGlobalVisualStudio9Generator(cm, name, "x64"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudio9Generator(cm, name, "x64")); } cmVisualStudioWCEPlatformParser parser(p); parser.ParseVersion("9.0"); if (!parser.Found()) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } - cmGlobalVisualStudio9Generator* ret = - new cmGlobalVisualStudio9Generator(cm, name, p); + auto ret = std::unique_ptr<cmGlobalVisualStudio9Generator>( + new cmGlobalVisualStudio9Generator(cm, name, p)); ret->WindowsCEVersion = parser.GetOSVersion(); - return ret; + return std::unique_ptr<cmGlobalGenerator>(std::move(ret)); } void GetDocumentation(cmDocumentationEntry& entry) const override @@ -103,9 +108,10 @@ public: std::string GetDefaultPlatformName() const override { return "Win32"; } }; -cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory() +std::unique_ptr<cmGlobalGeneratorFactory> +cmGlobalVisualStudio9Generator::NewFactory() { - return new Factory; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory); } cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator( diff --git a/Source/cmGlobalVisualStudio9Generator.h b/Source/cmGlobalVisualStudio9Generator.h index 7bebfd6..53318a6 100644 --- a/Source/cmGlobalVisualStudio9Generator.h +++ b/Source/cmGlobalVisualStudio9Generator.h @@ -3,6 +3,8 @@ #ifndef cmGlobalVisualStudio9Generator_h #define cmGlobalVisualStudio9Generator_h +#include <memory> + #include "cmGlobalVisualStudio8Generator.h" /** \class cmGlobalVisualStudio9Generator @@ -13,7 +15,7 @@ class cmGlobalVisualStudio9Generator : public cmGlobalVisualStudio8Generator { public: - static cmGlobalGeneratorFactory* NewFactory(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory(); /** * Where does this version of Visual Studio look for macros for the diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index a371633..13ae32a 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -121,30 +121,33 @@ class cmGlobalVisualStudioVersionedGenerator::Factory15 : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { std::string genName; const char* p = cmVS15GenName(name, genName); if (!p) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (!*p) { - return new cmGlobalVisualStudioVersionedGenerator( - cmGlobalVisualStudioGenerator::VS15, cm, genName, ""); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS15, cm, genName, "")); } if (*p++ != ' ') { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (strcmp(p, "Win64") == 0) { - return new cmGlobalVisualStudioVersionedGenerator( - cmGlobalVisualStudioGenerator::VS15, cm, genName, "x64"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS15, cm, genName, "x64")); } if (strcmp(p, "ARM") == 0) { - return new cmGlobalVisualStudioVersionedGenerator( - cmGlobalVisualStudioGenerator::VS15, cm, genName, "ARM"); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS15, cm, genName, "ARM")); } - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } void GetDocumentation(cmDocumentationEntry& entry) const override @@ -185,10 +188,10 @@ public: std::string GetDefaultPlatformName() const override { return "Win32"; } }; -cmGlobalGeneratorFactory* +std::unique_ptr<cmGlobalGeneratorFactory> cmGlobalVisualStudioVersionedGenerator::NewFactory15() { - return new Factory15; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory15); } static const char vs16generatorName[] = "Visual Studio 16 2019"; @@ -212,19 +215,20 @@ class cmGlobalVisualStudioVersionedGenerator::Factory16 : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override { std::string genName; const char* p = cmVS16GenName(name, genName); if (!p) { - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } if (!*p) { - return new cmGlobalVisualStudioVersionedGenerator( - cmGlobalVisualStudioGenerator::VS16, cm, genName, ""); + return std::unique_ptr<cmGlobalGenerator>( + new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS16, cm, genName, "")); } - return 0; + return std::unique_ptr<cmGlobalGenerator>(); } void GetDocumentation(cmDocumentationEntry& entry) const override @@ -265,10 +269,10 @@ public: } }; -cmGlobalGeneratorFactory* +std::unique_ptr<cmGlobalGeneratorFactory> cmGlobalVisualStudioVersionedGenerator::NewFactory16() { - return new Factory16; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory16); } cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator( diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index 466816b..abb6095 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <memory> #include <string> #include "cmGlobalVisualStudio14Generator.h" @@ -19,8 +20,8 @@ class cmGlobalVisualStudioVersionedGenerator : public cmGlobalVisualStudio14Generator { public: - static cmGlobalGeneratorFactory* NewFactory15(); - static cmGlobalGeneratorFactory* NewFactory16(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory15(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory16(); bool MatchesGeneratorName(const std::string& name) const override; diff --git a/Source/cmGlobalWatcomWMakeGenerator.h b/Source/cmGlobalWatcomWMakeGenerator.h index 64ace13..c0daf8a 100644 --- a/Source/cmGlobalWatcomWMakeGenerator.h +++ b/Source/cmGlobalWatcomWMakeGenerator.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <memory> #include <string> #include <vector> @@ -25,9 +26,10 @@ class cmGlobalWatcomWMakeGenerator : public cmGlobalUnixMakefileGenerator3 { public: cmGlobalWatcomWMakeGenerator(cmake* cm); - static cmGlobalGeneratorFactory* NewFactory() + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory() { - return new cmGlobalGeneratorSimpleFactory<cmGlobalWatcomWMakeGenerator>(); + return std::unique_ptr<cmGlobalGeneratorFactory>( + new cmGlobalGeneratorSimpleFactory<cmGlobalWatcomWMakeGenerator>()); } //! Get the name for the generator. std::string GetName() const override diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index dcd9705..f887284 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -131,8 +131,8 @@ public: class cmGlobalXCodeGenerator::Factory : public cmGlobalGeneratorFactory { public: - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const override; + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name, cmake* cm) const override; void GetDocumentation(cmDocumentationEntry& entry) const override { @@ -181,16 +181,17 @@ cmGlobalXCodeGenerator::cmGlobalXCodeGenerator( cm->GetState()->SetIsGeneratorMultiConfig(true); } -cmGlobalGeneratorFactory* cmGlobalXCodeGenerator::NewFactory() +std::unique_ptr<cmGlobalGeneratorFactory> cmGlobalXCodeGenerator::NewFactory() { - return new Factory; + return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory); } -cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( - const std::string& name, cmake* cm) const +std::unique_ptr<cmGlobalGenerator> +cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator(const std::string& name, + cmake* cm) const { if (name != GetActualName()) { - return nullptr; + return std::unique_ptr<cmGlobalGenerator>(); } #if !defined(CMAKE_BOOTSTRAP) cmXcodeVersionParser parser; @@ -226,16 +227,17 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( if (version_number < 50) { cm->IssueMessage(MessageType::FATAL_ERROR, "Xcode " + version_string + " not supported."); - return nullptr; + return std::unique_ptr<cmGlobalGenerator>(); } - auto gg = cm::make_unique<cmGlobalXCodeGenerator>(cm, version_string, - version_number); - return gg.release(); + return std::unique_ptr<cmGlobalGenerator>( + cm::make_unique<cmGlobalXCodeGenerator>(cm, version_string, + version_number)); #else std::cerr << "CMake should be built with cmake to use Xcode, " "default to Xcode 1.5\n"; - return new cmGlobalXCodeGenerator(cm); + return std::unique_ptr<cmGlobalGenerator>( + cm::make_unique<cmGlobalXCodeGenerator>(cm)); #endif } @@ -2355,9 +2357,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, buildSettings->AddAttribute("SECTORDER_FLAGS", this->CreateString("")); buildSettings->AddAttribute("USE_HEADERMAP", this->CreateString("NO")); cmXCodeObject* group = this->CreateObject(cmXCodeObject::OBJECT_LIST); - group->AddObject(this->CreateString("-Wmost")); - group->AddObject(this->CreateString("-Wno-four-char-constants")); - group->AddObject(this->CreateString("-Wno-unknown-pragmas")); group->AddObject(this->CreateString("$(inherited)")); buildSettings->AddAttribute("WARNING_CFLAGS", group); diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index a12021d..df68f80 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -35,7 +35,7 @@ class cmGlobalXCodeGenerator : public cmGlobalGenerator public: cmGlobalXCodeGenerator(cmake* cm, std::string const& version_string, unsigned int version_number); - static cmGlobalGeneratorFactory* NewFactory(); + static std::unique_ptr<cmGlobalGeneratorFactory> NewFactory(); //! Get the name for the generator. std::string GetName() const override diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 0c52cc5..54b85cd 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -85,7 +85,7 @@ public: std::string DefaultComponentName; }; -cmInstallTargetGenerator* CreateInstallTargetGenerator( +std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator( cmTarget& target, const cmInstallCommandArguments& args, bool impLib, cmListFileBacktrace const& backtrace, const std::string& destination, bool forceOpt = false, bool namelink = false) @@ -95,16 +95,16 @@ cmInstallTargetGenerator* CreateInstallTargetGenerator( target.SetHaveInstallRule(true); const char* component = namelink ? args.GetNamelinkComponent().c_str() : args.GetComponent().c_str(); - auto g = new cmInstallTargetGenerator( + auto g = cm::make_unique<cmInstallTargetGenerator>( target.GetName(), destination.c_str(), impLib, args.GetPermissions().c_str(), args.GetConfigurations(), component, message, args.GetExcludeFromAll(), args.GetOptional() || forceOpt, backtrace); - target.AddInstallGenerator(g); + target.AddInstallGenerator(g.get()); return g; } -cmInstallTargetGenerator* CreateInstallTargetGenerator( +std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator( cmTarget& target, const cmInstallCommandArguments& args, bool impLib, cmListFileBacktrace const& backtrace, bool forceOpt = false, bool namelink = false) @@ -114,20 +114,20 @@ cmInstallTargetGenerator* CreateInstallTargetGenerator( namelink); } -cmInstallFilesGenerator* CreateInstallFilesGenerator( +std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator( cmMakefile* mf, const std::vector<std::string>& absFiles, const cmInstallCommandArguments& args, bool programs, const std::string& destination) { cmInstallGenerator::MessageLevel message = cmInstallGenerator::SelectMessageLevel(mf); - return new cmInstallFilesGenerator( + return cm::make_unique<cmInstallFilesGenerator>( absFiles, destination.c_str(), programs, args.GetPermissions().c_str(), args.GetConfigurations(), args.GetComponent().c_str(), message, args.GetExcludeFromAll(), args.GetRename().c_str(), args.GetOptional()); } -cmInstallFilesGenerator* CreateInstallFilesGenerator( +std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator( cmMakefile* mf, const std::vector<std::string>& absFiles, const cmInstallCommandArguments& args, bool programs) { @@ -196,13 +196,15 @@ bool HandleScriptMode(std::vector<std::string> const& args, status.SetError("given a directory as value of SCRIPT argument."); return false; } - helper.Makefile->AddInstallGenerator(new cmInstallScriptGenerator( - script.c_str(), false, component.c_str(), exclude_from_all)); + helper.Makefile->AddInstallGenerator( + cm::make_unique<cmInstallScriptGenerator>( + script.c_str(), false, component.c_str(), exclude_from_all)); } else if (doing_code) { doing_code = false; std::string const& code = arg; - helper.Makefile->AddInstallGenerator(new cmInstallScriptGenerator( - code.c_str(), true, component.c_str(), exclude_from_all)); + helper.Makefile->AddInstallGenerator( + cm::make_unique<cmInstallScriptGenerator>( + code.c_str(), true, component.c_str(), exclude_from_all)); } } @@ -449,16 +451,16 @@ bool HandleTargetsMode(std::vector<std::string> const& args, for (cmTarget* ti : targets) { // Handle each target type. cmTarget& target = *ti; - cmInstallTargetGenerator* archiveGenerator = nullptr; - cmInstallTargetGenerator* libraryGenerator = nullptr; - cmInstallTargetGenerator* namelinkGenerator = nullptr; - cmInstallTargetGenerator* runtimeGenerator = nullptr; - cmInstallTargetGenerator* objectGenerator = nullptr; - cmInstallTargetGenerator* frameworkGenerator = nullptr; - cmInstallTargetGenerator* bundleGenerator = nullptr; - cmInstallFilesGenerator* privateHeaderGenerator = nullptr; - cmInstallFilesGenerator* publicHeaderGenerator = nullptr; - cmInstallFilesGenerator* resourceGenerator = nullptr; + std::unique_ptr<cmInstallTargetGenerator> archiveGenerator; + std::unique_ptr<cmInstallTargetGenerator> libraryGenerator; + std::unique_ptr<cmInstallTargetGenerator> namelinkGenerator; + std::unique_ptr<cmInstallTargetGenerator> runtimeGenerator; + std::unique_ptr<cmInstallTargetGenerator> objectGenerator; + std::unique_ptr<cmInstallTargetGenerator> frameworkGenerator; + std::unique_ptr<cmInstallTargetGenerator> bundleGenerator; + std::unique_ptr<cmInstallFilesGenerator> privateHeaderGenerator; + std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator; + std::unique_ptr<cmInstallFilesGenerator> resourceGenerator; // Track whether this is a namelink-only rule. bool namelinkOnly = false; @@ -485,7 +487,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args, runtimeGenerator = CreateInstallTargetGenerator( target, runtimeArgs, false, helper.Makefile->GetBacktrace()); } - if ((archiveGenerator == nullptr) && (runtimeGenerator == nullptr)) { + if (!archiveGenerator && !runtimeGenerator) { archiveGenerator = CreateInstallTargetGenerator( target, archiveArgs, true, helper.Makefile->GetBacktrace(), helper.GetArchiveDestination(nullptr)); @@ -712,43 +714,18 @@ bool HandleTargetsMode(std::vector<std::string> const& args, } } - // Keep track of whether we're installing anything in each category - installsArchive = installsArchive || archiveGenerator != nullptr; - installsLibrary = installsLibrary || libraryGenerator != nullptr; - installsNamelink = installsNamelink || namelinkGenerator != nullptr; - installsRuntime = installsRuntime || runtimeGenerator != nullptr; - installsObject = installsObject || objectGenerator != nullptr; - installsFramework = installsFramework || frameworkGenerator != nullptr; - installsBundle = installsBundle || bundleGenerator != nullptr; - installsPrivateHeader = - installsPrivateHeader || privateHeaderGenerator != nullptr; - installsPublicHeader = - installsPublicHeader || publicHeaderGenerator != nullptr; - installsResource = installsResource || resourceGenerator; - - helper.Makefile->AddInstallGenerator(archiveGenerator); - helper.Makefile->AddInstallGenerator(libraryGenerator); - helper.Makefile->AddInstallGenerator(namelinkGenerator); - helper.Makefile->AddInstallGenerator(runtimeGenerator); - helper.Makefile->AddInstallGenerator(objectGenerator); - helper.Makefile->AddInstallGenerator(frameworkGenerator); - helper.Makefile->AddInstallGenerator(bundleGenerator); - helper.Makefile->AddInstallGenerator(privateHeaderGenerator); - helper.Makefile->AddInstallGenerator(publicHeaderGenerator); - helper.Makefile->AddInstallGenerator(resourceGenerator); - // Add this install rule to an export if one was specified and // this is not a namelink-only rule. if (!exports.empty() && !namelinkOnly) { auto te = cm::make_unique<cmTargetExport>(); te->TargetName = target.GetName(); - te->ArchiveGenerator = archiveGenerator; - te->BundleGenerator = bundleGenerator; - te->FrameworkGenerator = frameworkGenerator; - te->HeaderGenerator = publicHeaderGenerator; - te->LibraryGenerator = libraryGenerator; - te->RuntimeGenerator = runtimeGenerator; - te->ObjectsGenerator = objectGenerator; + te->ArchiveGenerator = archiveGenerator.get(); + te->BundleGenerator = bundleGenerator.get(); + te->FrameworkGenerator = frameworkGenerator.get(); + te->HeaderGenerator = publicHeaderGenerator.get(); + te->LibraryGenerator = libraryGenerator.get(); + te->RuntimeGenerator = runtimeGenerator.get(); + te->ObjectsGenerator = objectGenerator.get(); te->InterfaceIncludeDirectories = cmJoin(includesArgs.GetIncludeDirs(), ";"); @@ -756,6 +733,29 @@ bool HandleTargetsMode(std::vector<std::string> const& args, ->GetExportSets()[exports] .AddTargetExport(std::move(te)); } + + // Keep track of whether we're installing anything in each category + installsArchive = installsArchive || archiveGenerator; + installsLibrary = installsLibrary || libraryGenerator; + installsNamelink = installsNamelink || namelinkGenerator; + installsRuntime = installsRuntime || runtimeGenerator; + installsObject = installsObject || objectGenerator; + installsFramework = installsFramework || frameworkGenerator; + installsBundle = installsBundle || bundleGenerator; + installsPrivateHeader = installsPrivateHeader || privateHeaderGenerator; + installsPublicHeader = installsPublicHeader || publicHeaderGenerator; + installsResource = installsResource || resourceGenerator; + + helper.Makefile->AddInstallGenerator(std::move(archiveGenerator)); + helper.Makefile->AddInstallGenerator(std::move(libraryGenerator)); + helper.Makefile->AddInstallGenerator(std::move(namelinkGenerator)); + helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator)); + helper.Makefile->AddInstallGenerator(std::move(objectGenerator)); + helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator)); + helper.Makefile->AddInstallGenerator(std::move(bundleGenerator)); + helper.Makefile->AddInstallGenerator(std::move(privateHeaderGenerator)); + helper.Makefile->AddInstallGenerator(std::move(publicHeaderGenerator)); + helper.Makefile->AddInstallGenerator(std::move(resourceGenerator)); } // Tell the global generator about any installation component names @@ -1200,10 +1200,11 @@ bool HandleDirectoryMode(std::vector<std::string> const& args, cmInstallGenerator::SelectMessageLevel(helper.Makefile, message_never); // Create the directory install generator. - helper.Makefile->AddInstallGenerator(new cmInstallDirectoryGenerator( - dirs, destination, permissions_file.c_str(), permissions_dir.c_str(), - configurations, component.c_str(), message, exclude_from_all, - literal_args.c_str(), optional)); + helper.Makefile->AddInstallGenerator( + cm::make_unique<cmInstallDirectoryGenerator>( + dirs, destination, permissions_file.c_str(), permissions_dir.c_str(), + configurations, component.c_str(), message, exclude_from_all, + literal_args.c_str(), optional)); // Tell the global generator about any installation component names // specified. @@ -1291,12 +1292,12 @@ bool HandleExportAndroidMKMode(std::vector<std::string> const& args, cmInstallGenerator::SelectMessageLevel(helper.Makefile); // Create the export install generator. - cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator( - &exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), - ica.GetConfigurations(), ica.GetComponent().c_str(), message, - ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, - true); - helper.Makefile->AddInstallGenerator(exportGenerator); + helper.Makefile->AddInstallGenerator( + cm::make_unique<cmInstallExportGenerator>( + &exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), + ica.GetConfigurations(), ica.GetComponent().c_str(), message, + ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, + true)); return true; #else @@ -1405,12 +1406,12 @@ bool HandleExportMode(std::vector<std::string> const& args, cmInstallGenerator::SelectMessageLevel(helper.Makefile); // Create the export install generator. - cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator( - &exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), - ica.GetConfigurations(), ica.GetComponent().c_str(), message, - ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, - false); - helper.Makefile->AddInstallGenerator(exportGenerator); + helper.Makefile->AddInstallGenerator( + cm::make_unique<cmInstallExportGenerator>( + &exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), + ica.GetConfigurations(), ica.GetComponent().c_str(), message, + ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld, + false)); return true; } diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index efbcb98..bfc7359 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallFilesCommand.h" +#include <cm/memory> + #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" @@ -121,7 +123,7 @@ static void CreateInstallGenerator(cmMakefile& makefile, std::vector<std::string> no_configurations; cmInstallGenerator::MessageLevel message = cmInstallGenerator::SelectMessageLevel(&makefile); - makefile.AddInstallGenerator(new cmInstallFilesGenerator( + makefile.AddInstallGenerator(cm::make_unique<cmInstallFilesGenerator>( files, destination.c_str(), false, no_permissions, no_configurations, no_component.c_str(), message, no_exclude_from_all, no_rename)); } diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx index 2088eae..2fd9bad 100644 --- a/Source/cmInstallProgramsCommand.cxx +++ b/Source/cmInstallProgramsCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallProgramsCommand.h" +#include <cm/memory> + #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" @@ -95,7 +97,7 @@ static void FinalAction(cmMakefile& makefile, std::string const& dest, std::vector<std::string> no_configurations; cmInstallGenerator::MessageLevel message = cmInstallGenerator::SelectMessageLevel(&makefile); - makefile.AddInstallGenerator(new cmInstallFilesGenerator( + makefile.AddInstallGenerator(cm::make_unique<cmInstallFilesGenerator>( files, destination.c_str(), true, no_permissions, no_configurations, no_component.c_str(), message, no_exclude_from_all, no_rename)); } diff --git a/Source/cmInstallSubdirectoryGenerator.cxx b/Source/cmInstallSubdirectoryGenerator.cxx index 8a0fefa..5405b7c 100644 --- a/Source/cmInstallSubdirectoryGenerator.cxx +++ b/Source/cmInstallSubdirectoryGenerator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallSubdirectoryGenerator.h" +#include <memory> #include <sstream> #include <vector> @@ -24,7 +25,7 @@ cmInstallSubdirectoryGenerator::~cmInstallSubdirectoryGenerator() = default; bool cmInstallSubdirectoryGenerator::HaveInstall() { - for (auto generator : this->Makefile->GetInstallGenerators()) { + for (const auto& generator : this->Makefile->GetInstallGenerators()) { if (generator->HaveInstall()) { return true; } diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index 5f86d85..dd36386 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -8,6 +8,7 @@ #include <functional> #include <limits> #include <map> +#include <memory> #include <set> #include <string> #include <unordered_map> @@ -44,7 +45,7 @@ namespace { std::vector<std::string> getConfigurations(const cmake* cm) { std::vector<std::string> configurations; - auto makefiles = cm->GetGlobalGenerator()->GetMakefiles(); + const auto& makefiles = cm->GetGlobalGenerator()->GetMakefiles(); if (makefiles.empty()) { return configurations; } @@ -83,8 +84,8 @@ void cmGetCMakeInputs(const cmGlobalGenerator* gg, std::vector<std::string>* tmpFiles) { const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot() + '/'; - std::vector<cmMakefile*> const& makefiles = gg->GetMakefiles(); - for (cmMakefile const* mf : makefiles) { + auto const& makefiles = gg->GetMakefiles(); + for (const auto& mf : makefiles) { for (std::string const& lf : mf->GetListFiles()) { const std::string startOfFile = lf.substr(0, cmakeRootDir.size()); @@ -486,10 +487,10 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, result[kHAS_INSTALL_RULE] = true; Json::Value installPaths = Json::arrayValue; - auto targetGenerators = target->Makefile->GetInstallGenerators(); - for (auto installGenerator : targetGenerators) { + for (const auto& installGenerator : + target->Makefile->GetInstallGenerators()) { auto installTargetGenerator = - dynamic_cast<cmInstallTargetGenerator*>(installGenerator); + dynamic_cast<cmInstallTargetGenerator*>(installGenerator.get()); if (installTargetGenerator != nullptr && installTargetGenerator->GetTarget()->Target == target->Target) { auto dest = installTargetGenerator->GetDestination(config); @@ -642,9 +643,9 @@ static Json::Value DumpProjectList(const cmake* cm, std::string const& config) // associated generators. bool hasInstallRule = false; for (const auto generator : projectIt.second) { - for (const auto installGen : + for (const auto& installGen : generator->GetMakefile()->GetInstallGenerators()) { - if (!dynamic_cast<cmInstallSubdirectoryGenerator*>(installGen)) { + if (!dynamic_cast<cmInstallSubdirectoryGenerator*>(installGen.get())) { hasInstallRule = true; break; } diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx index d845652..847334b 100644 --- a/Source/cmLinkLineDeviceComputer.cxx +++ b/Source/cmLinkLineDeviceComputer.cxx @@ -183,29 +183,29 @@ bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg, return cmIsOn(resolveDeviceSymbols); } - if (const char* separableCompilation = - target.GetProperty("CUDA_SEPARABLE_COMPILATION")) { - if (cmIsOn(separableCompilation)) { - bool doDeviceLinking = false; - switch (target.GetType()) { - case cmStateEnums::SHARED_LIBRARY: - case cmStateEnums::MODULE_LIBRARY: - case cmStateEnums::EXECUTABLE: - doDeviceLinking = true; - break; - default: - break; - } - return doDeviceLinking; - } - } - // Determine if we have any dependencies that require // us to do a device link step cmGeneratorTarget::LinkClosure const* closure = target.GetLinkClosure(config); if (cmContains(closure->Languages, "CUDA")) { + if (const char* separableCompilation = + target.GetProperty("CUDA_SEPARABLE_COMPILATION")) { + if (cmIsOn(separableCompilation)) { + bool doDeviceLinking = false; + switch (target.GetType()) { + case cmStateEnums::SHARED_LIBRARY: + case cmStateEnums::MODULE_LIBRARY: + case cmStateEnums::EXECUTABLE: + doDeviceLinking = true; + break; + default: + break; + } + return doDeviceLinking; + } + } + cmComputeLinkInformation* pcli = target.GetLinkInformation(config); if (pcli) { cmLinkLineDeviceComputer deviceLinkComputer( diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 5e39d9b..cedc3ad 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -315,9 +315,7 @@ void cmLocalGenerator::GenerateTestFiles() } // Ask each test generator to write its code. - std::vector<cmTestGenerator*> const& testers = - this->Makefile->GetTestGenerators(); - for (cmTestGenerator* tester : testers) { + for (const auto& tester : this->Makefile->GetTestGenerators()) { tester->Compute(this); tester->Generate(fout, config, configurationTypes); } @@ -363,9 +361,7 @@ void cmLocalGenerator::CreateEvaluationFileOutputs() void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config) { - std::vector<cmGeneratorExpressionEvaluationFile*> ef = - this->Makefile->GetEvaluationFiles(); - for (cmGeneratorExpressionEvaluationFile* geef : ef) { + for (const auto& geef : this->Makefile->GetEvaluationFiles()) { geef->CreateOutputFile(this, config); } } @@ -373,8 +369,7 @@ void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config) void cmLocalGenerator::ProcessEvaluationFiles( std::vector<std::string>& generatedFiles) { - for (cmGeneratorExpressionEvaluationFile* geef : - this->Makefile->GetEvaluationFiles()) { + for (const auto& geef : this->Makefile->GetEvaluationFiles()) { geef->Generate(this); if (cmSystemTools::GetFatalErrorOccured()) { return; @@ -557,18 +552,17 @@ void cmLocalGenerator::GenerateInstallRules() // Ask each install generator to write its code. cmPolicies::PolicyStatus status = this->GetPolicyStatus(cmPolicies::CMP0082); - std::vector<cmInstallGenerator*> const& installers = - this->Makefile->GetInstallGenerators(); + auto const& installers = this->Makefile->GetInstallGenerators(); bool haveSubdirectoryInstall = false; bool haveInstallAfterSubdirectory = false; if (status == cmPolicies::WARN) { - for (cmInstallGenerator* installer : installers) { + for (const auto& installer : installers) { installer->CheckCMP0082(haveSubdirectoryInstall, haveInstallAfterSubdirectory); installer->Generate(fout, config, configurationTypes); } } else { - for (cmInstallGenerator* installer : installers) { + for (const auto& installer : installers) { installer->Generate(fout, config, configurationTypes); } } @@ -2009,8 +2003,16 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName, // Treat the name as relative to the source directory in which it // was given. - dep = cmStrCat(this->StateSnapshot.GetDirectory().GetCurrentSource(), '/', - inName); + dep = cmStrCat(this->GetCurrentSourceDirectory(), '/', inName); + + // If the in-source path does not exist, assume it instead lives in the + // binary directory. + if (!cmSystemTools::FileExists(dep)) { + dep = cmStrCat(this->GetCurrentBinaryDirectory(), '/', inName); + } + + dep = cmSystemTools::CollapseFullPath(dep, this->GetBinaryDirectory()); + return true; } @@ -2220,10 +2222,11 @@ static void AddVisibilityCompileOption(std::string& flags, static void AddInlineVisibilityCompileOption(std::string& flags, cmGeneratorTarget const* target, cmLocalGenerator* lg, - std::string* warnCMP0063) + std::string* warnCMP0063, + const std::string& lang) { std::string compileOption = - "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN"; + cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN"); const char* opt = lg->GetMakefile()->GetDefinition(compileOption); if (!opt) { return; @@ -2265,8 +2268,8 @@ void cmLocalGenerator::AddVisibilityPresetFlags( AddVisibilityCompileOption(flags, target, this, lang, pWarnCMP0063); - if (lang == "CXX") { - AddInlineVisibilityCompileOption(flags, target, this, pWarnCMP0063); + if (lang == "CXX" || lang == "OBJCXX") { + AddInlineVisibilityCompileOption(flags, target, this, pWarnCMP0063, lang); } if (!warnCMP0063.empty() && this->WarnCMP0063.insert(target).second) { @@ -2632,7 +2635,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) chunk = std::min(itemsLeft, batchSize); std::string filename = cmStrCat(filename_base, "unity_", batch, - (lang == "C") ? ".c" : ".cxx"); + (lang == "C") ? "_c.c" : "_cxx.cxx"); const std::string filename_tmp = cmStrCat(filename, ".tmp"); { @@ -3281,7 +3284,8 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget( // CMakeFiles/<target>.dir/CMakeFiles/<target>.dir/generated_source_file.obj const char* unitySourceFile = source.GetProperty("UNITY_SOURCE_FILE"); const char* pchExtension = source.GetProperty("PCH_EXTENSION"); - if (unitySourceFile || pchExtension) { + const bool isPchObject = objectName.find("cmake_pch") != std::string::npos; + if (unitySourceFile || pchExtension || isPchObject) { if (pchExtension) { customOutputExtension = pchExtension; } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index f6a0e34..dbdde48 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -9,12 +9,12 @@ #include <utility> #include <cm/memory> +#include <cm/vector> #include <cmext/algorithm> #include "cmsys/FStream.hxx" #include "cmsys/Terminal.h" -#include "cmAlgorithms.h" #include "cmCustomCommand.h" // IWYU pragma: keep #include "cmCustomCommandGenerator.h" #include "cmFileTimeCache.h" @@ -1876,7 +1876,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo( std::string binaryDir = this->GetState()->GetBinaryDirectory(); if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) { std::string const& sourceDir = this->GetState()->GetSourceDirectory(); - cmEraseIf(includes, ::NotInProjectDir(sourceDir, binaryDir)); + cm::erase_if(includes, ::NotInProjectDir(sourceDir, binaryDir)); } for (std::string const& include : includes) { cmakefileStream << " \"" diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 7683855..55a9a72 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -530,6 +530,14 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] = { "linkIncrementalNo", 0 }, { "LinkIncremental", "INCREMENTAL:YES", "link incremental", "linkIncrementalYes", 0 }, + { "EnableCOMDATFolding", "OPT:NOICF", "Do not remove redundant COMDATs", + "optNoFolding", 0 }, + { "EnableCOMDATFolding", "OPT:ICF", "Remove redundant COMDATs", "optFolding", + 0 }, + { "OptimizeReferences", "OPT:NOREF", "Keep unreferenced data", + "optNoReferences", 0 }, + { "OptimizeReferences", "OPT:REF", "Eliminate unreferenced data", + "optReferences", 0 }, { "", "", "", "", 0 } }; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 13a6ed7..dc741d3 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -15,7 +15,9 @@ #include <utility> #include <cm/iterator> +#include <cm/memory> #include <cm/optional> +#include <cm/vector> #include <cmext/algorithm> #include "cmsys/FStream.hxx" @@ -122,15 +124,7 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, #endif } -cmMakefile::~cmMakefile() -{ - cmDeleteAll(this->InstallGenerators); - cmDeleteAll(this->TestGenerators); - cmDeleteAll(this->SourceFiles); - cmDeleteAll(this->Tests); - cmDeleteAll(this->ImportedTargetsOwned); - cmDeleteAll(this->EvaluationFiles); -} +cmMakefile::~cmMakefile() = default; cmDirectoryId cmMakefile::GetDirectoryId() const { @@ -138,7 +132,7 @@ cmDirectoryId cmMakefile::GetDirectoryId() const // If we ever need to expose this to CMake language code we should // add a read-only property in cmMakefile::GetProperty. char buf[32]; - sprintf(buf, "<%p>", + sprintf(buf, "(%p)", static_cast<void const*>(this)); // cast avoids format warning return std::string(buf); } @@ -772,12 +766,13 @@ void cmMakefile::AddEvaluationFile( std::unique_ptr<cmCompiledGeneratorExpression> condition, bool inputIsContent) { - this->EvaluationFiles.push_back(new cmGeneratorExpressionEvaluationFile( - inputFile, std::move(outputName), std::move(condition), inputIsContent, - this->GetPolicyStatus(cmPolicies::CMP0070))); + this->EvaluationFiles.push_back( + cm::make_unique<cmGeneratorExpressionEvaluationFile>( + inputFile, std::move(outputName), std::move(condition), inputIsContent, + this->GetPolicyStatus(cmPolicies::CMP0070))); } -std::vector<cmGeneratorExpressionEvaluationFile*> +const std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>>& cmMakefile::GetEvaluationFiles() const { return this->EvaluationFiles; @@ -839,12 +834,12 @@ void cmMakefile::DoGenerate(cmLocalGenerator& lg) // we don't want cmake to re-run if a configured file is created and deleted // during processing as that would make it a transient file that can't // influence the build process - cmEraseIf(this->OutputFiles, file_not_persistent()); + cm::erase_if(this->OutputFiles, file_not_persistent()); // if a configured file is used as input for another configured file, // and then deleted it will show up in the input list files so we // need to scan those too - cmEraseIf(this->ListFiles, file_not_persistent()); + cm::erase_if(this->ListFiles, file_not_persistent()); } // Generate the output file @@ -1423,6 +1418,20 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) this->RecursionDepth = parent->RecursionDepth; } +void cmMakefile::AddInstallGenerator(std::unique_ptr<cmInstallGenerator> g) +{ + if (g) { + this->InstallGenerators.push_back(std::move(g)); + } +} + +void cmMakefile::AddTestGenerator(std::unique_ptr<cmTestGenerator> g) +{ + if (g) { + this->TestGenerators.push_back(std::move(g)); + } +} + void cmMakefile::PushFunctionScope(std::string const& fileName, const cmPolicies::PolicyMap& pm) { @@ -1723,8 +1732,10 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath, cmSystemTools::MakeDirectory(binPath); - cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot); - this->GetGlobalGenerator()->AddMakefile(subMf); + auto subMfu = + cm::make_unique<cmMakefile>(this->GlobalGenerator, newSnapshot); + auto subMf = subMfu.get(); + this->GetGlobalGenerator()->AddMakefile(std::move(subMfu)); if (excludeFromAll) { subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); @@ -1736,7 +1747,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath, this->UnConfiguredDirectories.push_back(subMf); } - this->AddInstallGenerator(new cmInstallSubdirectoryGenerator( + this->AddInstallGenerator(cm::make_unique<cmInstallSubdirectoryGenerator>( subMf, binPath.c_str(), excludeFromAll)); } @@ -2100,18 +2111,18 @@ cmSourceFile* cmMakefile::LinearGetSourceFileWithOutput( // Look through all the source files that have custom commands and see if the // custom command has the passed source file as an output. - for (cmSourceFile* src : this->SourceFiles) { + for (const auto& src : this->SourceFiles) { // Does this source file have a custom command? if (src->GetCustomCommand()) { // Does the output of the custom command match the source file name? if (AnyOutputMatches(name, src->GetCustomCommand()->GetOutputs())) { // Return the first matching output. - return src; + return src.get(); } if (kind == cmSourceOutputKind::OutputOrByproduct) { if (AnyOutputMatches(name, src->GetCustomCommand()->GetByproducts())) { // Do not return the source yet as there might be a matching output. - fallback = src; + fallback = src.get(); } } } @@ -3469,24 +3480,25 @@ cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName, bool generated, cmSourceFileLocationKind kind) { - cmSourceFile* sf = new cmSourceFile(this, sourceName, kind); + auto sf = cm::make_unique<cmSourceFile>(this, sourceName, kind); if (generated) { sf->SetProperty("GENERATED", "1"); } - this->SourceFiles.push_back(sf); auto name = this->GetCMakeInstance()->StripExtension(sf->GetLocation().GetName()); #if defined(_WIN32) || defined(__APPLE__) name = cmSystemTools::LowerCase(name); #endif - this->SourceFileSearchIndex[name].push_back(sf); + this->SourceFileSearchIndex[name].push_back(sf.get()); // for "Known" paths add direct lookup (used for faster lookup in GetSource) if (kind == cmSourceFileLocationKind::Known) { - this->KnownFileSearchIndex[sourceName] = sf; + this->KnownFileSearchIndex[sourceName] = sf.get(); } - return sf; + this->SourceFiles.push_back(std::move(sf)); + + return this->SourceFiles.back().get(); } cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName, @@ -3615,8 +3627,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, // be run that way but the cmake object requires a vailid path cmake cm(cmake::RoleProject, cmState::Project); cm.SetIsInTryCompile(true); - cmGlobalGenerator* gg = - cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName()); + auto gg = cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName()); if (!gg) { this->IssueMessage(MessageType::INTERNAL_ERROR, "Global generator '" + @@ -3627,7 +3638,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, return 1; } gg->RecursionDepth = this->RecursionDepth; - cm.SetGlobalGenerator(gg); + cm.SetGlobalGenerator(std::move(gg)); // do a configure cm.SetHomeDirectory(srcdir); @@ -3636,7 +3647,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, cm.SetGeneratorPlatform(this->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM")); cm.SetGeneratorToolset(this->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET")); cm.LoadCache(); - if (!gg->IsMultiConfig()) { + if (!cm.GetGlobalGenerator()->IsMultiConfig()) { if (const char* config = this->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION")) { // Tell the single-configuration generator which one to use. @@ -3682,7 +3693,8 @@ int cmMakefile::TryCompile(const std::string& srcdir, cm.SetCacheArgs(*cmakeArgs); } // to save time we pass the EnableLanguage info directly - gg->EnableLanguagesFromGenerator(this->GetGlobalGenerator(), this); + cm.GetGlobalGenerator()->EnableLanguagesFromGenerator( + this->GetGlobalGenerator(), this); if (this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) { cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE", "", cmStateEnums::INTERNAL); @@ -4080,9 +4092,10 @@ cmTest* cmMakefile::CreateTest(const std::string& testName) if (test) { return test; } - test = new cmTest(this); - test->SetName(testName); - this->Tests[testName] = test; + auto newTest = cm::make_unique<cmTest>(this); + test = newTest.get(); + newTest->SetName(testName); + this->Tests[testName] = std::move(newTest); return test; } @@ -4090,7 +4103,7 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const { auto mi = this->Tests.find(testName); if (mi != this->Tests.end()) { - return mi->second; + return mi->second.get(); } return nullptr; } @@ -4098,7 +4111,7 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const void cmMakefile::GetTests(const std::string& config, std::vector<cmTest*>& tests) { - for (auto generator : this->GetTestGenerators()) { + for (const auto& generator : this->GetTestGenerators()) { if (generator->TestsForConfig(config)) { tests.push_back(generator->GetTest()); } @@ -4211,8 +4224,8 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name, this->GetGlobalGenerator()->IndexTarget(target.get()); // Transfer ownership to this cmMakefile object. - this->ImportedTargetsOwned.push_back(target.get()); - return target.release(); + this->ImportedTargetsOwned.push_back(std::move(target)); + return this->ImportedTargetsOwned.back().get(); } cmTarget* cmMakefile::FindTargetToUse(const std::string& name, diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 085c1d6..b13716b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -431,7 +431,7 @@ public: /** Get the target map - const version */ cmTargetMap const& GetTargets() const { return this->Targets; } - const std::vector<cmTarget*>& GetOwnedImportedTargets() const + const std::vector<std::unique_ptr<cmTarget>>& GetOwnedImportedTargets() const { return this->ImportedTargetsOwned; } @@ -727,7 +727,7 @@ public: /** * Get all the source files this makefile knows about */ - const std::vector<cmSourceFile*>& GetSourceFiles() const + const std::vector<std::unique_ptr<cmSourceFile>>& GetSourceFiles() const { return this->SourceFiles; } @@ -794,28 +794,22 @@ public: //! Initialize a makefile from its parent void InitializeFromParent(cmMakefile* parent); - void AddInstallGenerator(cmInstallGenerator* g) - { - if (g) { - this->InstallGenerators.push_back(g); - } - } - std::vector<cmInstallGenerator*>& GetInstallGenerators() + void AddInstallGenerator(std::unique_ptr<cmInstallGenerator> g); + + std::vector<std::unique_ptr<cmInstallGenerator>>& GetInstallGenerators() { return this->InstallGenerators; } - const std::vector<cmInstallGenerator*>& GetInstallGenerators() const + const std::vector<std::unique_ptr<cmInstallGenerator>>& + GetInstallGenerators() const { return this->InstallGenerators; } - void AddTestGenerator(cmTestGenerator* g) - { - if (g) { - this->TestGenerators.push_back(g); - } - } - const std::vector<cmTestGenerator*>& GetTestGenerators() const + void AddTestGenerator(std::unique_ptr<cmTestGenerator> g); + + const std::vector<std::unique_ptr<cmTestGenerator>>& GetTestGenerators() + const { return this->TestGenerators; } @@ -948,7 +942,8 @@ public: std::unique_ptr<cmCompiledGeneratorExpression> outputName, std::unique_ptr<cmCompiledGeneratorExpression> condition, bool inputIsContent); - std::vector<cmGeneratorExpressionEvaluationFile*> GetEvaluationFiles() const; + const std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>>& + GetEvaluationFiles() const; std::vector<cmExportBuildFileGenerator*> GetExportBuildFileGenerators() const; @@ -983,8 +978,7 @@ protected: using TargetsVec = std::vector<cmTarget*>; TargetsVec OrderedTargets; - using SourceFileVec = std::vector<cmSourceFile*>; - SourceFileVec SourceFiles; + std::vector<std::unique_ptr<cmSourceFile>> SourceFiles; // Because cmSourceFile names are compared in a fuzzy way (see // cmSourceFileLocation::Match()) we can't have a straight mapping from @@ -992,14 +986,15 @@ protected: // Name portion of the cmSourceFileLocation and then compare on the list of // cmSourceFiles that might match that name. Note that on platforms which // have a case-insensitive filesystem we store the key in all lowercase. - using SourceFileMap = std::unordered_map<std::string, SourceFileVec>; + using SourceFileMap = + std::unordered_map<std::string, std::vector<cmSourceFile*>>; SourceFileMap SourceFileSearchIndex; // For "Known" paths we can store a direct filename to cmSourceFile map std::unordered_map<std::string, cmSourceFile*> KnownFileSearchIndex; // Tests - std::map<std::string, cmTest*> Tests; + std::map<std::string, std::unique_ptr<cmTest>> Tests; // The set of include directories that are marked as system include // directories. @@ -1008,8 +1003,8 @@ protected: std::vector<std::string> ListFiles; std::vector<std::string> OutputFiles; - std::vector<cmInstallGenerator*> InstallGenerators; - std::vector<cmTestGenerator*> TestGenerators; + std::vector<std::unique_ptr<cmInstallGenerator>> InstallGenerators; + std::vector<std::unique_ptr<cmTestGenerator>> TestGenerators; std::string ComplainFileRegularExpression; std::string DefineFlags; @@ -1060,13 +1055,14 @@ private: std::vector<cmMakefile*> UnConfiguredDirectories; std::vector<cmExportBuildFileGenerator*> ExportBuildFileGenerators; - std::vector<cmGeneratorExpressionEvaluationFile*> EvaluationFiles; + std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>> + EvaluationFiles; std::vector<cmExecutionStatus*> ExecutionStatusStack; friend class cmMakefileCall; friend class cmParseFileScope; - std::vector<cmTarget*> ImportedTargetsOwned; + std::vector<std::unique_ptr<cmTarget>> ImportedTargetsOwned; using TargetMap = std::unordered_map<std::string, cmTarget*>; TargetMap ImportedTargets; diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 5c9608c..1df5410 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -420,10 +420,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) this->GetTargetLinkFlags(linkFlags, linkLanguage); { - std::unique_ptr<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer = this->CreateLinkLineComputer( this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory())); + this->LocalGenerator->GetStateSnapshot().GetDirectory()); this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags, this->GetConfigName()); @@ -509,10 +509,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) // Set path conversion for link script shells. this->LocalGenerator->SetLinkScriptShell(useLinkScript); - std::unique_ptr<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer = this->CreateLinkLineComputer( this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory())); + this->LocalGenerator->GetStateSnapshot().GetDirectory()); linkLineComputer->SetForResponse(useResponseFileForLibs); linkLineComputer->SetUseWatcomQuote(useWatcomQuote); linkLineComputer->SetRelink(relink); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index e728b67..357e273 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -172,10 +172,10 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink) this->LocalGenerator->AddConfigVariableFlags( extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->GetConfigName()); - std::unique_ptr<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer = this->CreateLinkLineComputer( this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory())); + this->LocalGenerator->GetStateSnapshot().GetDirectory()); this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags, this->GetConfigName()); @@ -207,10 +207,10 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink) this->LocalGenerator->AddConfigVariableFlags( extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->GetConfigName()); - std::unique_ptr<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer = this->CreateLinkLineComputer( this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory())); + this->LocalGenerator->GetStateSnapshot().GetDirectory()); this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags, this->GetConfigName()); @@ -700,10 +700,10 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( std::string linkLibs; if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) { - std::unique_ptr<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer = this->CreateLinkLineComputer( this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory())); + this->LocalGenerator->GetStateSnapshot().GetDirectory()); linkLineComputer->SetForResponse(useResponseFileForLibs); linkLineComputer->SetUseWatcomQuote(useWatcomQuote); linkLineComputer->SetRelink(relink); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 4979da5..77b6bc2 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -17,6 +17,7 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalUnixMakefileGenerator3.h" +#include "cmLinkLineComputer.h" #include "cmLocalCommonGenerator.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" @@ -753,8 +754,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( // See if we need to use a compiler launcher like ccache or distcc std::string compilerLauncher; if (!compileCommands.empty() && - (lang == "C" || lang == "CXX" || lang == "Fortran" || - lang == "CUDA")) { + (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" || + lang == "OBJC" || lang == "OBJCXX")) { std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER"; const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop); @@ -1634,7 +1635,8 @@ std::string cmMakefileTargetGenerator::CreateResponseFile( return responseFileName; } -cmLinkLineComputer* cmMakefileTargetGenerator::CreateLinkLineComputer( +std::unique_ptr<cmLinkLineComputer> +cmMakefileTargetGenerator::CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) { if (this->Makefile->IsOn("MSVC60")) { diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 710ef89..fd62933 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -140,7 +140,7 @@ protected: std::vector<std::string>& makefile_commands, std::vector<std::string>& makefile_depends); - cmLinkLineComputer* CreateLinkLineComputer( + std::unique_ptr<cmLinkLineComputer> CreateLinkLineComputer( cmOutputConverter* outputConverter, cmStateDirectory const& stateDir); /** Create a response file with the given set of options. Returns diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 5a12855..f853ac5 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -11,8 +11,8 @@ #include <utility> #include <cm/memory> +#include <cm/vector> -#include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommand.h" // IWYU pragma: keep #include "cmCustomCommandGenerator.h" @@ -72,6 +72,10 @@ void cmNinjaNormalTargetGenerator::Generate(const std::string& config) // Write the build statements bool firstForConfig = true; for (auto const& fileConfig : this->GetConfigNames()) { + if (fileConfig != config && + !this->GetGlobalGenerator()->EnableCrossConfigBuild()) { + continue; + } this->WriteObjectBuildStatements(config, fileConfig, firstForConfig); firstForConfig = false; } @@ -79,17 +83,23 @@ void cmNinjaNormalTargetGenerator::Generate(const std::string& config) if (this->GetGeneratorTarget()->GetType() == cmStateEnums::OBJECT_LIBRARY) { this->WriteObjectLibStatement(config); } else { - // If this target has cuda language link inputs, and we need to do - // device linking - this->WriteDeviceLinkStatement(config); firstForConfig = true; for (auto const& fileConfig : this->GetConfigNames()) { + if (fileConfig != config && + !this->GetGlobalGenerator()->EnableCrossConfigBuild()) { + continue; + } + // If this target has cuda language link inputs, and we need to do + // device linking + this->WriteDeviceLinkStatement(config, fileConfig, firstForConfig); this->WriteLinkStatement(config, fileConfig, firstForConfig); firstForConfig = false; } } - this->GetGlobalGenerator()->AddTargetAlias( - this->GetTargetName(), this->GetGeneratorTarget(), "all"); + if (this->GetGlobalGenerator()->EnableCrossConfigBuild()) { + this->GetGlobalGenerator()->AddTargetAlias( + this->GetTargetName(), this->GetGeneratorTarget(), "all"); + } // Find ADDITIONAL_CLEAN_FILES this->AdditionalCleanFiles(config); @@ -243,7 +253,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule( } // If there is no ranlib the command will be ":". Skip it. - cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands()); + cm::erase_if(linkCmds, cmNinjaRemoveNoOpCommands()); rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds); @@ -379,7 +389,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile, } // If there is no ranlib the command will be ":". Skip it. - cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands()); + cm::erase_if(linkCmds, cmNinjaRemoveNoOpCommands()); linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); linkCmds.emplace_back("$POST_BUILD"); @@ -551,7 +561,8 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd( } void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement( - const std::string& config) + const std::string& config, const std::string& fileConfig, + bool firstForConfig) { cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator(); if (!globalGen->GetLanguageEnabled("CUDA")) { @@ -574,12 +585,42 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement( std::string const& objExt = this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION"); - std::string const targetOutputReal = ConvertToNinjaPath( - genTarget->ObjectDirectory + "cmake_device_link" + objExt); + std::string targetOutputDir = + cmStrCat(this->GetLocalGenerator()->GetTargetDirectory(genTarget), + globalGen->ConfigDirectory(config), "/"); + targetOutputDir = globalGen->ExpandCFGIntDir(targetOutputDir, config); - std::string const targetOutputImplib = ConvertToNinjaPath( + std::string targetOutputReal = + ConvertToNinjaPath(targetOutputDir + "cmake_device_link" + objExt); + + std::string targetOutputImplib = ConvertToNinjaPath( genTarget->GetFullPath(config, cmStateEnums::ImportLibraryArtifact)); + if (config != fileConfig) { + std::string targetOutputFileConfigDir = + cmStrCat(this->GetLocalGenerator()->GetTargetDirectory(genTarget), + globalGen->ConfigDirectory(fileConfig), "/"); + targetOutputFileConfigDir = + globalGen->ExpandCFGIntDir(targetOutputDir, fileConfig); + if (targetOutputDir == targetOutputFileConfigDir) { + return; + } + + if (!genTarget->GetFullName(config, cmStateEnums::ImportLibraryArtifact) + .empty() && + !genTarget + ->GetFullName(fileConfig, cmStateEnums::ImportLibraryArtifact) + .empty() && + targetOutputImplib == + ConvertToNinjaPath(genTarget->GetFullPath( + fileConfig, cmStateEnums::ImportLibraryArtifact))) { + return; + } + } + + if (firstForConfig) { + globalGen->GetByproductsForCleanTarget(config).push_back(targetOutputReal); + } this->DeviceLinkObject = targetOutputReal; // Write comments. @@ -884,10 +925,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL); - std::unique_ptr<cmLinkLineComputer> linkLineComputer( + std::unique_ptr<cmLinkLineComputer> linkLineComputer = globalGen->CreateLinkLineComputer( this->GetLocalGenerator(), - this->GetLocalGenerator()->GetStateSnapshot().GetDirectory())); + this->GetLocalGenerator()->GetStateSnapshot().GetDirectory()); linkLineComputer->SetUseWatcomQuote(useWatcomQuote); linkLineComputer->SetUseNinjaMulti(globalGen->IsMultiConfig()); diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h index cda76d8..9de99b9 100644 --- a/Source/cmNinjaNormalTargetGenerator.h +++ b/Source/cmNinjaNormalTargetGenerator.h @@ -31,7 +31,9 @@ private: void WriteLinkStatement(const std::string& config, const std::string& fileConfig, bool firstForConfig); - void WriteDeviceLinkStatement(const std::string& config); + void WriteDeviceLinkStatement(const std::string& config, + const std::string& fileConfig, + bool firstForConfig); void WriteObjectLibStatement(const std::string& config); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 3f1dbe8..5a8c144 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -724,7 +724,8 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang, // See if we need to use a compiler launcher like ccache or distcc std::string compilerLauncher; if (!compileCmds.empty() && - (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA")) { + (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" || + lang == "OBJC" || lang == "OBJCXX")) { std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER"; const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop); if (clauncher && *clauncher) { @@ -1195,6 +1196,13 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(), vars); + if (!pchSource.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) { + if (source->GetFullPath() == pchSource) { + this->addPoolNinjaVariable("JOB_POOL_PRECOMPILE_HEADER", + this->GetGeneratorTarget(), vars); + } + } + this->SetMsvcTargetPdbVariable(vars, config); objBuild.RspFile = objectFileName + ".rsp"; diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index ecf892b..eef41c0 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -297,7 +297,12 @@ class cmMakefile; SELECT(POLICY, CMP0099, \ "Link properties are transitive over private dependency on static " \ "libraries.", \ - 3, 17, 0, cmPolicies::WARN) + 3, 17, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0100, "Let AUTOMOC and AUTOUIC process .hh files.", 3, \ + 17, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0101, \ + "target_compile_options honors BEFORE keyword in all scopes.", 3, \ + 17, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index ab47f3f..ebb522b 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -42,6 +42,7 @@ #include "cmSourceGroup.h" #include "cmState.h" #include "cmStateTypes.h" +#include "cmString.hxx" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" @@ -354,24 +355,38 @@ bool cmQtAutoGenInitializer::InitCustomTargets() } } - // Check status of policy CMP0071 - { - cmPolicies::PolicyStatus const CMP0071_status = - this->Makefile->GetPolicyStatus(cmPolicies::CMP0071); - switch (CMP0071_status) { - case cmPolicies::WARN: - this->CMP0071Warn = true; - CM_FALLTHROUGH; - case cmPolicies::OLD: - // Ignore GENERATED file - break; - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::NEW: - // Process GENERATED file - this->CMP0071Accept = true; - break; - } + // Check status of policy CMP0071 regarding handling of GENERATED files + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0071)) { + case cmPolicies::WARN: + // Ignore GENERATED files but warn + this->CMP0071Warn = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + // Ignore GENERATED files + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // Process GENERATED files + this->CMP0071Accept = true; + break; + } + + // Check status of policy CMP0100 regarding handling of .hh headers + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0100)) { + case cmPolicies::WARN: + // Ignore but .hh files but warn + this->CMP0100Warn = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + // Ignore .hh files + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // Process .hh file + this->CMP0100Accept = true; + break; } // Common directories @@ -733,15 +748,26 @@ bool cmQtAutoGenInitializer::InitScanFiles() return muf; }; - auto addMUFile = [&](MUFileHandle&& muf, bool isHeader) { + auto addMUHeader = [this](MUFileHandle&& muf, cm::string_view extension) { + cmSourceFile* sf = muf->SF; + const bool muIt = (muf->MocIt || muf->UicIt); + if (this->CMP0100Accept || (extension != "hh")) { + // Accept + if (muIt && muf->Generated) { + this->AutogenTarget.FilesGenerated.emplace_back(muf.get()); + } + this->AutogenTarget.Headers.emplace(sf, std::move(muf)); + } else if (muIt && this->CMP0100Warn) { + // Store file for warning message + this->AutogenTarget.CMP0100HeadersWarn.push_back(sf); + } + }; + + auto addMUSource = [this](MUFileHandle&& muf) { if ((muf->MocIt || muf->UicIt) && muf->Generated) { this->AutogenTarget.FilesGenerated.emplace_back(muf.get()); } - if (isHeader) { - this->AutogenTarget.Headers.emplace(muf->SF, std::move(muf)); - } else { - this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf)); - } + this->AutogenTarget.Sources.emplace(muf->SF, std::move(muf)); }; // Scan through target files @@ -763,11 +789,10 @@ bool cmQtAutoGenInitializer::InitScanFiles() // Register files that will be scanned by moc or uic if (this->MocOrUicEnabled()) { - // FIXME: Add a policy to include .hh files. - if (cm->IsHeaderExtension(extLower) && extLower != "hh") { - addMUFile(makeMUFile(sf, fullPath, true), true); + if (cm->IsHeaderExtension(extLower)) { + addMUHeader(makeMUFile(sf, fullPath, true), extLower); } else if (cm->IsSourceExtension(extLower)) { - addMUFile(makeMUFile(sf, fullPath, true), false); + addMUSource(makeMUFile(sf, fullPath, true)); } } @@ -801,8 +826,6 @@ bool cmQtAutoGenInitializer::InitScanFiles() // For source files find additional headers and private headers if (this->MocOrUicEnabled()) { - std::vector<MUFileHandle> extraHeaders; - extraHeaders.reserve(this->AutogenTarget.Sources.size() * 2); // Header search suffixes and extensions static std::initializer_list<cm::string_view> const suffixes{ "", "_p" }; auto const& exts = cm->GetHeaderExtensions(); @@ -847,16 +870,12 @@ bool cmQtAutoGenInitializer::InitScanFiles() if (!muf.UicIt) { eMuf->UicIt = false; } - extraHeaders.emplace_back(std::move(eMuf)); + addMUHeader(std::move(eMuf), ext); } } } } } - // Move generated files to main headers list - for (auto& eMuf : extraHeaders) { - addMUFile(std::move(eMuf), true); - } } // Scan through all source files in the makefile to extract moc and uic @@ -864,7 +883,7 @@ bool cmQtAutoGenInitializer::InitScanFiles() // The reason is that their file names might be discovered from source files // at generation time. if (this->MocOrUicEnabled()) { - for (cmSourceFile* sf : this->Makefile->GetSourceFiles()) { + for (const auto& sf : this->Makefile->GetSourceFiles()) { // sf->GetExtension() is only valid after sf->ResolveFullPath() ... // Since we're iterating over source files that might be not in the // target we need to check for path errors (not existing files). @@ -876,19 +895,18 @@ bool cmQtAutoGenInitializer::InitScanFiles() std::string const& extLower = cmSystemTools::LowerCase(sf->GetExtension()); - // FIXME: Add a policy to include .hh files. - if (cm->IsHeaderExtension(extLower) && extLower != "hh") { - if (!cmContains(this->AutogenTarget.Headers, sf)) { - auto muf = makeMUFile(sf, fullPath, false); + if (cm->IsHeaderExtension(extLower)) { + if (!cmContains(this->AutogenTarget.Headers, sf.get())) { + auto muf = makeMUFile(sf.get(), fullPath, false); if (muf->SkipMoc || muf->SkipUic) { - this->AutogenTarget.Headers.emplace(sf, std::move(muf)); + addMUHeader(std::move(muf), extLower); } } } else if (cm->IsSourceExtension(extLower)) { - if (!cmContains(this->AutogenTarget.Headers, sf)) { - auto muf = makeMUFile(sf, fullPath, false); + if (!cmContains(this->AutogenTarget.Sources, sf.get())) { + auto muf = makeMUFile(sf.get(), fullPath, false); if (muf->SkipMoc || muf->SkipUic) { - this->AutogenTarget.Sources.emplace(sf, std::move(muf)); + addMUSource(std::move(muf)); } } } else if (this->Uic.Enabled && (extLower == kw.ui)) { @@ -946,6 +964,35 @@ bool cmQtAutoGenInitializer::InitScanFiles() } } + // Generate CMP0100 warning + if (this->MocOrUicEnabled() && + !this->AutogenTarget.CMP0100HeadersWarn.empty()) { + cm::string_view property; + if (this->Moc.Enabled && this->Uic.Enabled) { + property = "SKIP_AUTOGEN"; + } else if (this->Moc.Enabled) { + property = "SKIP_AUTOMOC"; + } else if (this->Uic.Enabled) { + property = "SKIP_AUTOUIC"; + } + std::string files; + for (cmSourceFile* sf : this->AutogenTarget.CMP0100HeadersWarn) { + files += cmStrCat(" ", Quoted(sf->GetFullPath()), '\n'); + } + this->Makefile->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat( + cmPolicies::GetPolicyWarning(cmPolicies::CMP0100), '\n', + "For compatibility, CMake is excluding the header file(s):\n", files, + "from processing by ", + cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false), + ". If any of the files should be processed, set CMP0100 to NEW. " + "If any of the files should not be processed, " + "explicitly exclude them by setting the source file property ", + property, ":\n set_property(SOURCE file.hh PROPERTY ", property, + " ON)\n")); + } + // Process qrc files if (!this->Rcc.Qrcs.empty()) { const bool modernQt = (this->QtVersion.Major >= 5); @@ -1172,7 +1219,10 @@ bool cmQtAutoGenInitializer::InitRccTargets() // Register info file as generated by CMake this->Makefile->AddCMakeOutputFile(qrc.InfoFile); // Register file at target - this->AddGeneratedSource(qrc.OutputFile, this->Rcc); + { + cmSourceFile* sf = this->AddGeneratedSource(qrc.OutputFile, this->Rcc); + sf->SetProperty("SKIP_UNITY_BUILD_INCLUSION", "On"); + } std::vector<std::string> ccOutput; ccOutput.push_back(qrc.OutputFile); @@ -1467,27 +1517,30 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo() return true; } -void cmQtAutoGenInitializer::RegisterGeneratedSource( +cmSourceFile* cmQtAutoGenInitializer::RegisterGeneratedSource( std::string const& filename) { cmSourceFile* gFile = this->Makefile->GetOrCreateSource(filename, true); gFile->SetProperty("GENERATED", "1"); gFile->SetProperty("SKIP_AUTOGEN", "1"); + return gFile; } -bool cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, - GenVarsT const& genVars, - bool prepend) +cmSourceFile* cmQtAutoGenInitializer::AddGeneratedSource( + std::string const& filename, GenVarsT const& genVars, bool prepend) { // Register source at makefile - this->RegisterGeneratedSource(filename); + cmSourceFile* gFile = this->RegisterGeneratedSource(filename); // Add source file to target this->GenTarget->AddSource(filename, prepend); + // Add source file to source group - return this->AddToSourceGroup(filename, genVars.GenNameUpper); + this->AddToSourceGroup(filename, genVars.GenNameUpper); + + return gFile; } -bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName, +void cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName, cm::string_view genNameUpper) { cmSourceGroup* sourceGroup = nullptr; @@ -1518,14 +1571,12 @@ bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName, cmStrCat(genNameUpper, " error in ", property, ": Could not find or create the source group ", cmQtAutoGen::Quoted(groupName))); - return false; } } } if (sourceGroup != nullptr) { sourceGroup->AddGroupFile(fileName); } - return true; } void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName) @@ -1634,21 +1685,39 @@ std::string cmQtAutoGenInitializer::GetMocBuildPath(MUFile const& muf) if (!muf.MocIt) { return res; } - { - std::string const basePath = - cmStrCat(this->PathCheckSum.getPart(muf.FullPath), "/moc_", - FileNameWithoutLastExtension(muf.FullPath)); - std::string suffix; - constexpr std::size_t num_tries_max = 256; - for (std::size_t ii = 0; ii != num_tries_max; ++ii) { - res = cmStrCat(basePath, suffix, ".cpp"); - if (this->Moc.EmittedBuildPaths.emplace(res).second) { - break; - } - // Compute new suffix - suffix = cmStrCat('_', ii + 1); + + std::string basePath = + cmStrCat(this->PathCheckSum.getPart(muf.FullPath), "/moc_", + FileNameWithoutLastExtension(muf.FullPath)); + + res = cmStrCat(basePath, ".cpp"); + if (this->Moc.EmittedBuildPaths.emplace(res).second) { + return res; + } + + // File name already emitted. + // Try appending the header suffix to the base path. + basePath = cmStrCat(basePath, '_', muf.SF->GetExtension()); + res = cmStrCat(basePath, ".cpp"); + if (this->Moc.EmittedBuildPaths.emplace(res).second) { + return res; + } + + // File name with header extension already emitted. + // Try adding a number to the base path. + constexpr std::size_t number_begin = 2; + constexpr std::size_t number_end = 256; + for (std::size_t ii = number_begin; ii != number_end; ++ii) { + res = cmStrCat(basePath, '_', ii, ".cpp"); + if (this->Moc.EmittedBuildPaths.emplace(res).second) { + return res; } } + + // Output file name conflict (unlikely, but still...) + cmSystemTools::Error( + cmStrCat("moc output file name conflict for ", muf.FullPath)); + return res; } diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index 486dab7..8cedf14 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -129,10 +129,11 @@ private: bool SetupWriteAutogenInfo(); bool SetupWriteRccInfo(); - void RegisterGeneratedSource(std::string const& filename); - bool AddGeneratedSource(std::string const& filename, GenVarsT const& genVars, - bool prepend = false); - bool AddToSourceGroup(std::string const& fileName, + cmSourceFile* RegisterGeneratedSource(std::string const& filename); + cmSourceFile* AddGeneratedSource(std::string const& filename, + GenVarsT const& genVars, + bool prepend = false); + void AddToSourceGroup(std::string const& fileName, cm::string_view genNameUpper); void AddCleanFile(std::string const& fileName); @@ -159,6 +160,8 @@ private: bool MultiConfig = false; bool CMP0071Accept = false; bool CMP0071Warn = false; + bool CMP0100Accept = false; + bool CMP0100Warn = false; std::string ConfigDefault; std::vector<std::string> ConfigsList; std::string TargetsFolder; @@ -192,6 +195,7 @@ private: std::unordered_map<cmSourceFile*, MUFileHandle> Headers; std::unordered_map<cmSourceFile*, MUFileHandle> Sources; std::vector<MUFile*> FilesGenerated; + std::vector<cmSourceFile*> CMP0100HeadersWarn; } AutogenTarget; /** moc variables. */ diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index 56003df..1d4ea01 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -744,7 +744,7 @@ void cmServerProtocol1::GeneratorInformation::SetupGenerator( cm->SetHomeDirectory(SourceDirectory); cm->SetHomeOutputDirectory(BuildDirectory); - cmGlobalGenerator* gg = cm->CreateGlobalGenerator(fullGeneratorName); + auto gg = cm->CreateGlobalGenerator(fullGeneratorName); if (!gg) { setErrorMessage( errorMessage, @@ -753,7 +753,7 @@ void cmServerProtocol1::GeneratorInformation::SetupGenerator( return; } - cm->SetGlobalGenerator(gg); + cm->SetGlobalGenerator(std::move(gg)); cm->SetGeneratorToolset(Toolset); cm->SetGeneratorPlatform(Platform); diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index 8c3a4cb..5e2a146 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -121,7 +121,7 @@ bool cmSetCommand(std::vector<std::string> const& args, if (cache) { std::string::size_type cacheStart = args.size() - 3 - (force ? 1 : 0); - if (!cmState::StringToCacheEntryType(args[cacheStart + 1].c_str(), type)) { + if (!cmState::StringToCacheEntryType(args[cacheStart + 1], type)) { std::string m = "implicitly converting '" + args[cacheStart + 1] + "' to 'STRING' type."; status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, m); diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 2a345eb..60adf7f 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -128,7 +128,7 @@ bool cmSourceFile::FindFullPath(std::string* error) // The file is not generated. It must exist on disk. cmMakefile const* makefile = this->Location.GetMakefile(); // Location path - std::string const lPath = this->Location.GetFullPath(); + std::string const& lPath = this->Location.GetFullPath(); // List of extension lists std::array<std::vector<std::string> const*, 2> const extsLists = { { &makefile->GetCMakeInstance()->GetSourceExtensions(), @@ -145,7 +145,7 @@ bool cmSourceFile::FindFullPath(std::string* error) return true; } // Try full path with extension - for (auto exts : extsLists) { + for (auto& exts : extsLists) { for (std::string const& ext : *exts) { if (!ext.empty()) { std::string extPath = cmStrCat(fullPath, '.', ext); diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index df702b0..5f807b8 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -31,7 +31,8 @@ cmSourceFileLocation::cmSourceFileLocation(cmMakefile const* mf, this->AmbiguousExtension = true; this->Directory = cmSystemTools::GetFilenamePath(name); if (cmSystemTools::FileIsFullPath(this->Directory)) { - this->Directory = cmSystemTools::CollapseFullPath(this->Directory); + this->Directory = cmSystemTools::CollapseFullPath( + this->Directory, mf->GetHomeOutputDirectory()); } this->Name = cmSystemTools::GetFilenameName(name); if (kind == cmSourceFileLocationKind::Known) { diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 72f663d..35f07a1 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -3,9 +3,9 @@ #include "cmState.h" #include <algorithm> +#include <array> #include <cassert> #include <cstdlib> -#include <cstring> #include <utility> #include <cm/memory> @@ -60,43 +60,44 @@ const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType) return nullptr; } -const char* cmCacheEntryTypes[] = { "BOOL", "PATH", "FILEPATH", - "STRING", "INTERNAL", "STATIC", - "UNINITIALIZED", nullptr }; +static const std::array<std::string, 7> cmCacheEntryTypes = { + { "BOOL", "PATH", "FILEPATH", "STRING", "INTERNAL", "STATIC", + "UNINITIALIZED" } +}; -const char* cmState::CacheEntryTypeToString(cmStateEnums::CacheEntryType type) +const std::string& cmState::CacheEntryTypeToString( + cmStateEnums::CacheEntryType type) { - if (type > 6) { - return cmCacheEntryTypes[6]; + if (type < cmStateEnums::BOOL || type > cmStateEnums::UNINITIALIZED) { + type = cmStateEnums::UNINITIALIZED; } return cmCacheEntryTypes[type]; } -cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(const char* s) +cmStateEnums::CacheEntryType cmState::StringToCacheEntryType( + const std::string& s) { cmStateEnums::CacheEntryType type = cmStateEnums::STRING; StringToCacheEntryType(s, type); return type; } -bool cmState::StringToCacheEntryType(const char* s, +bool cmState::StringToCacheEntryType(const std::string& s, cmStateEnums::CacheEntryType& type) { - int i = 0; - while (cmCacheEntryTypes[i]) { - if (strcmp(s, cmCacheEntryTypes[i]) == 0) { + for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) { + if (s == cmCacheEntryTypes[i]) { type = static_cast<cmStateEnums::CacheEntryType>(i); return true; } - ++i; } return false; } bool cmState::IsCacheEntryType(std::string const& key) { - for (int i = 0; cmCacheEntryTypes[i]; ++i) { - if (key == cmCacheEntryTypes[i]) { + for (const std::string& i : cmCacheEntryTypes) { + if (key == i) { return true; } } @@ -149,8 +150,7 @@ const std::string* cmState::GetInitializedCacheValue( cmStateEnums::CacheEntryType cmState::GetCacheEntryType( std::string const& key) const { - cmCacheManager::CacheIterator it = - this->CacheManager->GetCacheIterator(key.c_str()); + cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key); return it.GetType(); } @@ -164,8 +164,7 @@ void cmState::SetCacheEntryProperty(std::string const& key, std::string const& propertyName, std::string const& value) { - cmCacheManager::CacheIterator it = - this->CacheManager->GetCacheIterator(key.c_str()); + cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key); it.SetProperty(propertyName, value.c_str()); } @@ -173,24 +172,21 @@ void cmState::SetCacheEntryBoolProperty(std::string const& key, std::string const& propertyName, bool value) { - cmCacheManager::CacheIterator it = - this->CacheManager->GetCacheIterator(key.c_str()); + cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key); it.SetProperty(propertyName, value); } std::vector<std::string> cmState::GetCacheEntryPropertyList( const std::string& key) { - cmCacheManager::CacheIterator it = - this->CacheManager->GetCacheIterator(key.c_str()); + cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key); return it.GetPropertyList(); } const char* cmState::GetCacheEntryProperty(std::string const& key, std::string const& propertyName) { - cmCacheManager::CacheIterator it = - this->CacheManager->GetCacheIterator(key.c_str()); + cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key); if (!it.PropertyExists(propertyName)) { return nullptr; } @@ -200,8 +196,8 @@ const char* cmState::GetCacheEntryProperty(std::string const& key, bool cmState::GetCacheEntryPropertyAsBool(std::string const& key, std::string const& propertyName) { - return this->CacheManager->GetCacheIterator(key.c_str()) - .GetPropertyAsBool(propertyName); + return this->CacheManager->GetCacheIterator(key).GetPropertyAsBool( + propertyName); } void cmState::AddCacheEntry(const std::string& key, const char* value, @@ -253,15 +249,14 @@ void cmState::AppendCacheEntryProperty(const std::string& key, const std::string& property, const std::string& value, bool asString) { - this->CacheManager->GetCacheIterator(key.c_str()) - .AppendProperty(property, value.c_str(), asString); + this->CacheManager->GetCacheIterator(key).AppendProperty(property, value, + asString); } void cmState::RemoveCacheEntryProperty(std::string const& key, std::string const& propertyName) { - this->CacheManager->GetCacheIterator(key.c_str()) - .SetProperty(propertyName, nullptr); + this->CacheManager->GetCacheIterator(key).SetProperty(propertyName, nullptr); } cmStateSnapshot cmState::Reset() @@ -1006,12 +1001,12 @@ bool cmState::ParseCacheEntry(const std::string& entry, std::string& var, bool flag = false; if (regQuoted.find(entry)) { var = regQuoted.match(1); - type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str()); + type = cmState::StringToCacheEntryType(regQuoted.match(2)); value = regQuoted.match(3); flag = true; } else if (reg.find(entry)) { var = reg.match(1); - type = cmState::StringToCacheEntryType(reg.match(2).c_str()); + type = cmState::StringToCacheEntryType(reg.match(2)); value = reg.match(3); flag = true; } diff --git a/Source/cmState.h b/Source/cmState.h index cd871b9..a744266 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -70,10 +70,12 @@ public: cmStateSnapshot const& originSnapshot); cmStateSnapshot Pop(cmStateSnapshot const& originSnapshot); - static cmStateEnums::CacheEntryType StringToCacheEntryType(const char*); - static bool StringToCacheEntryType(const char*, + static cmStateEnums::CacheEntryType StringToCacheEntryType( + const std::string&); + static bool StringToCacheEntryType(const std::string&, cmStateEnums::CacheEntryType& type); - static const char* CacheEntryTypeToString(cmStateEnums::CacheEntryType); + static const std::string& CacheEntryTypeToString( + cmStateEnums::CacheEntryType); static bool IsCacheEntryType(std::string const& key); bool LoadCache(const std::string& path, bool internal, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index d2693b8..a0b3138 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -336,6 +336,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("C_STANDARD"); initProp("C_STANDARD_REQUIRED"); initProp("C_EXTENSIONS"); + initProp("OBJC_COMPILER_LAUNCHER"); initProp("OBJC_STANDARD"); initProp("OBJC_STANDARD_REQUIRED"); initProp("OBJC_EXTENSIONS"); @@ -347,6 +348,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("CXX_STANDARD"); initProp("CXX_STANDARD_REQUIRED"); initProp("CXX_EXTENSIONS"); + initProp("OBJCXX_COMPILER_LAUNCHER"); initProp("OBJCXX_STANDARD"); initProp("OBJCXX_STANDARD_REQUIRED"); initProp("OBJCXX_EXTENSIONS"); @@ -358,7 +360,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("CUDA_RESOLVE_DEVICE_SYMBOLS"); initProp("LINK_SEARCH_START_STATIC"); initProp("LINK_SEARCH_END_STATIC"); - initProp("FOLDER"); initProp("Swift_LANGUAGE_VERSION"); initProp("Swift_MODULE_DIRECTORY"); initProp("VS_JUST_MY_CODE_DEBUGGING"); @@ -390,6 +391,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, } if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) { + initProp("FOLDER"); + if (this->GetGlobalGenerator()->IsXcode()) { initProp("XCODE_GENERATE_SCHEME"); } @@ -510,6 +513,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->GetType() != cmStateEnums::UTILITY) { initProp("JOB_POOL_COMPILE"); initProp("JOB_POOL_LINK"); + initProp("JOB_POOL_PRECOMPILE_HEADER"); } if (impl->TargetType <= cmStateEnums::UTILITY) { @@ -934,14 +938,7 @@ cmTarget::LinkLibraryVectorType const& cmTarget::GetOriginalLinkLibraries() return impl->OriginalLinkLibraries; } -void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib, - cmTargetLinkLibraryType llt) -{ - this->AddLinkLibrary(mf, lib, lib, llt); -} - void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib, - std::string const& libRef, cmTargetLinkLibraryType llt) { cmTarget* tgt = mf.FindTargetToUse(lib); @@ -950,13 +947,13 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib, const std::string libName = (isNonImportedTarget && llt != GENERAL_LibraryType) - ? targetNameGenex(libRef) - : libRef; + ? targetNameGenex(lib) + : lib; this->AppendProperty("LINK_LIBRARIES", this->GetDebugGeneratorExpressions(libName, llt)); } - if (cmGeneratorExpression::Find(lib) != std::string::npos || lib != libRef || + if (cmGeneratorExpression::Find(lib) != std::string::npos || (tgt && (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY || tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) || @@ -1559,8 +1556,12 @@ static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value, static void cmTargetCheckIMPORTED_GLOBAL(const cmTarget* target, cmMakefile* context) { - std::vector<cmTarget*> targets = context->GetOwnedImportedTargets(); - auto it = std::find(targets.begin(), targets.end(), target); + const auto& targets = context->GetOwnedImportedTargets(); + auto it = + std::find_if(targets.begin(), targets.end(), + [&](const std::unique_ptr<cmTarget>& importTarget) -> bool { + return target == importTarget.get(); + }); if (it == targets.end()) { std::ostringstream e; e << "Attempt to promote imported target \"" << target->GetName() diff --git a/Source/cmTarget.h b/Source/cmTarget.h index bdf8c0f..ca37f0d 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -110,10 +110,8 @@ public: //! Clear the dependency information recorded for this target, if any. void ClearDependencyInformation(cmMakefile& mf); - void AddLinkLibrary(cmMakefile& mf, const std::string& lib, - cmTargetLinkLibraryType llt); void AddLinkLibrary(cmMakefile& mf, std::string const& lib, - std::string const& libRef, cmTargetLinkLibraryType llt); + cmTargetLinkLibraryType llt); enum TLLSignature { diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx index e39b726..dee2c10 100644 --- a/Source/cmTargetCompileOptionsCommand.cxx +++ b/Source/cmTargetCompileOptionsCommand.cxx @@ -5,6 +5,7 @@ #include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmPolicies.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" #include "cmTargetPropCommandBase.h" @@ -27,10 +28,16 @@ private: bool HandleDirectContent(cmTarget* tgt, const std::vector<std::string>& content, - bool /*prepend*/, bool /*system*/) override + bool prepend, bool /*system*/) override { + cmPolicies::PolicyStatus policyStatus = + this->Makefile->GetPolicyStatus(cmPolicies::CMP0101); + if (policyStatus == cmPolicies::OLD || policyStatus == cmPolicies::WARN) { + prepend = false; + } + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertCompileOption(this->Join(content), lfbt); + tgt->InsertCompileOption(this->Join(content), lfbt, prepend); return true; // Successfully handled. } diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index e1ac6a8..df751da 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -3,7 +3,10 @@ #include "cmTargetLinkLibrariesCommand.h" #include <cstring> +#include <memory> #include <sstream> +#include <unordered_set> +#include <utility> #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" @@ -34,15 +37,30 @@ enum ProcessingState const char* LinkLibraryTypeNames[3] = { "general", "debug", "optimized" }; +struct TLL +{ + cmMakefile& Makefile; + cmTarget* Target; + bool WarnRemoteInterface = false; + bool RejectRemoteLinking = false; + bool EncodeRemoteReference = false; + std::string DirectoryId; + std::unordered_set<std::string> Props; + + TLL(cmMakefile& mf, cmTarget* target); + ~TLL(); + + bool HandleLibrary(ProcessingState currentProcessingState, + const std::string& lib, cmTargetLinkLibraryType llt); + void AppendProperty(std::string const& prop, std::string const& value); + void AffectsProperty(std::string const& prop); +}; + } // namespace static void LinkLibraryTypeSpecifierWarning(cmMakefile& mf, int left, int right); -static bool HandleLibrary(cmMakefile& mf, cmTarget* target, - ProcessingState currentProcessingState, - const std::string& lib, cmTargetLinkLibraryType llt); - bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args, cmExecutionStatus& status) { @@ -64,11 +82,9 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args, cmTarget* target = mf.GetCMakeInstance()->GetGlobalGenerator()->FindTarget(args[0]); if (!target) { - const std::vector<cmTarget*>& importedTargets = - mf.GetOwnedImportedTargets(); - for (cmTarget* importedTarget : importedTargets) { + for (const auto& importedTarget : mf.GetOwnedImportedTargets()) { if (importedTarget->GetName() == args[0]) { - target = importedTarget; + target = importedTarget.get(); break; } } @@ -149,6 +165,8 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args, return true; } + TLL tll(mf, target); + // Keep track of link configuration specifiers. cmTargetLinkLibraryType llt = GENERAL_LibraryType; bool haveLLT = false; @@ -247,7 +265,7 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args, } else if (haveLLT) { // The link type was specified by the previous argument. haveLLT = false; - if (!HandleLibrary(mf, target, currentProcessingState, args[i], llt)) { + if (!tll.HandleLibrary(currentProcessingState, args[i], llt)) { return false; } } else { @@ -268,7 +286,7 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args, llt = OPTIMIZED_LibraryType; } } - if (!HandleLibrary(mf, target, currentProcessingState, args[i], llt)) { + if (!tll.HandleLibrary(currentProcessingState, args[i], llt)) { return false; } } @@ -311,21 +329,48 @@ static void LinkLibraryTypeSpecifierWarning(cmMakefile& mf, int left, "\" instead of a library name. The first specifier will be ignored.")); } -static bool HandleLibrary(cmMakefile& mf, cmTarget* target, - ProcessingState currentProcessingState, - const std::string& lib, cmTargetLinkLibraryType llt) +namespace { + +TLL::TLL(cmMakefile& mf, cmTarget* target) + : Makefile(mf) + , Target(target) +{ + if (&this->Makefile != this->Target->GetMakefile()) { + // The LHS target was created in another directory. + switch (this->Makefile.GetPolicyStatus(cmPolicies::CMP0079)) { + case cmPolicies::WARN: + this->WarnRemoteInterface = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + this->RejectRemoteLinking = true; + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::NEW: + this->EncodeRemoteReference = true; + break; + } + } + if (this->EncodeRemoteReference) { + cmDirectoryId const dirId = this->Makefile.GetDirectoryId(); + this->DirectoryId = cmStrCat(CMAKE_DIRECTORY_ID_SEP, dirId.String); + } +} + +bool TLL::HandleLibrary(ProcessingState currentProcessingState, + const std::string& lib, cmTargetLinkLibraryType llt) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY && + if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY && currentProcessingState != ProcessingKeywordLinkInterface) { - mf.IssueMessage( + this->Makefile.IssueMessage( MessageType::FATAL_ERROR, "INTERFACE library can only be used with the INTERFACE keyword of " "target_link_libraries"); return false; } - if (target->IsImported() && + if (this->Target->IsImported() && currentProcessingState != ProcessingKeywordLinkInterface) { - mf.IssueMessage( + this->Makefile.IssueMessage( MessageType::FATAL_ERROR, "IMPORTED library can only be used with the INTERFACE keyword of " "target_link_libraries"); @@ -340,11 +385,12 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, currentProcessingState == ProcessingKeywordLinkInterface) ? cmTarget::KeywordTLLSignature : cmTarget::PlainTLLSignature; - if (!target->PushTLLCommandTrace(sig, mf.GetExecutionContext())) { + if (!this->Target->PushTLLCommandTrace( + sig, this->Makefile.GetExecutionContext())) { std::ostringstream e; const char* modal = nullptr; MessageType messageType = MessageType::AUTHOR_WARNING; - switch (mf.GetPolicyStatus(cmPolicies::CMP0023)) { + switch (this->Makefile.GetPolicyStatus(cmPolicies::CMP0023)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0023) << "\n"; modal = "should"; @@ -365,73 +411,38 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, e << "The " << existingSig << " signature for target_link_libraries has " "already been used with the target \"" - << target->GetName() + << this->Target->GetName() << "\". All uses of target_link_libraries with a target " << modal << " be either all-keyword or all-plain.\n"; - target->GetTllSignatureTraces(e, - sig == cmTarget::KeywordTLLSignature - ? cmTarget::PlainTLLSignature - : cmTarget::KeywordTLLSignature); - mf.IssueMessage(messageType, e.str()); + this->Target->GetTllSignatureTraces(e, + sig == cmTarget::KeywordTLLSignature + ? cmTarget::PlainTLLSignature + : cmTarget::KeywordTLLSignature); + this->Makefile.IssueMessage(messageType, e.str()); if (messageType == MessageType::FATAL_ERROR) { return false; } } } - bool warnRemoteInterface = false; - bool rejectRemoteLinking = false; - bool encodeRemoteReference = false; - if (&mf != target->GetMakefile()) { - // The LHS target was created in another directory. - switch (mf.GetPolicyStatus(cmPolicies::CMP0079)) { - case cmPolicies::WARN: - warnRemoteInterface = true; - CM_FALLTHROUGH; - case cmPolicies::OLD: - rejectRemoteLinking = true; - break; - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::NEW: - encodeRemoteReference = true; - break; - } - } - - std::string libRef; - if (encodeRemoteReference && !cmSystemTools::FileIsFullPath(lib)) { - // This is a library name added by a caller that is not in the - // same directory as the target was created. Add a suffix to - // the name to tell ResolveLinkItem to look up the name in the - // caller's directory. - cmDirectoryId const dirId = mf.GetDirectoryId(); - libRef = lib + CMAKE_DIRECTORY_ID_SEP + dirId.String; - } else { - // This is an absolute path or a library name added by a caller - // in the same directory as the target was created. We can use - // the original name directly. - libRef = lib; - } - // Handle normal case where the command was called with another keyword than // INTERFACE / LINK_INTERFACE_LIBRARIES or none at all. (The "LINK_LIBRARIES" // property of the target on the LHS shall be populated.) if (currentProcessingState != ProcessingKeywordLinkInterface && currentProcessingState != ProcessingPlainLinkInterface) { - if (rejectRemoteLinking) { - mf.IssueMessage( + if (this->RejectRemoteLinking) { + this->Makefile.IssueMessage( MessageType::FATAL_ERROR, cmStrCat("Attempt to add link library \"", lib, "\" to target \"", - target->GetName(), + this->Target->GetName(), "\" which is not built in this " "directory.\nThis is allowed only when policy CMP0079 " "is set to NEW.")); return false; } - cmTarget* tgt = mf.GetGlobalGenerator()->FindTarget(lib); + cmTarget* tgt = this->Makefile.GetGlobalGenerator()->FindTarget(lib); if (tgt && (tgt->GetType() != cmStateEnums::STATIC_LIBRARY) && (tgt->GetType() != cmStateEnums::SHARED_LIBRARY) && @@ -439,7 +450,7 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, (tgt->GetType() != cmStateEnums::OBJECT_LIBRARY) && (tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) && !tgt->IsExecutableWithExports()) { - mf.IssueMessage( + this->Makefile.IssueMessage( MessageType::FATAL_ERROR, cmStrCat( "Target \"", lib, "\" of type ", @@ -449,15 +460,16 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, "executables with the ENABLE_EXPORTS property set.")); } - target->AddLinkLibrary(mf, lib, libRef, llt); + this->AffectsProperty("LINK_LIBRARIES"); + this->Target->AddLinkLibrary(this->Makefile, lib, llt); } - if (warnRemoteInterface) { - mf.IssueMessage( + if (this->WarnRemoteInterface) { + this->Makefile.IssueMessage( MessageType::AUTHOR_WARNING, cmStrCat( cmPolicies::GetPolicyWarning(cmPolicies::CMP0079), "\nTarget\n ", - target->GetName(), + this->Target->GetName(), "\nis not created in this " "directory. For compatibility with older versions of CMake, link " "library\n ", @@ -472,15 +484,15 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, // STATIC library.) if (currentProcessingState == ProcessingKeywordPrivateInterface || currentProcessingState == ProcessingPlainPrivateInterface) { - if (target->GetType() == cmStateEnums::STATIC_LIBRARY || - target->GetType() == cmStateEnums::OBJECT_LIBRARY) { + if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY || + this->Target->GetType() == cmStateEnums::OBJECT_LIBRARY) { std::string configLib = - target->GetDebugGeneratorExpressions(libRef, llt); + this->Target->GetDebugGeneratorExpressions(lib, llt); if (cmGeneratorExpression::IsValidTargetName(lib) || cmGeneratorExpression::Find(lib) != std::string::npos) { configLib = "$<LINK_ONLY:" + configLib + ">"; } - target->AppendProperty("INTERFACE_LINK_LIBRARIES", configLib); + this->AppendProperty("INTERFACE_LINK_LIBRARIES", configLib); } return true; } @@ -488,8 +500,8 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, // Handle general case where the command was called with another keyword than // PRIVATE / LINK_PRIVATE or none at all. (The "INTERFACE_LINK_LIBRARIES" // property of the target on the LHS shall be populated.) - target->AppendProperty("INTERFACE_LINK_LIBRARIES", - target->GetDebugGeneratorExpressions(libRef, llt)); + this->AppendProperty("INTERFACE_LINK_LIBRARIES", + this->Target->GetDebugGeneratorExpressions(lib, llt)); // Stop processing if called without any keyword. if (currentProcessingState == ProcessingLinkLibraries) { @@ -497,13 +509,13 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, } // Stop processing if policy CMP0022 is set to NEW. const cmPolicies::PolicyStatus policy22Status = - target->GetPolicyStatusCMP0022(); + this->Target->GetPolicyStatusCMP0022(); if (policy22Status != cmPolicies::OLD && policy22Status != cmPolicies::WARN) { return true; } // Stop processing if called with an INTERFACE library on the LHS. - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { return true; } @@ -513,7 +525,7 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, { // Get the list of configurations considered to be DEBUG. std::vector<std::string> debugConfigs = - mf.GetCMakeInstance()->GetDebugConfigs(); + this->Makefile.GetCMakeInstance()->GetDebugConfigs(); std::string prop; // Include this library in the link interface for the target. @@ -521,22 +533,49 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target, // Put in the DEBUG configuration interfaces. for (std::string const& dc : debugConfigs) { prop = cmStrCat("LINK_INTERFACE_LIBRARIES_", dc); - target->AppendProperty(prop, libRef); + this->AppendProperty(prop, lib); } } if (llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType) { // Put in the non-DEBUG configuration interfaces. - target->AppendProperty("LINK_INTERFACE_LIBRARIES", libRef); + this->AppendProperty("LINK_INTERFACE_LIBRARIES", lib); // Make sure the DEBUG configuration interfaces exist so that the // general one will not be used as a fall-back. for (std::string const& dc : debugConfigs) { prop = cmStrCat("LINK_INTERFACE_LIBRARIES_", dc); - if (!target->GetProperty(prop)) { - target->SetProperty(prop, ""); + if (!this->Target->GetProperty(prop)) { + this->Target->SetProperty(prop, ""); } } } } return true; } + +void TLL::AppendProperty(std::string const& prop, std::string const& value) +{ + this->AffectsProperty(prop); + this->Target->AppendProperty(prop, value); +} + +void TLL::AffectsProperty(std::string const& prop) +{ + if (!this->EncodeRemoteReference) { + return; + } + // Add a wrapper to the expression to tell LookupLinkItems to look up + // names in the caller's directory. + if (this->Props.insert(prop).second) { + this->Target->AppendProperty(prop, this->DirectoryId); + } +} + +TLL::~TLL() +{ + for (std::string const& prop : this->Props) { + this->Target->AppendProperty(prop, CMAKE_DIRECTORY_ID_SEP); + } +} + +} // namespace diff --git a/Source/cmTargetPropertyComputer.cxx b/Source/cmTargetPropertyComputer.cxx index baab8da..f37995c 100644 --- a/Source/cmTargetPropertyComputer.cxx +++ b/Source/cmTargetPropertyComputer.cxx @@ -62,6 +62,7 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty( "COMPATIBLE_INTERFACE_NUMBER_MAX", "COMPATIBLE_INTERFACE_NUMBER_MIN", "COMPATIBLE_INTERFACE_STRING", + "DEPRECATION", "EXPORT_NAME", "EXPORT_PROPERTIES", "IMPORTED", diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 8e4f629..ab76df9 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2,6 +2,15 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmake.h" +#include <algorithm> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <initializer_list> +#include <iostream> +#include <sstream> +#include <utility> + #include <cm/memory> #include <cm/string_view> #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW) @@ -10,6 +19,10 @@ #include <cmext/algorithm> +#include "cmsys/FStream.hxx" +#include "cmsys/Glob.hxx" +#include "cmsys/RegularExpression.hxx" + #include "cm_sys_stat.h" #include "cmAlgorithms.h" @@ -58,6 +71,8 @@ // include the generator #if defined(_WIN32) && !defined(__CYGWIN__) # if !defined(CMAKE_BOOT_MINGW) +# include <cmext/memory> + # include "cmGlobalBorlandMakefileGenerator.h" # include "cmGlobalJOMMakefileGenerator.h" # include "cmGlobalNMakeMakefileGenerator.h" @@ -108,19 +123,6 @@ # include <sys/time.h> #endif -#include <algorithm> -#include <cstdio> -#include <cstdlib> -#include <cstring> -#include <initializer_list> -#include <iostream> -#include <sstream> -#include <utility> - -#include "cmsys/FStream.hxx" -#include "cmsys/Glob.hxx" -#include "cmsys/RegularExpression.hxx" - namespace { #if !defined(CMAKE_BOOTSTRAP) @@ -203,14 +205,7 @@ cmake::cmake(Role role, cmState::Mode mode) } } -cmake::~cmake() -{ - if (this->GlobalGenerator) { - delete this->GlobalGenerator; - this->GlobalGenerator = nullptr; - } - cmDeleteAll(this->Generators); -} +cmake::~cmake() = default; #if !defined(CMAKE_BOOTSTRAP) Json::Value cmake::ReportVersionJson() const @@ -463,12 +458,12 @@ void cmake::ReadListFile(const std::vector<std::string>& args, { // if a generator was not yet created, temporarily create one cmGlobalGenerator* gg = this->GetGlobalGenerator(); - bool created = false; // if a generator was not specified use a generic one + std::unique_ptr<cmGlobalGenerator> gen; if (!gg) { - gg = new cmGlobalGenerator(this); - created = true; + gen = cm::make_unique<cmGlobalGenerator>(this); + gg = gen.get(); } // read in the list file to fill the cache @@ -490,11 +485,6 @@ void cmake::ReadListFile(const std::vector<std::string>& args, cmSystemTools::Error("Error processing file: " + path); } } - - // free generic one if generated - if (created) { - delete gg; - } } bool cmake::FindPackage(const std::vector<std::string>& args) @@ -502,9 +492,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args) this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory()); this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory()); - // if a generator was not yet created, temporarily create one - cmGlobalGenerator* gg = new cmGlobalGenerator(this); - this->SetGlobalGenerator(gg); + this->SetGlobalGenerator(cm::make_unique<cmGlobalGenerator>(this)); cmStateSnapshot snapshot = this->GetCurrentSnapshot(); snapshot.GetDirectory().SetCurrentBinary( @@ -513,8 +501,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args) cmSystemTools::GetCurrentWorkingDirectory()); // read in the list file to fill the cache snapshot.SetDefaultDefinitions(); - cmMakefile* mf = new cmMakefile(gg, snapshot); - gg->AddMakefile(mf); + auto mfu = cm::make_unique<cmMakefile>(this->GetGlobalGenerator(), snapshot); + cmMakefile* mf = mfu.get(); + this->GlobalGenerator->AddMakefile(std::move(mfu)); mf->SetArgcArgv(args); @@ -539,8 +528,8 @@ bool cmake::FindPackage(const std::vector<std::string>& args) std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS"); std::vector<std::string> includeDirs = cmExpandedList(includes); - gg->CreateGenerationObjects(); - const auto& lg = gg->LocalGenerators[0]; + this->GlobalGenerator->CreateGenerationObjects(); + const auto& lg = this->GlobalGenerator->LocalGenerators[0]; std::string includeFlags = lg->GetIncludeFlags(includeDirs, nullptr, language); @@ -566,8 +555,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args) std::string linkPath; std::string flags; std::string linkFlags; - gg->CreateGenerationObjects(); - cmGeneratorTarget* gtgt = gg->FindGeneratorTarget(tgt->GetName()); + this->GlobalGenerator->CreateGenerationObjects(); + cmGeneratorTarget* gtgt = + this->GlobalGenerator->FindGeneratorTarget(tgt->GetName()); cmLocalGenerator* lg = gtgt->GetLocalGenerator(); cmLinkLineComputer linkLineComputer(lg, lg->GetStateSnapshot().GetDirectory()); @@ -587,10 +577,6 @@ bool cmake::FindPackage(const std::vector<std::string>& args) }*/ } - // free generic one if generated - // this->SetGlobalGenerator(0); // setting 0-pointer is not possible - // delete gg; // this crashes inside the cmake instance - return packageFound; } @@ -838,7 +824,7 @@ void cmake::SetArgs(const std::vector<std::string>& args) } value = args[i]; } - cmGlobalGenerator* gen = this->CreateGlobalGenerator(value); + auto gen = this->CreateGlobalGenerator(value); if (!gen) { std::string kdevError; if (value.find("KDevelop3", 0) != std::string::npos) { @@ -850,7 +836,7 @@ void cmake::SetArgs(const std::vector<std::string>& args) this->PrintGeneratorList(); return; } - this->SetGlobalGenerator(gen); + this->SetGlobalGenerator(std::move(gen)); } // no option assume it is the path to the source or an existing build else { @@ -1118,7 +1104,7 @@ void cmake::AddDefaultExtraGenerators() void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators, bool includeNamesWithPlatform) const { - for (cmGlobalGeneratorFactory* gen : this->Generators) { + for (const auto& gen : this->Generators) { std::vector<std::string> names = gen->GetGeneratorNames(); if (includeNamesWithPlatform) { @@ -1167,7 +1153,8 @@ void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators, } } -static std::pair<cmExternalMakefileProjectGenerator*, std::string> +static std::pair<std::unique_ptr<cmExternalMakefileProjectGenerator>, + std::string> createExtraGenerator( const std::vector<cmExternalMakefileProjectGeneratorFactory*>& in, const std::string& name) @@ -1190,15 +1177,17 @@ createExtraGenerator( return { nullptr, name }; } -cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname) +std::unique_ptr<cmGlobalGenerator> cmake::CreateGlobalGenerator( + const std::string& gname) { - std::pair<cmExternalMakefileProjectGenerator*, std::string> extra = - createExtraGenerator(this->ExtraGenerators, gname); - cmExternalMakefileProjectGenerator* extraGenerator = extra.first; - const std::string name = extra.second; + std::pair<std::unique_ptr<cmExternalMakefileProjectGenerator>, std::string> + extra = createExtraGenerator(this->ExtraGenerators, gname); + std::unique_ptr<cmExternalMakefileProjectGenerator>& extraGenerator = + extra.first; + const std::string& name = extra.second; - cmGlobalGenerator* generator = nullptr; - for (cmGlobalGeneratorFactory* g : this->Generators) { + std::unique_ptr<cmGlobalGenerator> generator; + for (const auto& g : this->Generators) { generator = g->CreateGlobalGenerator(name, this); if (generator) { break; @@ -1206,9 +1195,7 @@ cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname) } if (generator) { - generator->SetExternalMakefileProjectGenerator(extraGenerator); - } else { - delete extraGenerator; + generator->SetExternalMakefileProjectGenerator(std::move(extraGenerator)); } return generator; @@ -1260,15 +1247,13 @@ std::string cmake::FindCacheFile(const std::string& binaryDir) return cachePath; } -void cmake::SetGlobalGenerator(cmGlobalGenerator* gg) +void cmake::SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator> gg) { if (!gg) { cmSystemTools::Error("Error SetGlobalGenerator called with null"); return; } - // delete the old generator if (this->GlobalGenerator) { - delete this->GlobalGenerator; // restore the original environment variables CXX and CC // Restore CC std::string env = "CC="; @@ -1284,7 +1269,7 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator* gg) } // set the new - this->GlobalGenerator = gg; + this->GlobalGenerator = std::move(gg); // set the global flag for unix style paths on cmSystemTools as soon as // the generator is set. This allows gmake to be used on windows. @@ -1647,7 +1632,7 @@ int cmake::ActualConfigure() } } - cmMakefile* mf = this->GlobalGenerator->GetMakefiles()[0]; + auto& mf = this->GlobalGenerator->GetMakefiles()[0]; if (mf->IsOn("CTEST_USE_LAUNCHERS") && !this->State->GetGlobalProperty("RULE_LAUNCH_COMPILE")) { cmSystemTools::Error( @@ -1668,13 +1653,12 @@ int cmake::ActualConfigure() std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator() { if (!this->EnvironmentGenerator.empty()) { - cmGlobalGenerator* gen = - this->CreateGlobalGenerator(this->EnvironmentGenerator); + auto gen = this->CreateGlobalGenerator(this->EnvironmentGenerator); if (!gen) { cmSystemTools::Error("CMAKE_GENERATOR was set but the specified " "generator doesn't exist. Using CMake default."); } else { - return std::unique_ptr<cmGlobalGenerator>(gen); + return gen; } } #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW) @@ -1724,13 +1708,14 @@ std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator() } } } - cmGlobalGenerator* gen = this->CreateGlobalGenerator(found); + auto gen = this->CreateGlobalGenerator(found); if (!gen) { - gen = new cmGlobalNMakeMakefileGenerator(this); + gen = cm::make_unique<cmGlobalNMakeMakefileGenerator>(this); } - return std::unique_ptr<cmGlobalGenerator>(gen); + return std::unique_ptr<cmGlobalGenerator>(std::move(gen)); #else - return cm::make_unique<cmGlobalUnixMakefileGenerator3>(this); + return std::unique_ptr<cmGlobalGenerator>( + cm::make_unique<cmGlobalUnixMakefileGenerator3>(this)); #endif } @@ -1741,7 +1726,7 @@ void cmake::CreateDefaultGlobalGenerator() // This print could be unified for all platforms std::cout << "-- Building for: " << gen->GetName() << "\n"; #endif - this->SetGlobalGenerator(gen.release()); + this->SetGlobalGenerator(std::move(gen)); } void cmake::PreLoadCMakeFiles() @@ -1844,10 +1829,11 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) cmSystemTools::Message("CMake Configure step failed. " "Build files cannot be regenerated correctly. " "Attempting to stop IDE build."); - cmGlobalVisualStudioGenerator* gg = - static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator); - gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop, - this->VSSolutionFile); + cmGlobalVisualStudioGenerator& gg = + cm::static_reference_cast<cmGlobalVisualStudioGenerator>( + this->GlobalGenerator); + gg.CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop, + this->VSSolutionFile); } #endif return ret; @@ -2103,7 +2089,7 @@ void cmake::AppendGlobalGeneratorsDocumentation( const std::string defaultName = defaultGenerator->GetName(); bool foundDefaultOne = false; - for (cmGlobalGeneratorFactory* g : this->Generators) { + for (const auto& g : this->Generators) { cmDocumentationEntry e; g->GetDocumentation(e); if (!foundDefaultOne && cmHasPrefix(e.Name, defaultName)) { @@ -2243,8 +2229,8 @@ int cmake::CheckBuildSystem() } // Create the generator and use it to clear the dependencies. - std::unique_ptr<cmGlobalGenerator> ggd( - this->CreateGlobalGenerator(genName)); + std::unique_ptr<cmGlobalGenerator> ggd = + this->CreateGlobalGenerator(genName); if (ggd) { cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot()); @@ -2457,12 +2443,12 @@ int cmake::GetSystemInformation(std::vector<std::string>& args) } value = args[i]; } - cmGlobalGenerator* gen = this->CreateGlobalGenerator(value); + auto gen = this->CreateGlobalGenerator(value); if (!gen) { cmSystemTools::Error("Could not create named generator " + value); this->PrintGeneratorList(); } else { - this->SetGlobalGenerator(gen); + this->SetGlobalGenerator(std::move(gen)); } } // no option assume it is the output file @@ -2674,34 +2660,37 @@ int cmake::Build(int jobs, const std::string& dir, std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n"; return 1; } - cmGlobalGenerator* gen = this->CreateGlobalGenerator(cachedGenerator); + auto gen = this->CreateGlobalGenerator(cachedGenerator); if (!gen) { std::cerr << "Error: could create CMAKE_GENERATOR \"" << cachedGenerator << "\"\n"; return 1; } - this->SetGlobalGenerator(gen); + this->SetGlobalGenerator(std::move(gen)); const char* cachedGeneratorInstance = this->State->GetCacheEntryValue("CMAKE_GENERATOR_INSTANCE"); if (cachedGeneratorInstance) { - cmMakefile mf(gen, this->GetCurrentSnapshot()); - if (!gen->SetGeneratorInstance(cachedGeneratorInstance, &mf)) { + cmMakefile mf(this->GetGlobalGenerator(), this->GetCurrentSnapshot()); + if (!this->GlobalGenerator->SetGeneratorInstance(cachedGeneratorInstance, + &mf)) { return 1; } } const char* cachedGeneratorPlatform = this->State->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM"); if (cachedGeneratorPlatform) { - cmMakefile mf(gen, this->GetCurrentSnapshot()); - if (!gen->SetGeneratorPlatform(cachedGeneratorPlatform, &mf)) { + cmMakefile mf(this->GetGlobalGenerator(), this->GetCurrentSnapshot()); + if (!this->GlobalGenerator->SetGeneratorPlatform(cachedGeneratorPlatform, + &mf)) { return 1; } } const char* cachedGeneratorToolset = this->State->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET"); if (cachedGeneratorToolset) { - cmMakefile mf(gen, this->GetCurrentSnapshot()); - if (!gen->SetGeneratorToolset(cachedGeneratorToolset, true, &mf)) { + cmMakefile mf(this->GetGlobalGenerator(), this->GetCurrentSnapshot()); + if (!this->GlobalGenerator->SetGeneratorToolset(cachedGeneratorToolset, + true, &mf)) { return 1; } } @@ -2776,10 +2765,11 @@ int cmake::Build(int jobs, const std::string& dir, } #endif - gen->PrintBuildCommandAdvice(std::cerr, jobs); - return gen->Build(jobs, "", dir, projName, targets, output, "", config, - clean, false, verbose, cmDuration::zero(), - cmSystemTools::OUTPUT_PASSTHROUGH, nativeOptions); + this->GlobalGenerator->PrintBuildCommandAdvice(std::cerr, jobs); + return this->GlobalGenerator->Build( + jobs, "", dir, projName, targets, output, "", config, clean, false, + verbose, cmDuration::zero(), cmSystemTools::OUTPUT_PASSTHROUGH, + nativeOptions); } bool cmake::Open(const std::string& dir, bool dryRun) @@ -2807,8 +2797,8 @@ bool cmake::Open(const std::string& dir, bool dryRun) cmExternalMakefileProjectGenerator::CreateFullGeneratorName( genName, extraGenName ? *extraGenName : ""); - std::unique_ptr<cmGlobalGenerator> gen( - this->CreateGlobalGenerator(fullName)); + std::unique_ptr<cmGlobalGenerator> gen = + this->CreateGlobalGenerator(fullName); if (!gen) { std::cerr << "Error: could create CMAKE_GENERATOR \"" << fullName << "\"\n"; diff --git a/Source/cmake.h b/Source/cmake.h index 266d66c..22d3c39 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -213,21 +213,25 @@ public: void PreLoadCMakeFiles(); //! Create a GlobalGenerator - cmGlobalGenerator* CreateGlobalGenerator(const std::string& name); + std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator( + const std::string& name); //! Return the global generator assigned to this instance of cmake - cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; } + cmGlobalGenerator* GetGlobalGenerator() + { + return this->GlobalGenerator.get(); + } //! Return the global generator assigned to this instance of cmake, const const cmGlobalGenerator* GetGlobalGenerator() const { - return this->GlobalGenerator; + return this->GlobalGenerator.get(); } //! Return the full path to where the CMakeCache.txt file should be. static std::string FindCacheFile(const std::string& binaryDir); //! Return the global generator assigned to this instance of cmake - void SetGlobalGenerator(cmGlobalGenerator*); + void SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator>); //! Get the names of the current registered generators void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators, @@ -547,7 +551,8 @@ protected: void RunCheckForUnusedVariables(); int HandleDeleteCacheVariables(const std::string& var); - using RegisteredGeneratorsVector = std::vector<cmGlobalGeneratorFactory*>; + using RegisteredGeneratorsVector = + std::vector<std::unique_ptr<cmGlobalGeneratorFactory>>; RegisteredGeneratorsVector Generators; using RegisteredExtraGeneratorsVector = std::vector<cmExternalMakefileProjectGeneratorFactory*>; @@ -557,7 +562,6 @@ protected: void AddDefaultGenerators(); void AddDefaultExtraGenerators(); - cmGlobalGenerator* GlobalGenerator = nullptr; std::map<std::string, DiagLevel> DiagLevels; std::string GeneratorInstance; std::string GeneratorPlatform; @@ -638,6 +642,8 @@ private: std::stack<std::string> CheckInProgressMessages; + std::unique_ptr<cmGlobalGenerator> GlobalGenerator; + void UpdateConversionPathTable(); //! Print a list of valid generators to stderr. diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 9a07aef..67c776e 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1080,13 +1080,13 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args) cm.SetHomeDirectory(homeDir); cm.SetHomeOutputDirectory(homeOutDir); cm.GetCurrentSnapshot().SetDefaultDefinitions(); - if (cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen)) { - cm.SetGlobalGenerator(ggd); + if (auto ggd = cm.CreateGlobalGenerator(gen)) { + cm.SetGlobalGenerator(std::move(ggd)); cmStateSnapshot snapshot = cm.GetCurrentSnapshot(); snapshot.GetDirectory().SetCurrentBinary(startOutDir); snapshot.GetDirectory().SetCurrentSource(startDir); - cmMakefile mf(ggd, snapshot); - auto lgd = ggd->CreateLocalGenerator(&mf); + cmMakefile mf(cm.GetGlobalGenerator(), snapshot); + auto lgd = cm.GetGlobalGenerator()->CreateLocalGenerator(&mf); // Actually scan dependencies. return lgd->UpdateDependencies(depInfo, verbose, color) ? 0 : 2; |