diff options
Diffstat (limited to 'Source')
263 files changed, 2955 insertions, 2416 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 91c45bc..9e753e6 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -298,6 +298,7 @@ set(SRCS cmMakefileExecutableTargetGenerator.cxx cmMakefileLibraryTargetGenerator.cxx cmMakefileUtilityTargetGenerator.cxx + cmMessageType.h cmMessenger.cxx cmMessenger.h cmMSVC60LinkLineComputer.cxx @@ -696,10 +697,10 @@ if (WIN32) cmGlobalVisualStudio12Generator.cxx cmGlobalVisualStudio14Generator.h cmGlobalVisualStudio14Generator.cxx - cmGlobalVisualStudio15Generator.h - cmGlobalVisualStudio15Generator.cxx cmGlobalVisualStudioGenerator.cxx cmGlobalVisualStudioGenerator.h + cmGlobalVisualStudioVersionedGenerator.h + cmGlobalVisualStudioVersionedGenerator.cxx cmIDEFlagTable.h cmIDEOptions.cxx cmIDEOptions.h diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index a257cbc..1a300f2 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 13) -set(CMake_VERSION_PATCH 20181217) +set(CMake_VERSION_PATCH 20190116) #set(CMake_VERSION_RC 1) diff --git a/Source/CPack/OSXScriptLauncher.cxx b/Source/CPack/OSXScriptLauncher.cxx index d3de02b..4966d09 100644 --- a/Source/CPack/OSXScriptLauncher.cxx +++ b/Source/CPack/OSXScriptLauncher.cxx @@ -46,8 +46,7 @@ int main(int argc, char* argv[]) // get the file system path of the url as a cstring // in an encoding suitable for posix apis - if (CFURLGetFileSystemRepresentation(scriptFileURL, true, path, PATH_MAX) == - false) { + if (!CFURLGetFileSystemRepresentation(scriptFileURL, true, path, PATH_MAX)) { DebugError("CFURLGetFileSystemRepresentation failed"); return 1; } diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h index 128a04d..f8c7644 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.h +++ b/Source/CPack/WiX/cmCPackWIXGenerator.h @@ -28,20 +28,20 @@ public: ~cmCPackWIXGenerator(); protected: - virtual int InitializeInternal(); + int InitializeInternal() override; - virtual int PackageFiles(); + int PackageFiles() override; - virtual const char* GetOutputExtension() { return ".msi"; } + const char* GetOutputExtension() override { return ".msi"; } - virtual enum CPackSetDestdirSupport SupportsSetDestdir() const + enum CPackSetDestdirSupport SupportsSetDestdir() const override { return SETDESTDIR_UNSUPPORTED; } - virtual bool SupportsAbsoluteDestination() const { return false; } + bool SupportsAbsoluteDestination() const override { return false; } - virtual bool SupportsComponentInstallation() const { return true; } + bool SupportsComponentInstallation() const override { return true; } private: typedef std::map<std::string, std::string> id_map_t; diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index ee1070f..1756218 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -10,6 +10,7 @@ #include "cmWorkingDirectory.h" #include <cstring> +#include <map> #include <ostream> #include <utility> #include <vector> @@ -111,13 +112,15 @@ int cmCPackArchiveGenerator::addOneComponentToArchive( return 0; \ } \ cmArchiveWrite archive(gf, this->Compress, this->ArchiveFormat); \ - if (!(archive)) { \ - cmCPackLogger(cmCPackLog::LOG_ERROR, \ - "Problem to create archive <" \ - << (filename) << ">, ERROR = " << (archive).GetError() \ - << std::endl); \ - return 0; \ - } + do { \ + if (!(archive)) { \ + cmCPackLogger(cmCPackLog::LOG_ERROR, \ + "Problem to create archive <" \ + << (filename) << ">, ERROR = " << (archive).GetError() \ + << std::endl); \ + return 0; \ + } \ + } while (false) int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup) { diff --git a/Source/CPack/cmCPackExternalGenerator.cxx b/Source/CPack/cmCPackExternalGenerator.cxx index 9f7b236..ff69418 100644 --- a/Source/CPack/cmCPackExternalGenerator.cxx +++ b/Source/CPack/cmCPackExternalGenerator.cxx @@ -13,6 +13,7 @@ #include "cmsys/FStream.hxx" +#include <map> #include <utility> #include <vector> diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx index 2fcd1a8..1e6b118 100644 --- a/Source/CPack/cmCPackFreeBSDGenerator.cxx +++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx @@ -257,13 +257,8 @@ void cmCPackFreeBSDGenerator::write_manifest_fields( static bool ignore_file(const std::string& filename) { struct stat statbuf; - - if (!((stat(filename.c_str(), &statbuf) >= 0) && - ((statbuf.st_mode & S_IFMT) == S_IFREG))) { - return true; - } - // May be other reasons to return false - return false; + return stat(filename.c_str(), &statbuf) < 0 || + (statbuf.st_mode & S_IFMT) != S_IFREG; } // Write the given list of @p files to the manifest stream @p s, diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index ef0d118..e55ea87 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -6,6 +6,7 @@ #include <sstream> #include <stdio.h> #include <string> +#include <vector> #include "cmCPackGenerator.h" #include "cmCPackLog.h" diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 65b4976..32f7496 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -7,6 +7,7 @@ #include "cmCTestGenericHandler.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmake.h" @@ -95,7 +96,7 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() std::string e = "could not create generator named \""; e += cmakeGeneratorName; e += "\""; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e); cmSystemTools::SetFatalErrorOccured(); return nullptr; } diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index a8309d9..361883c 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -357,14 +357,18 @@ int cmCTestBuildHandler::ProcessHandler() // Pre-compile regular expressions objects for all regular expressions #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \ - regexes.clear(); \ - cmCTestOptionalLog(this->CTest, DEBUG, \ - this << "Add " #regexes << std::endl, this->Quiet); \ - for (std::string const& s : (strings)) { \ + do { \ + regexes.clear(); \ cmCTestOptionalLog(this->CTest, DEBUG, \ - "Add " #strings ": " << s << std::endl, this->Quiet); \ - (regexes).push_back(s.c_str()); \ - } + this << "Add " #regexes << std::endl, this->Quiet); \ + for (std::string const& s : (strings)) { \ + cmCTestOptionalLog(this->CTest, DEBUG, \ + "Add " #strings ": " << s << std::endl, \ + this->Quiet); \ + (regexes).push_back(s.c_str()); \ + } \ + } while (false) + cmCTestBuildHandlerPopulateRegexVector(this->CustomErrorMatches, this->ErrorMatchRegex); cmCTestBuildHandlerPopulateRegexVector(this->CustomErrorExceptions, @@ -503,10 +507,7 @@ public: : FTC(ftc) { } - FragmentCompare() - : FTC(nullptr) - { - } + FragmentCompare() {} bool operator()(std::string const& l, std::string const& r) const { // Order files by modification time. Use lexicographic order @@ -520,7 +521,7 @@ public: } private: - cmFileTimeComparison* FTC; + cmFileTimeComparison* FTC = nullptr; }; void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml) diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 1d9a5f7..fbd1038 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -57,7 +57,6 @@ public: { this->CommandLineStrings.clear(); this->CommandLineStrings.push_back(command); - ; } void AddArgument(const char* arg) { diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 97c6b4f..4ede3d4 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -475,15 +475,9 @@ private: { std::string Name; std::string EMail; - unsigned long Time; - long TimeZone; - Person() - : Name() - , EMail() - , Time(0) - , TimeZone(0) - { - } + unsigned long Time = 0; + long TimeZone = 0; + Person() {} }; void ParsePerson(const char* str, Person& person) diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index c63694d..57a14ef 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -5,9 +5,9 @@ #include "cmCTest.h" #include "cmCTestGenericHandler.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmWorkingDirectory.h" -#include "cmake.h" #include <cstring> #include <sstream> @@ -289,7 +289,7 @@ bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg) if (this->Values[k]) { std::ostringstream e; e << "Called with more than one value for " << this->Arguments[k]; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); this->ArgumentDoing = ArgumentDoingError; return true; } diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index f026001..8867323 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -6,9 +6,13 @@ #include "cmCTest.h" #include "cmCTestRunTest.h" #include "cmCTestTestHandler.h" +#include "cmDuration.h" +#include "cmListFileCache.h" #include "cmSystemTools.h" #include "cmWorkingDirectory.h" +#include "cm_jsoncpp_value.h" +#include "cm_jsoncpp_writer.h" #include "cm_uv.h" #include "cmUVSignalHackRAII.h" // IWYU pragma: keep @@ -20,13 +24,19 @@ #include <chrono> #include <cstring> #include <iomanip> +#include <iostream> #include <list> #include <math.h> #include <sstream> #include <stack> #include <stdlib.h> +#include <unordered_map> #include <utility> +namespace cmsys { +class RegularExpression; +} + class TestComparator { public: @@ -725,9 +735,330 @@ void cmCTestMultiProcessHandler::MarkFinished() cmSystemTools::RemoveFile(fname); } +static Json::Value DumpToJsonArray(const std::set<std::string>& values) +{ + Json::Value jsonArray = Json::arrayValue; + for (auto& it : values) { + jsonArray.append(it); + } + return jsonArray; +} + +static Json::Value DumpToJsonArray(const std::vector<std::string>& values) +{ + Json::Value jsonArray = Json::arrayValue; + for (auto& it : values) { + jsonArray.append(it); + } + return jsonArray; +} + +static Json::Value DumpRegExToJsonArray( + const std::vector<std::pair<cmsys::RegularExpression, std::string>>& values) +{ + Json::Value jsonArray = Json::arrayValue; + for (auto& it : values) { + jsonArray.append(it.second); + } + return jsonArray; +} + +static Json::Value DumpMeasurementToJsonArray( + const std::map<std::string, std::string>& values) +{ + Json::Value jsonArray = Json::arrayValue; + for (auto& it : values) { + Json::Value measurement = Json::objectValue; + measurement["measurement"] = it.first; + measurement["value"] = it.second; + jsonArray.append(measurement); + } + return jsonArray; +} + +static Json::Value DumpTimeoutAfterMatch( + cmCTestTestHandler::cmCTestTestProperties& testProperties) +{ + Json::Value timeoutAfterMatch = Json::objectValue; + timeoutAfterMatch["timeout"] = testProperties.AlternateTimeout.count(); + timeoutAfterMatch["regex"] = + DumpRegExToJsonArray(testProperties.TimeoutRegularExpressions); + return timeoutAfterMatch; +} + +static Json::Value DumpCTestProperty(std::string const& name, + Json::Value value) +{ + Json::Value property = Json::objectValue; + property["name"] = name; + property["value"] = std::move(value); + return property; +} + +static Json::Value DumpCTestProperties( + cmCTestTestHandler::cmCTestTestProperties& testProperties) +{ + Json::Value properties = Json::arrayValue; + if (!testProperties.AttachOnFail.empty()) { + properties.append(DumpCTestProperty( + "ATTACHED_FILES_ON_FAIL", DumpToJsonArray(testProperties.AttachOnFail))); + } + if (!testProperties.AttachedFiles.empty()) { + properties.append(DumpCTestProperty( + "ATTACHED_FILES", DumpToJsonArray(testProperties.AttachedFiles))); + } + if (testProperties.Cost != 0.0f) { + properties.append( + DumpCTestProperty("COST", static_cast<double>(testProperties.Cost))); + } + if (!testProperties.Depends.empty()) { + properties.append( + DumpCTestProperty("DEPENDS", DumpToJsonArray(testProperties.Depends))); + } + if (testProperties.Disabled) { + properties.append(DumpCTestProperty("DISABLED", testProperties.Disabled)); + } + if (!testProperties.Environment.empty()) { + properties.append(DumpCTestProperty( + "ENVIRONMENT", DumpToJsonArray(testProperties.Environment))); + } + if (!testProperties.ErrorRegularExpressions.empty()) { + properties.append(DumpCTestProperty( + "FAIL_REGULAR_EXPRESSION", + DumpRegExToJsonArray(testProperties.ErrorRegularExpressions))); + } + if (!testProperties.FixturesCleanup.empty()) { + properties.append(DumpCTestProperty( + "FIXTURES_CLEANUP", DumpToJsonArray(testProperties.FixturesCleanup))); + } + if (!testProperties.FixturesRequired.empty()) { + properties.append(DumpCTestProperty( + "FIXTURES_REQUIRED", DumpToJsonArray(testProperties.FixturesRequired))); + } + if (!testProperties.FixturesSetup.empty()) { + properties.append(DumpCTestProperty( + "FIXTURES_SETUP", DumpToJsonArray(testProperties.FixturesSetup))); + } + if (!testProperties.Labels.empty()) { + properties.append( + DumpCTestProperty("LABELS", DumpToJsonArray(testProperties.Labels))); + } + if (!testProperties.Measurements.empty()) { + properties.append(DumpCTestProperty( + "MEASUREMENT", DumpMeasurementToJsonArray(testProperties.Measurements))); + } + if (!testProperties.RequiredRegularExpressions.empty()) { + properties.append(DumpCTestProperty( + "PASS_REGULAR_EXPRESSION", + DumpRegExToJsonArray(testProperties.RequiredRegularExpressions))); + } + if (testProperties.WantAffinity) { + properties.append( + DumpCTestProperty("PROCESSOR_AFFINITY", testProperties.WantAffinity)); + } + if (testProperties.Processors != 1) { + properties.append( + DumpCTestProperty("PROCESSORS", testProperties.Processors)); + } + if (!testProperties.RequiredFiles.empty()) { + properties["REQUIRED_FILES"] = + DumpToJsonArray(testProperties.RequiredFiles); + } + if (!testProperties.LockedResources.empty()) { + properties.append(DumpCTestProperty( + "RESOURCE_LOCK", DumpToJsonArray(testProperties.LockedResources))); + } + if (testProperties.RunSerial) { + properties.append( + DumpCTestProperty("RUN_SERIAL", testProperties.RunSerial)); + } + if (testProperties.SkipReturnCode != -1) { + properties.append( + DumpCTestProperty("SKIP_RETURN_CODE", testProperties.SkipReturnCode)); + } + if (testProperties.ExplicitTimeout) { + properties.append( + DumpCTestProperty("TIMEOUT", testProperties.Timeout.count())); + } + if (!testProperties.TimeoutRegularExpressions.empty()) { + properties.append(DumpCTestProperty( + "TIMEOUT_AFTER_MATCH", DumpTimeoutAfterMatch(testProperties))); + } + if (testProperties.WillFail) { + properties.append(DumpCTestProperty("WILL_FAIL", testProperties.WillFail)); + } + if (!testProperties.Directory.empty()) { + properties.append( + DumpCTestProperty("WORKING_DIRECTORY", testProperties.Directory)); + } + return properties; +} + +class BacktraceData +{ + std::unordered_map<std::string, Json::ArrayIndex> CommandMap; + std::unordered_map<std::string, Json::ArrayIndex> FileMap; + std::unordered_map<cmListFileContext const*, Json::ArrayIndex> NodeMap; + Json::Value Commands = Json::arrayValue; + Json::Value Files = Json::arrayValue; + Json::Value Nodes = Json::arrayValue; + + Json::ArrayIndex AddCommand(std::string const& command) + { + auto i = this->CommandMap.find(command); + if (i == this->CommandMap.end()) { + i = this->CommandMap.emplace(command, this->Commands.size()).first; + this->Commands.append(command); + } + return i->second; + } + + Json::ArrayIndex AddFile(std::string const& file) + { + auto i = this->FileMap.find(file); + if (i == this->FileMap.end()) { + i = this->FileMap.emplace(file, this->Files.size()).first; + this->Files.append(file); + } + return i->second; + } + +public: + bool Add(cmListFileBacktrace const& bt, Json::ArrayIndex& index); + Json::Value Dump(); +}; + +bool BacktraceData::Add(cmListFileBacktrace const& bt, Json::ArrayIndex& index) +{ + if (bt.Empty()) { + return false; + } + cmListFileContext const* top = &bt.Top(); + auto found = this->NodeMap.find(top); + if (found != this->NodeMap.end()) { + index = found->second; + return true; + } + Json::Value entry = Json::objectValue; + entry["file"] = this->AddFile(top->FilePath); + if (top->Line) { + entry["line"] = static_cast<int>(top->Line); + } + if (!top->Name.empty()) { + entry["command"] = this->AddCommand(top->Name); + } + Json::ArrayIndex parent; + if (this->Add(bt.Pop(), parent)) { + entry["parent"] = parent; + } + index = this->NodeMap[top] = this->Nodes.size(); + this->Nodes.append(std::move(entry)); // NOLINT(*) + return true; +} + +Json::Value BacktraceData::Dump() +{ + Json::Value backtraceGraph; + this->CommandMap.clear(); + this->FileMap.clear(); + this->NodeMap.clear(); + backtraceGraph["commands"] = std::move(this->Commands); + backtraceGraph["files"] = std::move(this->Files); + backtraceGraph["nodes"] = std::move(this->Nodes); + return backtraceGraph; +} + +static void AddBacktrace(BacktraceData& backtraceGraph, Json::Value& object, + cmListFileBacktrace const& bt) +{ + Json::ArrayIndex backtrace; + if (backtraceGraph.Add(bt, backtrace)) { + object["backtrace"] = backtrace; + } +} + +static Json::Value DumpCTestInfo( + cmCTestRunTest& testRun, + cmCTestTestHandler::cmCTestTestProperties& testProperties, + BacktraceData& backtraceGraph) +{ + Json::Value testInfo = Json::objectValue; + // test name should always be present + testInfo["name"] = testProperties.Name; + std::string const& config = testRun.GetCTest()->GetConfigType(); + if (!config.empty()) { + testInfo["config"] = config; + } + std::string const& command = testRun.GetActualCommand(); + if (!command.empty()) { + std::vector<std::string> commandAndArgs; + commandAndArgs.push_back(command); + const std::vector<std::string>& args = testRun.GetArguments(); + if (!args.empty()) { + commandAndArgs.reserve(args.size() + 1); + commandAndArgs.insert(commandAndArgs.end(), args.begin(), args.end()); + } + testInfo["command"] = DumpToJsonArray(commandAndArgs); + } + Json::Value properties = DumpCTestProperties(testProperties); + if (!properties.empty()) { + testInfo["properties"] = properties; + } + if (!testProperties.Backtrace.Empty()) { + AddBacktrace(backtraceGraph, testInfo, testProperties.Backtrace); + } + return testInfo; +} + +static Json::Value DumpVersion(int major, int minor) +{ + Json::Value version = Json::objectValue; + version["major"] = major; + version["minor"] = minor; + return version; +} + +void cmCTestMultiProcessHandler::PrintOutputAsJson() +{ + this->TestHandler->SetMaxIndex(this->FindMaxIndex()); + + Json::Value result = Json::objectValue; + result["kind"] = "ctestInfo"; + result["version"] = DumpVersion(1, 0); + + BacktraceData backtraceGraph; + Json::Value tests = Json::arrayValue; + for (auto& it : this->Properties) { + cmCTestTestHandler::cmCTestTestProperties& p = *it.second; + + // Don't worry if this fails, we are only showing the test list, not + // running the tests + cmWorkingDirectory workdir(p.Directory); + cmCTestRunTest testRun(*this); + testRun.SetIndex(p.Index); + testRun.SetTestProperties(&p); + testRun.ComputeArguments(); + + Json::Value testInfo = DumpCTestInfo(testRun, p, backtraceGraph); + tests.append(testInfo); + } + result["backtraceGraph"] = backtraceGraph.Dump(); + result["tests"] = std::move(tests); + + Json::StreamWriterBuilder builder; + builder["indentation"] = " "; + std::unique_ptr<Json::StreamWriter> jout(builder.newStreamWriter()); + jout->write(result, &std::cout); +} + // For ShowOnly mode void cmCTestMultiProcessHandler::PrintTestList() { + if (this->CTest->GetOutputAsJson()) { + PrintOutputAsJson(); + return; + } + this->TestHandler->SetMaxIndex(this->FindMaxIndex()); int count = 0; diff --git a/Source/CTest/cmCTestMultiProcessHandler.h b/Source/CTest/cmCTestMultiProcessHandler.h index 3927a8a..93bb880 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.h +++ b/Source/CTest/cmCTestMultiProcessHandler.h @@ -51,6 +51,7 @@ public: void SetParallelLevel(size_t); void SetTestLoad(unsigned long load); virtual void RunTests(); + void PrintOutputAsJson(); void PrintTestList(); void PrintLabels(); diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h index 10dceca..c786413 100644 --- a/Source/CTest/cmCTestRunTest.h +++ b/Source/CTest/cmCTestRunTest.h @@ -78,6 +78,10 @@ public: cmCTest* GetCTest() const { return this->CTest; } + std::string& GetActualCommand() { return this->ActualCommand; } + + const std::vector<std::string>& GetArguments() { return this->Arguments; } + void FinalizeTest(); bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; } diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx index 43bd636..76a1830 100644 --- a/Source/CTest/cmCTestSubmitCommand.cxx +++ b/Source/CTest/cmCTestSubmitCommand.cxx @@ -6,8 +6,8 @@ #include "cmCTestGenericHandler.h" #include "cmCTestSubmitHandler.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" -#include "cmake.h" #include <sstream> @@ -203,7 +203,7 @@ bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg) } else { std::ostringstream e; e << "Part name \"" << arg << "\" is invalid."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); this->ArgumentDoing = ArgumentDoingError; } return true; @@ -216,7 +216,7 @@ bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg) std::ostringstream e; e << "File \"" << arg << "\" does not exist. Cannot submit " << "a non-existent file."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); this->ArgumentDoing = ArgumentDoingError; } return true; diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 67c669c..3042480 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -119,7 +119,6 @@ static size_t cmCTestSubmitHandlerCurlDebugCallback(CURL* /*unused*/, } cmCTestSubmitHandler::cmCTestSubmitHandler() - : HTTPProxy() { this->Initialize(); } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 2e1bb0a..9fd2299 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2147,6 +2147,32 @@ bool cmCTestTestHandler::SetTestsProperties( for (std::string const& t : tests) { for (cmCTestTestProperties& rt : this->TestList) { if (t == rt.Name) { + if (key == "_BACKTRACE_TRIPLES") { + std::vector<std::string> triples; + // allow empty args in the triples + cmSystemTools::ExpandListArgument(val, triples, true); + + // Ensure we have complete triples otherwise the data is corrupt. + if (triples.size() % 3 == 0) { + cmState state; + rt.Backtrace = cmListFileBacktrace(state.CreateBaseSnapshot()); + + // the first entry represents the top of the trace so we need to + // reconstruct the backtrace in reverse + for (size_t i = triples.size(); i >= 3; i -= 3) { + cmListFileContext fc; + fc.FilePath = triples[i - 3]; + long line = 0; + if (!cmSystemTools::StringToLong(triples[i - 2].c_str(), + &line)) { + line = 0; + } + fc.Line = line; + fc.Name = triples[i - 1]; + rt.Backtrace = rt.Backtrace.Push(fc); + } + } + } if (key == "WILL_FAIL") { rt.WillFail = cmSystemTools::IsOn(val); } diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index bcacf23..0b557db 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -7,6 +7,7 @@ #include "cmCTestGenericHandler.h" #include "cmDuration.h" +#include "cmListFileCache.h" #include "cmsys/RegularExpression.hxx" #include <chrono> @@ -141,6 +142,8 @@ public: std::set<std::string> FixturesCleanup; std::set<std::string> FixturesRequired; std::set<std::string> RequireSuccessDepends; + // Private test generator properties used to track backtraces + cmListFileBacktrace Backtrace; }; struct cmCTestTestResult diff --git a/Source/CTest/cmCTestUploadCommand.cxx b/Source/CTest/cmCTestUploadCommand.cxx index ec78c1e..2fe2cd3 100644 --- a/Source/CTest/cmCTestUploadCommand.cxx +++ b/Source/CTest/cmCTestUploadCommand.cxx @@ -9,8 +9,8 @@ #include "cmCTestGenericHandler.h" #include "cmCTestUploadHandler.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" -#include "cmake.h" cmCTestGenericHandler* cmCTestUploadCommand::InitializeHandler() { @@ -58,7 +58,7 @@ bool cmCTestUploadCommand::CheckArgumentValue(std::string const& arg) std::ostringstream e; e << "File \"" << arg << "\" does not exist. Cannot submit " << "a non-existent file."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); this->ArgumentDoing = ArgumentDoingError; return false; } diff --git a/Source/CTest/cmParseMumpsCoverage.cxx b/Source/CTest/cmParseMumpsCoverage.cxx index 18412ba..488d237 100644 --- a/Source/CTest/cmParseMumpsCoverage.cxx +++ b/Source/CTest/cmParseMumpsCoverage.cxx @@ -9,6 +9,7 @@ #include <map> #include <string> #include <utility> +#include <vector> cmParseMumpsCoverage::cmParseMumpsCoverage( cmCTestCoverageHandlerContainer& cont, cmCTest* ctest) diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index c4cf046..7737f65 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -7,7 +7,6 @@ #include "cmCTestTestHandler.h" #include "cmsys/Process.h" -#include <algorithm> #include <fcntl.h> #include <iostream> #include <signal.h> @@ -15,6 +14,7 @@ #if !defined(_WIN32) # include <unistd.h> #endif +#include <utility> #define CM_PROCESS_BUF_SIZE 65536 diff --git a/Source/LexerParser/cmCommandArgumentLexer.cxx b/Source/LexerParser/cmCommandArgumentLexer.cxx index 6b4fc85..5879912 100644 --- a/Source/LexerParser/cmCommandArgumentLexer.cxx +++ b/Source/LexerParser/cmCommandArgumentLexer.cxx @@ -664,12 +664,14 @@ Modify cmCommandArgumentLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #include "cmCommandArgumentParserHelper.h" /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = yyextra->LexInput(buf, max_size); } + do { result = yyextra->LexInput(buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmCommandArgumentParserTokens.h" @@ -2246,3 +2248,5 @@ void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes) BEGIN(ESCAPES); } } + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmCommandArgumentLexer.in.l b/Source/LexerParser/cmCommandArgumentLexer.in.l index 5927b9e..010d54b 100644 --- a/Source/LexerParser/cmCommandArgumentLexer.in.l +++ b/Source/LexerParser/cmCommandArgumentLexer.in.l @@ -18,12 +18,14 @@ Modify cmCommandArgumentLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #include "cmCommandArgumentParserHelper.h" /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = yyextra->LexInput(buf, max_size); } + do { result = yyextra->LexInput(buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmCommandArgumentParserTokens.h" @@ -145,3 +147,5 @@ void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes) BEGIN(ESCAPES); } } + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmDependsJavaLexer.cxx b/Source/LexerParser/cmDependsJavaLexer.cxx index 36cac61..d703e3c 100644 --- a/Source/LexerParser/cmDependsJavaLexer.cxx +++ b/Source/LexerParser/cmDependsJavaLexer.cxx @@ -860,6 +860,8 @@ Modify cmDependsJavaLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #include <iostream> #include "cmDependsJavaParserHelper.h" @@ -867,7 +869,7 @@ Modify cmDependsJavaLexer.cxx: /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = yyextra->LexInput(buf, max_size); } + do { result = yyextra->LexInput(buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmDependsJavaParserTokens.h" @@ -2811,3 +2813,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) } #define YYTABLES_NAME "yytables" + +/*--------------------------------------------------------------------------*/ + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmDependsJavaLexer.in.l b/Source/LexerParser/cmDependsJavaLexer.in.l index 01a0fa3..3dd3c22 100644 --- a/Source/LexerParser/cmDependsJavaLexer.in.l +++ b/Source/LexerParser/cmDependsJavaLexer.in.l @@ -18,6 +18,8 @@ Modify cmDependsJavaLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #include <iostream> #include "cmDependsJavaParserHelper.h" @@ -25,7 +27,7 @@ Modify cmDependsJavaLexer.cxx: /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = yyextra->LexInput(buf, max_size); } + do { result = yyextra->LexInput(buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmDependsJavaParserTokens.h" @@ -173,3 +175,7 @@ null { PRIMITIVE; return jp_NULLLITERAL; } } %% + +/*--------------------------------------------------------------------------*/ + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmDependsJavaParser.cxx b/Source/LexerParser/cmDependsJavaParser.cxx index 5400a10..e83afa9 100644 --- a/Source/LexerParser/cmDependsJavaParser.cxx +++ b/Source/LexerParser/cmDependsJavaParser.cxx @@ -107,7 +107,7 @@ static void cmDependsJava_yyerror(yyscan_t yyscanner, const char* message); #define YYMAXDEPTH 1000000 -#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp); +#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp) #define jpElementStart(cnt) yyGetParser->PrepareElement(&yyval) #define jpStoreClass(str) yyGetParser->AddClassFound(str); yyGetParser->DeallocateParserType(&(str)) /* Disable some warnings in the generated code. */ diff --git a/Source/LexerParser/cmDependsJavaParser.y b/Source/LexerParser/cmDependsJavaParser.y index a4e9c5d..d15cffc 100644 --- a/Source/LexerParser/cmDependsJavaParser.y +++ b/Source/LexerParser/cmDependsJavaParser.y @@ -36,7 +36,7 @@ static void cmDependsJava_yyerror(yyscan_t yyscanner, const char* message); #define YYMAXDEPTH 1000000 -#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp); +#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp) #define jpElementStart(cnt) yyGetParser->PrepareElement(&yyval) #define jpStoreClass(str) yyGetParser->AddClassFound(str); yyGetParser->DeallocateParserType(&(str)) /* Disable some warnings in the generated code. */ diff --git a/Source/LexerParser/cmExprLexer.cxx b/Source/LexerParser/cmExprLexer.cxx index cb24687..72e59b6 100644 --- a/Source/LexerParser/cmExprLexer.cxx +++ b/Source/LexerParser/cmExprLexer.cxx @@ -664,12 +664,14 @@ Modify cmExprLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #include "cmExprParserHelper.h" /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = yyextra->LexInput(buf, max_size); } + do { result = yyextra->LexInput(buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmExprParserTokens.h" @@ -2223,3 +2225,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) } #define YYTABLES_NAME "yytables" + +/*--------------------------------------------------------------------------*/ + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmExprLexer.in.l b/Source/LexerParser/cmExprLexer.in.l index 2197c2a..f8a4224 100644 --- a/Source/LexerParser/cmExprLexer.in.l +++ b/Source/LexerParser/cmExprLexer.in.l @@ -18,12 +18,14 @@ Modify cmExprLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #include "cmExprParserHelper.h" /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = yyextra->LexInput(buf, max_size); } + do { result = yyextra->LexInput(buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmExprParserTokens.h" @@ -61,3 +63,7 @@ Modify cmExprLexer.cxx: . { yyextra->UnexpectedChar(yytext[0]); } %% + +/*--------------------------------------------------------------------------*/ + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmFortranLexer.cxx b/Source/LexerParser/cmFortranLexer.cxx index 82048df..bcda77c 100644 --- a/Source/LexerParser/cmFortranLexer.cxx +++ b/Source/LexerParser/cmFortranLexer.cxx @@ -838,6 +838,8 @@ Modify cmFortranLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #undef YY_NO_UNPUT #define cmFortranLexer_cxx @@ -846,7 +848,7 @@ Modify cmFortranLexer.cxx: /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = cmFortranParser_Input(yyextra, buf, max_size); } + do { result = cmFortranParser_Input(yyextra, buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmFortranParserTokens.h" @@ -2610,3 +2612,5 @@ YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner) struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; return YY_CURRENT_BUFFER; } + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmFortranLexer.in.l b/Source/LexerParser/cmFortranLexer.in.l index b7e837b..3d38a7d 100644 --- a/Source/LexerParser/cmFortranLexer.in.l +++ b/Source/LexerParser/cmFortranLexer.in.l @@ -27,6 +27,8 @@ Modify cmFortranLexer.cxx: /* IWYU pragma: no_forward_declare yyguts_t */ +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + #undef YY_NO_UNPUT #define cmFortranLexer_cxx @@ -35,7 +37,7 @@ Modify cmFortranLexer.cxx: /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = cmFortranParser_Input(yyextra, buf, max_size); } + do { result = cmFortranParser_Input(yyextra, buf, max_size); } while (0) /* Include the set of tokens from the parser. */ #include "cmFortranParserTokens.h" @@ -183,3 +185,5 @@ YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner) struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; return YY_CURRENT_BUFFER; } + +#endif /* __clang_analyzer__ */ diff --git a/Source/LexerParser/cmListFileLexer.c b/Source/LexerParser/cmListFileLexer.c index eb37337..c726415 100644 --- a/Source/LexerParser/cmListFileLexer.c +++ b/Source/LexerParser/cmListFileLexer.c @@ -805,7 +805,7 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); } + do { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); } while (0) /*--------------------------------------------------------------------------*/ diff --git a/Source/LexerParser/cmListFileLexer.in.l b/Source/LexerParser/cmListFileLexer.in.l index 23c7e49..6a6fb5f 100644 --- a/Source/LexerParser/cmListFileLexer.in.l +++ b/Source/LexerParser/cmListFileLexer.in.l @@ -57,7 +57,7 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); /* Replace the lexer input function. */ #undef YY_INPUT #define YY_INPUT(buf, result, max_size) \ - { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); } + do { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); } while (0) /*--------------------------------------------------------------------------*/ %} diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 53f5593..a840f17 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -10,11 +10,11 @@ #include "cmCustomCommandLines.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSourceFile.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -361,7 +361,7 @@ bool cmAddCustomCommandCommand::InitialPass( } else { bool issueMessage = true; std::ostringstream e; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0050)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0050) << "\n"; @@ -372,7 +372,7 @@ bool cmAddCustomCommandCommand::InitialPass( case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; break; } @@ -380,7 +380,7 @@ bool cmAddCustomCommandCommand::InitialPass( e << "The SOURCE signatures of add_custom_command are no longer " "supported."; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index ddd9b70..8240d3e 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -9,10 +9,10 @@ #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -183,19 +183,19 @@ bool cmAddCustomTargetCommand::InitialPass( if (commandLines.empty() && !byproducts.empty()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "BYPRODUCTS may not be specified without any COMMAND"); return true; } if (commandLines.empty() && uses_terminal) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "USES_TERMINAL may not be specified without any COMMAND"); return true; } if (commandLines.empty() && command_expand_lists) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "COMMAND_EXPAND_LISTS may not be specified without any COMMAND"); return true; } diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx index a73b57e..021bd29 100644 --- a/Source/cmAddDependenciesCommand.cxx +++ b/Source/cmAddDependenciesCommand.cxx @@ -5,8 +5,8 @@ #include <sstream> #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -24,7 +24,7 @@ bool cmAddDependenciesCommand::InitialPass( std::ostringstream e; e << "Cannot add target-level dependencies to alias target \"" << target_name << "\".\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } if (cmTarget* target = this->Makefile->FindTargetToUse(target_name)) { std::vector<std::string>::const_iterator s = args.begin(); @@ -40,7 +40,7 @@ bool cmAddDependenciesCommand::InitialPass( << "by the add_executable, add_library, or add_custom_target commands. " << "If you want to add file-level dependencies see the DEPENDS option " << "of the add_custom_target and add_custom_command commands."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } return true; diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index fae8063..5149333 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -7,11 +7,11 @@ #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -259,7 +259,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args, << (type == cmStateEnums::SHARED_LIBRARY ? "SHARED" : "MODULE") << " option but the target platform does not support dynamic linking. " "Building a STATIC library instead. This may lead to problems."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); type = cmStateEnums::STATIC_LIBRARY; } @@ -275,7 +275,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args, if (!this->Makefile->GetGlobalGenerator()->HasKnownObjectFileLocation( &reason)) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The OBJECT library type may not be used for IMPORTED libraries" + reason + "."); return true; @@ -307,7 +307,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args, // A non-imported target may not have UNKNOWN type. if (type == cmStateEnums::UNKNOWN_LIBRARY) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The UNKNOWN library type may be used only for IMPORTED libraries."); return true; } diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index bbd3e8e..2f8e675 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -396,6 +396,12 @@ constexpr #endif +template <typename T> +int isize(const T& t) +{ + return static_cast<int>(cm::size(t)); +} + #if __cplusplus >= 201402L || defined(_MSVC_LANG) && _MSVC_LANG >= 201402L using std::cbegin; diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 3f2e784..6e5109a 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -135,7 +135,7 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, return; } break; - }; + } #if !defined(_WIN32) || defined(__CYGWIN__) if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK) { this->Error = "archive_read_disk_set_standard_lookup: "; diff --git a/Source/cmAuxSourceDirectoryCommand.cxx b/Source/cmAuxSourceDirectoryCommand.cxx index 1f9f580..106e7a7 100644 --- a/Source/cmAuxSourceDirectoryCommand.cxx +++ b/Source/cmAuxSourceDirectoryCommand.cxx @@ -5,6 +5,7 @@ #include "cmsys/Directory.hxx" #include <algorithm> #include <stddef.h> +#include <utility> #include "cmAlgorithms.h" #include "cmMakefile.h" diff --git a/Source/cmBreakCommand.cxx b/Source/cmBreakCommand.cxx index 3772c6f..d07898f 100644 --- a/Source/cmBreakCommand.cxx +++ b/Source/cmBreakCommand.cxx @@ -6,8 +6,8 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" -#include "cmake.h" // cmBreakCommand bool cmBreakCommand::InitialPass(std::vector<std::string> const& args, @@ -16,7 +16,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args, if (!this->Makefile->IsLoopBlock()) { bool issueMessage = true; std::ostringstream e; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0055)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0055) << "\n"; @@ -27,7 +27,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args, case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; break; } @@ -35,7 +35,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args, e << "A BREAK command was found outside of a proper " "FOREACH or WHILE loop scope."; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } @@ -46,7 +46,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args, if (!args.empty()) { bool issueMessage = true; std::ostringstream e; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0055)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0055) << "\n"; @@ -57,14 +57,14 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args, case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; break; } if (issueMessage) { e << "The BREAK command does not accept any arguments."; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx index fd87600..428a0b2 100644 --- a/Source/cmBuildCommand.cxx +++ b/Source/cmBuildCommand.cxx @@ -6,9 +6,9 @@ #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -84,7 +84,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) if (!project_name.empty()) { this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, "Ignoring PROJECT_NAME option because it has no effect."); } diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx index 8822942..54f08bb 100644 --- a/Source/cmCMakeHostSystemInformationCommand.cxx +++ b/Source/cmCMakeHostSystemInformationCommand.cxx @@ -10,7 +10,7 @@ #if defined(_WIN32) # include "cmAlgorithms.h" # include "cmGlobalGenerator.h" -# include "cmGlobalVisualStudio15Generator.h" +# include "cmGlobalVisualStudioVersionedGenerator.h" # include "cmSystemTools.h" # include "cmVSSetupHelper.h" # define HAVE_VS_SETUP_HELPER @@ -133,15 +133,31 @@ bool cmCMakeHostSystemInformationCommand::GetValue( // If generating for the VS 15 IDE, use the same instance. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 15 ")) { - cmGlobalVisualStudio15Generator* vs15gen = - static_cast<cmGlobalVisualStudio15Generator*>(gg); + cmGlobalVisualStudioVersionedGenerator* vs15gen = + static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg); if (vs15gen->GetVSInstance(value)) { return true; } } // Otherwise, find a VS 15 instance ourselves. - cmVSSetupAPIHelper vsSetupAPIHelper; + cmVSSetupAPIHelper vsSetupAPIHelper(15); + if (vsSetupAPIHelper.GetVSInstanceInfo(value)) { + cmSystemTools::ConvertToUnixSlashes(value); + } + } else if (key == "VS_16_DIR") { + // If generating for the VS 16 IDE, use the same instance. + cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); + if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 16 ")) { + cmGlobalVisualStudioVersionedGenerator* vs16gen = + static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg); + if (vs16gen->GetVSInstance(value)) { + return true; + } + } + + // Otherwise, find a VS 16 instance ourselves. + cmVSSetupAPIHelper vsSetupAPIHelper(16); if (vsSetupAPIHelper.GetVSInstanceInfo(value)) { cmSystemTools::ConvertToUnixSlashes(value); } diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx index 2b51976..4218d81 100644 --- a/Source/cmCMakeMinimumRequired.cxx +++ b/Source/cmCMakeMinimumRequired.cxx @@ -6,9 +6,9 @@ #include <stdio.h> #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmVersion.h" -#include "cmake.h" class cmExecutionStatus; @@ -96,7 +96,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args, e << "CMake " << version_min << " or higher is required. You are running version " << cmVersion::GetCMakeVersion(); - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return true; } @@ -108,7 +108,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args, if (required_major < 2 || (required_major == 2 && required_minor < 4)) { this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, "Compatibility with CMake < 2.4 is not supported by CMake >= 3.0."); this->Makefile->SetPolicyVersion("2.4", version_max); } else { diff --git a/Source/cmCMakePolicyCommand.cxx b/Source/cmCMakePolicyCommand.cxx index 3209ea5..ac30e1a 100644 --- a/Source/cmCMakePolicyCommand.cxx +++ b/Source/cmCMakePolicyCommand.cxx @@ -5,10 +5,10 @@ #include <sstream> #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmState.h" #include "cmStateTypes.h" -#include "cmake.h" class cmExecutionStatus; @@ -146,7 +146,7 @@ bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args) << "The call to cmake_policy(GET " << id << " ...) at which this " << "error appears requests the policy, and this version of CMake " << "requires that the policy be set to NEW before it is checked."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } } diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 22ae340..264c63c 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -347,7 +347,7 @@ static void addLinkLibrary(cmMakefile* mf, std::string const& target, std::ostringstream e; e << "Attempt to add link library \"" << lib << "\" to target \"" << target << "\" which is not built in this directory."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -362,7 +362,7 @@ static void addLinkLibrary(cmMakefile* mf, std::string const& target, << " may not be linked into another target. " << "One may link only to STATIC or SHARED libraries, or " << "to executables with the ENABLE_EXPORTS property set."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); } t->AddLinkLibrary(*mf, lib, llt); @@ -407,7 +407,7 @@ char CCONV* cmExpandVariablesInString(void* arg, const char* source, cmMakefile* mf = static_cast<cmMakefile*>(arg); std::string barf = source; std::string const& result = - mf->ExpandVariablesInString(barf, escapeQuotes, atOnly); + mf->ExpandVariablesInString(barf, escapeQuotes != 0, atOnly != 0); return strdup(result.c_str()); } @@ -475,11 +475,8 @@ int CCONV cmGetTotalArgumentSize(int argc, char** argv) // API for source files. struct cmCPluginAPISourceFile { - cmCPluginAPISourceFile() - : RealSourceFile(nullptr) - { - } - cmSourceFile* RealSourceFile; + cmCPluginAPISourceFile() {} + cmSourceFile* RealSourceFile = nullptr; std::string SourceName; std::string SourceExtension; std::string FullPath; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 7c19864..65c0d91 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -278,6 +278,8 @@ cmCTest::cmCTest() this->ExtraVerbose = false; this->ProduceXML = false; this->ShowOnly = false; + this->OutputAsJson = false; + this->OutputAsJsonVersion = 1; this->RunConfigurationScript = false; this->UseHTTP10 = false; this->PrintLabels = false; @@ -1930,6 +1932,20 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "-N", "--show-only")) { this->ShowOnly = true; } + if (cmSystemTools::StringStartsWith(arg.c_str(), "--show-only=")) { + this->ShowOnly = true; + + // Check if a specific format is requested. Defaults to human readable + // text. + std::string argWithFormat = "--show-only="; + std::string format = arg.substr(argWithFormat.length()); + if (format == "json-v1") { + // Force quiet mode so the only output is the json object model. + this->Quiet = true; + this->OutputAsJson = true; + this->OutputAsJsonVersion = 1; + } + } if (this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1) { i++; @@ -2630,6 +2646,16 @@ bool cmCTest::GetShowOnly() return this->ShowOnly; } +bool cmCTest::GetOutputAsJson() +{ + return this->OutputAsJson; +} + +int cmCTest::GetOutputAsJsonVersion() +{ + return this->OutputAsJsonVersion; +} + int cmCTest::GetMaxTestNameWidth() const { return this->MaxTestNameWidth; @@ -2827,9 +2853,11 @@ static const char* cmCTestStringLogType[] = { "DEBUG", nullptr }; #define cmCTestLogOutputFileLine(stream) \ - if (this->ShowLineNumbers) { \ - (stream) << std::endl << file << ":" << line << " "; \ - } + do { \ + if (this->ShowLineNumbers) { \ + (stream) << std::endl << file << ":" << line << " "; \ + } \ + } while (false) void cmCTest::InitStreams() { diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 7da0e1d..2b40ca3 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -57,10 +57,7 @@ public: /** Representation of one part. */ struct PartInfo { - PartInfo() - : Enabled(false) - { - } + PartInfo() {} void SetName(const std::string& name) { this->Name = name; } const std::string& GetName() const { return this->Name; } @@ -71,7 +68,7 @@ public: std::vector<std::string> SubmitFiles; private: - bool Enabled; + bool Enabled = false; std::string Name; }; #ifdef CMAKE_BUILD_WITH_CMAKE @@ -218,6 +215,10 @@ public: /** Should we only show what we would do? */ bool GetShowOnly(); + bool GetOutputAsJson(); + + int GetOutputAsJsonVersion(); + bool ShouldUseHTTP10() { return this->UseHTTP10; } bool ShouldPrintLabels() { return this->PrintLabels; } @@ -510,6 +511,8 @@ private: t_TestingHandlers TestingHandlers; bool ShowOnly; + bool OutputAsJson; + int OutputAsJsonVersion; /** Map of configuration properties */ typedef std::map<std::string, std::string> CTestConfigurationMap; diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 6ccb3a8..e1d312b 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -11,6 +11,7 @@ #include <string> #include "cmGeneratedFileStream.h" +#include "cmMessageType.h" #include "cmMessenger.h" #include "cmState.h" #include "cmSystemTools.h" @@ -478,7 +479,7 @@ void cmCacheManager::OutputNewlineTruncationWarning(std::ostream& fout, std::string message = "Value of "; message += key; message += " contained a newline; truncating"; - messenger->IssueMessage(cmake::WARNING, message); + messenger->IssueMessage(MessageType::WARNING, message); } std::string comment = "WARNING: Value of "; diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index a269271..b39856e 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -34,20 +34,15 @@ private: struct CacheEntry { std::string Value; - cmStateEnums::CacheEntryType Type; + cmStateEnums::CacheEntryType Type = cmStateEnums::UNINITIALIZED; cmPropertyMap Properties; 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, bool asString = false); - bool Initialized; - CacheEntry() - : Value("") - , Type(cmStateEnums::UNINITIALIZED) - , Initialized(false) - { - } + bool Initialized = false; + CacheEntry() {} }; public: diff --git a/Source/cmCommand.h b/Source/cmCommand.h index 2cc0b88..dfc3e78 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -30,10 +30,7 @@ public: /** * Construct the command. By default it has no makefile. */ - cmCommand() - : Makefile(nullptr) - { - } + cmCommand() {} /** * Need virtual destructor to destroy real command type. @@ -90,7 +87,7 @@ public: void SetError(const std::string& e); protected: - cmMakefile* Makefile; + cmMakefile* Makefile = nullptr; private: std::string Error; diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 2b4ceaa..ca29967 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -6,7 +6,6 @@ #include "cmMakefile.h" #include "cmState.h" #include "cmSystemTools.h" -#include "cmake.h" #include <iostream> #include <sstream> @@ -16,8 +15,6 @@ int cmCommandArgument_yyparse(yyscan_t yyscanner); // cmCommandArgumentParserHelper::cmCommandArgumentParserHelper() { - this->WarnUninitialized = false; - this->CheckSystemVars = false; this->FileLine = -1; this->FileName = nullptr; this->RemoveEmpty = true; @@ -95,23 +92,11 @@ const char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) return this->AddString(ostr.str()); } const char* value = this->Makefile->GetDefinition(var); - if (!value && !this->RemoveEmpty) { - // check to see if we need to print a warning - // if strict mode is on and the variable has - // not been "cleared"/initialized with a set(foo ) call - if (this->WarnUninitialized && !this->Makefile->VariableInitialized(var)) { - if (this->CheckSystemVars || - (this->FileName && - (cmSystemTools::IsSubDirectory( - this->FileName, this->Makefile->GetHomeDirectory()) || - cmSystemTools::IsSubDirectory( - this->FileName, this->Makefile->GetHomeOutputDirectory())))) { - std::ostringstream msg; - msg << "uninitialized variable \'" << var << "\'"; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); - } + if (!value) { + this->Makefile->MaybeWarnUninitialized(var, this->FileName); + if (!this->RemoveEmpty) { + return nullptr; } - return nullptr; } if (this->EscapeQuotes && value) { return this->AddString(cmSystemTools::EscapeQuotes(value)); @@ -286,8 +271,6 @@ void cmCommandArgumentParserHelper::Error(const char* str) void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf) { this->Makefile = mf; - this->WarnUninitialized = mf->GetCMakeInstance()->GetWarnUninitialized(); - this->CheckSystemVars = mf->GetCMakeInstance()->GetCheckSystemVars(); } void cmCommandArgumentParserHelper::SetResult(const char* value) diff --git a/Source/cmCommandArgumentParserHelper.h b/Source/cmCommandArgumentParserHelper.h index 098c000..4dc238e 100644 --- a/Source/cmCommandArgumentParserHelper.h +++ b/Source/cmCommandArgumentParserHelper.h @@ -75,8 +75,6 @@ private: long FileLine; int CurrentLine; int Verbose; - bool WarnUninitialized; - bool CheckSystemVars; bool EscapeQuotes; bool NoEscapeMode; bool ReplaceAtSyntax; diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index 66fb1e6..32a2a62 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -35,16 +35,10 @@ public: struct LinkEntry { std::string Item; - cmGeneratorTarget const* Target; - bool IsSharedDep; - bool IsFlag; - LinkEntry() - : Item() - , Target(nullptr) - , IsSharedDep(false) - , IsFlag(false) - { - } + cmGeneratorTarget const* Target = nullptr; + bool IsSharedDep = false; + bool IsFlag = false; + LinkEntry() {} LinkEntry(LinkEntry const& r) : Item(r.Item) , Target(r.Target) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 27b8599..4274cb4 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -8,6 +8,7 @@ #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOrderDirectories.h" #include "cmOutputConverter.h" #include "cmPolicies.h" @@ -30,7 +31,7 @@ Notes about linking on various platforms: ------------------------------------------------------------------------------ -Linux, FreeBSD, macOS, IRIX, Sun, Windows: +Linux, FreeBSD, macOS, Sun, Windows: Linking to libraries using the full path works fine. @@ -522,7 +523,7 @@ bool cmComputeLinkInformation::Compute() "name." ; /* clang-format on */ - this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(), + this->CMakeInstance->IssueMessage(MessageType::AUTHOR_WARNING, w.str(), this->Target->GetBacktrace()); } @@ -1382,7 +1383,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item, << " " << item << "\n" << "which is a full-path but not a valid library file name."; /* clang-format on */ - this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(), + this->CMakeInstance->IssueMessage(MessageType::AUTHOR_WARNING, w.str(), this->Target->GetBacktrace()); } } @@ -1401,7 +1402,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item, << " " << item << "\n" << "which is a full-path but not a valid library file name."; /* clang-format on */ - this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->CMakeInstance->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->Target->GetBacktrace()); } break; } @@ -1424,7 +1425,7 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories() "CMP0003-WARNING-GIVEN", "1"); std::ostringstream w; this->PrintLinkPolicyDiagnosis(w); - this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(), + this->CMakeInstance->IssueMessage(MessageType::AUTHOR_WARNING, w.str(), this->Target->GetBacktrace()); } case cmPolicies::OLD: @@ -1439,7 +1440,7 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories() std::ostringstream e; e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0003) << "\n"; this->PrintLinkPolicyDiagnosis(e); - this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->CMakeInstance->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->Target->GetBacktrace()); return false; } diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index e00d230..db7eb96 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -30,12 +30,7 @@ public: struct Item { - Item() - : Value() - , IsPath(true) - , Target(nullptr) - { - } + Item() {} Item(std::string const& v, bool p, cmGeneratorTarget const* target = nullptr) : Value(v) @@ -44,8 +39,8 @@ public: { } std::string Value; - bool IsPath; - cmGeneratorTarget const* Target; + bool IsPath = true; + cmGeneratorTarget const* Target = nullptr; }; typedef std::vector<Item> ItemVector; ItemVector const& GetItems() const; diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index f8ac333..fde9750 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -9,6 +9,7 @@ #include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSourceFile.h" #include "cmState.h" @@ -217,7 +218,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) depender->GetType() != cmStateEnums::MODULE_LIBRARY && depender->GetType() != cmStateEnums::OBJECT_LIBRARY) { this->GlobalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "Only executables and libraries may reference target objects.", depender->GetBacktrace()); return; @@ -314,7 +315,7 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index, if (!dependee && !linking && (depender->GetType() != cmStateEnums::GLOBAL_TARGET)) { - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; bool issueMessage = false; std::ostringstream e; switch (depender->GetPolicyStatusCMP0046()) { @@ -327,7 +328,7 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: issueMessage = true; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (issueMessage) { cmake* cm = this->GlobalGenerator->GetCMakeInstance(); diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 3b4206f..33b9cf1 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -11,8 +11,10 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmSystemTools.h" +#include "cmake.h" class cmCommand; class cmTest; @@ -81,7 +83,7 @@ cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile, bool cmConditionEvaluator::IsTrue( const std::vector<cmExpandedCommandArgument>& args, std::string& errorString, - cmake::MessageType& status) + MessageType& status) { errorString.clear(); @@ -123,7 +125,7 @@ bool cmConditionEvaluator::IsTrue( // now at the end there should only be one argument left if (newArgs.size() != 1) { errorString = "Unknown arguments specified"; - status = cmake::FATAL_ERROR; + status = MessageType::FATAL_ERROR; return false; } @@ -155,7 +157,7 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted( "Since the policy is not set the OLD behavior will be used."; this->Makefile.GetCMakeInstance()->IssueMessage( - cmake::AUTHOR_WARNING, e.str(), this->Backtrace); + MessageType::AUTHOR_WARNING, e.str(), this->Backtrace); } } @@ -199,7 +201,7 @@ bool cmConditionEvaluator::IsKeyword(std::string const& keyword, "Since the policy is not set the OLD behavior will be used."; this->Makefile.GetCMakeInstance()->IssueMessage( - cmake::AUTHOR_WARNING, e.str(), this->Backtrace); + MessageType::AUTHOR_WARNING, e.str(), this->Backtrace); } } @@ -269,7 +271,7 @@ bool cmConditionEvaluator::GetBooleanValueOld( // returns the resulting boolean value bool cmConditionEvaluator::GetBooleanValueWithAutoDereference( cmExpandedCommandArgument& newArg, std::string& errorString, - cmake::MessageType& status, bool oneArg) const + MessageType& status, bool oneArg) const { // Use the policy if it is set. if (this->Policy12Status == cmPolicies::NEW) { @@ -288,7 +290,7 @@ bool cmConditionEvaluator::GetBooleanValueWithAutoDereference( errorString = "An argument named \"" + newArg.GetValue() + "\" appears in a conditional statement. " + cmPolicies::GetPolicyWarning(cmPolicies::CMP0012); - status = cmake::AUTHOR_WARNING; + status = MessageType::AUTHOR_WARNING; CM_FALLTHROUGH; case cmPolicies::OLD: return oldResult; @@ -297,7 +299,7 @@ bool cmConditionEvaluator::GetBooleanValueWithAutoDereference( errorString = "An argument named \"" + newArg.GetValue() + "\" appears in a conditional statement. " + cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0012); - status = cmake::FATAL_ERROR; + status = MessageType::FATAL_ERROR; } case cmPolicies::NEW: break; @@ -362,7 +364,7 @@ void cmConditionEvaluator::HandleBinaryOp(bool value, int& reducible, // level 0 processes parenthetical expressions bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status) + MessageType& status) { int reducible; do { @@ -386,7 +388,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, } if (depth) { errorString = "mismatched parenthesis in condition"; - status = cmake::FATAL_ERROR; + status = MessageType::FATAL_ERROR; return false; } // store the reduced args in this vector @@ -419,7 +421,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, //========================================================================= // level one handles most predicates except for NOT bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, - cmake::MessageType&) + MessageType&) { int reducible; do { @@ -485,7 +487,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, "when the policy is set to NEW. " "Since the policy is not set the OLD behavior will be used."; - this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->Makefile.IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } // is a variable defined if (this->IsKeyword(keyDEFINED, *arg) && argP1 != newArgs.end()) { @@ -516,7 +518,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, // level two handles most binary operations except for AND OR bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status) + MessageType& status) { int reducible; std::string def_buf; @@ -547,7 +549,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, std::ostringstream error; error << "Regular expression \"" << rex << "\" cannot compile"; errorString = error.str(); - status = cmake::FATAL_ERROR; + status = MessageType::FATAL_ERROR; return false; } if (regEntry.find(def)) { @@ -682,7 +684,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, "when the policy is set to NEW. " "Since the policy is not set the OLD behavior will be used."; - this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->Makefile.IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } } @@ -696,7 +698,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, // level 3 handles NOT bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status) + MessageType& status) { int reducible; do { @@ -722,7 +724,7 @@ bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs, // level 4 handles AND OR bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status) + MessageType& status) { int reducible; bool lhs; diff --git a/Source/cmConditionEvaluator.h b/Source/cmConditionEvaluator.h index 50f4edc..fc87a2d 100644 --- a/Source/cmConditionEvaluator.h +++ b/Source/cmConditionEvaluator.h @@ -11,8 +11,8 @@ #include "cmExpandedCommandArgument.h" #include "cmListFileCache.h" +#include "cmMessageType.h" #include "cmPolicies.h" -#include "cmake.h" class cmMakefile; @@ -28,7 +28,7 @@ public: // arguments were valid, and if so, was the response true. If there is // an error, the errorString will be set. bool IsTrue(const std::vector<cmExpandedCommandArgument>& args, - std::string& errorString, cmake::MessageType& status); + std::string& errorString, MessageType& status); private: // Filter the given variable definition based on policy CMP0054. @@ -48,7 +48,7 @@ private: bool GetBooleanValueWithAutoDereference(cmExpandedCommandArgument& newArg, std::string& errorString, - cmake::MessageType& status, + MessageType& status, bool oneArg = false) const; void IncrementArguments(cmArgumentList& newArgs, @@ -66,19 +66,18 @@ private: cmArgumentList::iterator& argP2); bool HandleLevel0(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status); + MessageType& status); - bool HandleLevel1(cmArgumentList& newArgs, std::string&, - cmake::MessageType&); + bool HandleLevel1(cmArgumentList& newArgs, std::string&, MessageType&); bool HandleLevel2(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status); + MessageType& status); bool HandleLevel3(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status); + MessageType& status); bool HandleLevel4(cmArgumentList& newArgs, std::string& errorString, - cmake::MessageType& status); + MessageType& status); cmMakefile& Makefile; cmListFileContext ExecutionContext; diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx index 305262d..8224a0f 100644 --- a/Source/cmConfigureFileCommand.cxx +++ b/Source/cmConfigureFileCommand.cxx @@ -5,8 +5,8 @@ #include <sstream> #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -89,7 +89,7 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args, if (!unknown_args.empty()) { std::string msg = "configure_file called with unknown argument(s):\n"; msg += unknown_args; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg); } if (!this->ConfigureFile()) { diff --git a/Source/cmContinueCommand.cxx b/Source/cmContinueCommand.cxx index 2298a05..48f1f41 100644 --- a/Source/cmContinueCommand.cxx +++ b/Source/cmContinueCommand.cxx @@ -4,15 +4,15 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" -#include "cmake.h" // cmContinueCommand bool cmContinueCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus& status) { if (!this->Makefile->IsLoopBlock()) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "A CONTINUE command was found outside of a " "proper FOREACH or WHILE loop scope."); cmSystemTools::SetFatalErrorOccured(); @@ -22,7 +22,7 @@ bool cmContinueCommand::InitialPass(std::vector<std::string> const& args, status.SetContinueInvoked(); if (!args.empty()) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "The CONTINUE command does not accept any " "arguments."); cmSystemTools::SetFatalErrorOccured(); diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 541ae76..a483fd1 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -13,6 +13,7 @@ #include "cmExportTryCompileFileGenerator.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmState.h" @@ -24,10 +25,18 @@ static std::string const kCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN = "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN"; static std::string const kCMAKE_C_COMPILER_TARGET = "CMAKE_C_COMPILER_TARGET"; +static std::string const kCMAKE_C_LINK_NO_PIE_SUPPORTED = + "CMAKE_C_LINK_NO_PIE_SUPPORTED"; +static std::string const kCMAKE_C_LINK_PIE_SUPPORTED = + "CMAKE_C_LINK_PIE_SUPPORTED"; static std::string const kCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN = "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN"; static std::string const kCMAKE_CXX_COMPILER_TARGET = "CMAKE_CXX_COMPILER_TARGET"; +static std::string const kCMAKE_CXX_LINK_NO_PIE_SUPPORTED = + "CMAKE_CXX_LINK_NO_PIE_SUPPORTED"; +static std::string const kCMAKE_CXX_LINK_PIE_SUPPORTED = + "CMAKE_CXX_LINK_PIE_SUPPORTED"; static std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS"; static std::string const kCMAKE_LINK_SEARCH_END_STATIC = "CMAKE_LINK_SEARCH_END_STATIC"; @@ -88,7 +97,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, targetType = cmStateEnums::STATIC_LIBRARY; } else { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, std::string("Invalid value '") + tt + "' for " "CMAKE_TRY_COMPILE_TARGET_TYPE. Only " @@ -230,7 +239,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, CM_FALLTHROUGH; default: this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "Only libraries may be used as try_compile or try_run IMPORTED " "LINK_LIBRARIES. Got " + std::string(tgt->GetName()) + @@ -289,93 +298,95 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, } else { std::ostringstream m; m << "try_compile given unknown argument \"" << argv[i] << "\"."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m.str()); } } if (didCopyFile && copyFile.empty()) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "COPY_FILE must be followed by a file path"); return -1; } if (didCopyFileError && copyFileError.empty()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "COPY_FILE_ERROR must be followed by a variable name"); return -1; } if (didCopyFileError && !didCopyFile) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, "COPY_FILE_ERROR may be used only with COPY_FILE"); + MessageType::FATAL_ERROR, + "COPY_FILE_ERROR may be used only with COPY_FILE"); return -1; } if (didOutputVariable && outputVariable.empty()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "OUTPUT_VARIABLE must be followed by a variable name"); return -1; } if (useSources && sources.empty()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "SOURCES must be followed by at least one source file"); return -1; } if (didCStandard && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, "C_STANDARD allowed only in source file signature."); + MessageType::FATAL_ERROR, + "C_STANDARD allowed only in source file signature."); return -1; } if (didCxxStandard && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "CXX_STANDARD allowed only in source file signature."); return -1; } if (didCudaStandard && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "CUDA_STANDARD allowed only in source file signature."); return -1; } if (didCStandardRequired && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "C_STANDARD_REQUIRED allowed only in source file signature."); return -1; } if (didCxxStandardRequired && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "CXX_STANDARD_REQUIRED allowed only in source file signature."); return -1; } if (didCudaStandardRequired && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "CUDA_STANDARD_REQUIRED allowed only in source file signature."); return -1; } if (didCExtensions && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "C_EXTENSIONS allowed only in source file signature."); return -1; } if (didCxxExtensions && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "CXX_EXTENSIONS allowed only in source file signature."); return -1; } if (didCudaExtensions && !this->SrcFileSignature) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "CUDA_EXTENSIONS allowed only in source file signature."); return -1; } @@ -389,13 +400,13 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, // only valid for srcfile signatures if (!compileDefs.empty()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE"); return -1; } if (!copyFile.empty()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "COPY_FILE specified on a srcdir type TRY_COMPILE"); return -1; } @@ -408,7 +419,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, std::ostringstream e; e << "Attempt at a recursive or nested TRY_COMPILE in directory\n" << " " << this->BinaryDirectory << "\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return -1; } @@ -442,7 +453,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, gg->GetEnabledLanguages(langs); err << cmJoin(langs, " "); err << "\nSee project() command to enable other languages."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, err.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err.str()); return -1; } } @@ -463,7 +474,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, << " " << outFileName << "\n" << cmSystemTools::GetLastSystemError(); /* clang-format on */ - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return -1; } @@ -514,7 +525,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, "(e.g. CMAKE_C_FLAGS_DEBUG) in the test project." ; /* clang-format on */ - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } case cmPolicies::OLD: // OLD behavior is to do nothing. @@ -522,7 +533,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0066)); CM_FALLTHROUGH; case cmPolicies::NEW: { @@ -551,7 +562,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, "in the test project." ; /* clang-format on */ - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } case cmPolicies::OLD: // OLD behavior is to do nothing. @@ -559,7 +570,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0056)); CM_FALLTHROUGH; case cmPolicies::NEW: @@ -598,7 +609,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, tcfg.SetConfig(tcConfig); if (!tcfg.GenerateImportFile()) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "could not write export file."); fclose(fout); return -1; @@ -633,6 +644,16 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, vars.insert(varList.begin(), varList.end()); } + if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0083) == + cmPolicies::NEW) { + // To ensure full support of PIE, propagate cache variables + // driving the link options + vars.insert(kCMAKE_C_LINK_PIE_SUPPORTED); + vars.insert(kCMAKE_C_LINK_NO_PIE_SUPPORTED); + vars.insert(kCMAKE_CXX_LINK_PIE_SUPPORTED); + vars.insert(kCMAKE_CXX_LINK_NO_PIE_SUPPORTED); + } + /* for the TRY_COMPILEs we want to be able to specify the architecture. So the user can set CMAKE_OSX_ARCHITECTURES to i386;ppc and then set CMAKE_TRY_COMPILE_OSX_ARCHITECTURES first to i386 and then to ppc to @@ -716,7 +737,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0067)); case cmPolicies::NEW: // NEW behavior is to honor the language standard variables. @@ -778,7 +799,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, for (std::string const& vi : this->WarnCMP0067) { w << " " << vi << "\n"; } - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } if (testC) { @@ -887,7 +908,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, emsg << this->FindErrorMessage.c_str(); } if (copyFileError.empty()) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, emsg.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str()); return -1; } copyFileErrorMessage = emsg.str(); diff --git a/Source/cmCurl.cxx b/Source/cmCurl.cxx index 0482898..0004f66 100644 --- a/Source/cmCurl.cxx +++ b/Source/cmCurl.cxx @@ -14,11 +14,13 @@ #endif #define check_curl_result(result, errstr) \ - if ((result) != CURLE_OK && (result) != CURLE_NOT_BUILT_IN) { \ - e += e.empty() ? "" : "\n"; \ - e += (errstr); \ - e += ::curl_easy_strerror(result); \ - } + do { \ + if ((result) != CURLE_OK && (result) != CURLE_NOT_BUILT_IN) { \ + e += e.empty() ? "" : "\n"; \ + e += (errstr); \ + e += ::curl_easy_strerror(result); \ + } \ + } while (false) std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile) { diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index e87eb1e..9dcec2f 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -15,13 +15,9 @@ cmCustomCommand::cmCustomCommand(cmMakefile const* mf, , Byproducts(byproducts) , Depends(depends) , CommandLines(commandLines) - , Backtrace() , Comment(comment ? comment : "") , WorkingDirectory(workingDirectory ? workingDirectory : "") , HaveComment(comment != nullptr) - , EscapeAllowMakeVars(false) - , EscapeOldStyle(true) - , CommandExpandLists(false) { if (mf) { this->Backtrace = mf->GetBacktrace(); diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index 4ab5be6..b2794fa 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -47,26 +47,19 @@ private: typedef std::string std_string; public: - Def() - : std_string() - , Exists(false) - , Used(false) - { - } + Def() {} Def(const char* v) : std_string(v ? v : "") , Exists(v ? true : false) - , Used(false) { } Def(const std_string& v) : std_string(v) , Exists(true) - , Used(false) { } - bool Exists; - bool Used; + bool Exists = false; + bool Used = false; }; static Def NoDef; diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 6f1afd7..2acb015 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -15,10 +15,7 @@ cmDepends::cmDepends(cmLocalGenerator* lg, const char* targetDir) : LocalGenerator(lg) - , Verbose(false) - , FileComparison(nullptr) , TargetDirectory(targetDir) - , MaxPath(16384) , Dependee(new char[MaxPath]) , Depender(new char[MaxPath]) { diff --git a/Source/cmDepends.h b/Source/cmDepends.h index 4b9e05a..705d215 100644 --- a/Source/cmDepends.h +++ b/Source/cmDepends.h @@ -96,15 +96,15 @@ protected: cmLocalGenerator* LocalGenerator; // Flag for verbose output. - bool Verbose; - cmFileTimeComparison* FileComparison; + bool Verbose = false; + cmFileTimeComparison* FileComparison = nullptr; std::string Language; // The full path to the target's build directory. std::string TargetDirectory; - size_t MaxPath; + size_t MaxPath = 16384; char* Dependee; char* Depender; diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index f7dd33b..072d116 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -20,7 +20,6 @@ #define INCLUDE_REGEX_TRANSFORM_MARKER "#IncludeRegexTransform: " cmDependsC::cmDependsC() - : ValidDeps(nullptr) { } diff --git a/Source/cmDependsC.h b/Source/cmDependsC.h index 2f76f62..f833888 100644 --- a/Source/cmDependsC.h +++ b/Source/cmDependsC.h @@ -75,16 +75,13 @@ public: struct cmIncludeLines { - cmIncludeLines() - : Used(false) - { - } + cmIncludeLines() {} std::vector<UnscannedEntry> UnscannedEntries; - bool Used; + bool Used = false; }; protected: - const std::map<std::string, DependencyVector>* ValidDeps; + const std::map<std::string, DependencyVector>* ValidDeps = nullptr; std::set<std::string> Encountered; std::queue<UnscannedEntry> Unscanned; diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 310af2d..e51f81e 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -69,7 +69,6 @@ public: }; cmDependsFortran::cmDependsFortran() - : Internal(nullptr) { } diff --git a/Source/cmDependsFortran.h b/Source/cmDependsFortran.h index bee9804..5d96dd4 100644 --- a/Source/cmDependsFortran.h +++ b/Source/cmDependsFortran.h @@ -76,7 +76,7 @@ protected: std::set<std::string> PPDefinitions; // Internal implementation details. - cmDependsFortranInternals* Internal; + cmDependsFortranInternals* Internal = nullptr; private: std::string MaybeConvertToRelativePath(std::string const& base, diff --git a/Source/cmDisallowedCommand.cxx b/Source/cmDisallowedCommand.cxx index ce1965d..418d98c 100644 --- a/Source/cmDisallowedCommand.cxx +++ b/Source/cmDisallowedCommand.cxx @@ -3,7 +3,7 @@ #include "cmDisallowedCommand.h" #include "cmMakefile.h" -#include "cmake.h" +#include "cmMessageType.h" class cmExecutionStatus; @@ -12,7 +12,7 @@ bool cmDisallowedCommand::InitialPass(std::vector<std::string> const& args, { switch (this->Makefile->GetPolicyStatus(this->Policy)) { case cmPolicies::WARN: - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(this->Policy)); break; case cmPolicies::OLD: @@ -20,7 +20,7 @@ bool cmDisallowedCommand::InitialPass(std::vector<std::string> const& args, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: - this->Makefile->IssueMessage(cmake::FATAL_ERROR, this->Message); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, this->Message); return true; } diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 2dfba04..6a817b4 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDocumentation.h" -#include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmDocumentationSection.h" #include "cmRST.h" @@ -55,11 +54,6 @@ cmDocumentation::cmDocumentation() this->ShowGenerators = true; } -cmDocumentation::~cmDocumentation() -{ - cmDeleteAll(this->AllSections); -} - bool cmDocumentation::PrintVersion(std::ostream& os) { /* clang-format off */ @@ -145,10 +139,12 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os) } #define GET_OPT_ARGUMENT(target) \ - if ((i + 1 < argc) && !this->IsOption(argv[i + 1])) { \ - (target) = argv[i + 1]; \ - i = i + 1; \ - }; + do { \ + if ((i + 1 < argc) && !this->IsOption(argv[i + 1])) { \ + (target) = argv[i + 1]; \ + i = i + 1; \ + }; \ + } while (false) void cmDocumentation::WarnFormFromFilename( cmDocumentation::RequestedHelpItem& request, bool& result) @@ -174,20 +170,16 @@ void cmDocumentation::WarnFormFromFilename( void cmDocumentation::addCommonStandardDocSections() { - cmDocumentationSection* sec; - - sec = new cmDocumentationSection("Options", "OPTIONS"); - sec->Append(cmDocumentationStandardOptions); - this->AllSections["Options"] = sec; + cmDocumentationSection sec{ "Options" }; + sec.Append(cmDocumentationStandardOptions); + this->AllSections.emplace("Options", std::move(sec)); } void cmDocumentation::addCMakeStandardDocSections() { - cmDocumentationSection* sec; - - sec = new cmDocumentationSection("Generators", "GENERATORS"); - sec->Append(cmDocumentationGeneratorsHeader); - this->AllSections["Generators"] = sec; + cmDocumentationSection sec{ "Generators" }; + sec.Append(cmDocumentationGeneratorsHeader); + this->AllSections.emplace("Generators", std::move(sec)); } void cmDocumentation::addCTestStandardDocSections() @@ -199,11 +191,7 @@ void cmDocumentation::addCTestStandardDocSections() void cmDocumentation::addCPackStandardDocSections() { - cmDocumentationSection* sec; - - sec = new cmDocumentationSection("Generators", "GENERATORS"); - sec->Append(cmDocumentationGeneratorsHeader); - this->AllSections["Generators"] = sec; + addCMakeStandardDocSections(); } bool cmDocumentation::CheckOptions(int argc, const char* const* argv, @@ -364,91 +352,59 @@ void cmDocumentation::SetName(const std::string& name) } void cmDocumentation::SetSection(const char* name, - cmDocumentationSection* section) + cmDocumentationSection section) { - if (this->AllSections.find(name) != this->AllSections.end()) { - delete this->AllSections[name]; - } - this->AllSections[name] = section; + this->SectionAtName(name) = std::move(section); } void cmDocumentation::SetSection(const char* name, std::vector<cmDocumentationEntry>& docs) { - cmDocumentationSection* sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); - sec->Append(docs); - this->SetSection(name, sec); + cmDocumentationSection sec{ name }; + sec.Append(docs); + this->SetSection(name, std::move(sec)); } void cmDocumentation::SetSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); - sec->Append(docs); - this->SetSection(name, sec); + cmDocumentationSection sec{ name }; + sec.Append(docs); + this->SetSection(name, std::move(sec)); } void cmDocumentation::SetSections( - std::map<std::string, cmDocumentationSection*>& sections) + std::map<std::string, cmDocumentationSection> sections) { - for (auto const& s : sections) { - this->SetSection(s.first.c_str(), s.second); + for (auto& s : sections) { + this->SetSection(s.first.c_str(), std::move(s.second)); } } +cmDocumentationSection& cmDocumentation::SectionAtName(const char* name) +{ + return this->AllSections.emplace(name, cmDocumentationSection{ name }) + .first->second; +} void cmDocumentation::PrependSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Prepend(docs); + this->SectionAtName(name).Prepend(docs); } void cmDocumentation::PrependSection(const char* name, std::vector<cmDocumentationEntry>& docs) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Prepend(docs); + this->SectionAtName(name).Prepend(docs); } void cmDocumentation::AppendSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Append(docs); + this->SectionAtName(name).Append(docs); } void cmDocumentation::AppendSection(const char* name, std::vector<cmDocumentationEntry>& docs) { - cmDocumentationSection* sec = nullptr; - if (this->AllSections.find(name) == this->AllSections.end()) { - sec = - new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); - this->SetSection(name, sec); - } else { - sec = this->AllSections[name]; - } - sec->Append(docs); + this->SectionAtName(name).Append(docs); } void cmDocumentation::AppendSection(const char* name, @@ -631,11 +587,10 @@ bool cmDocumentation::PrintHelpListPolicies(std::ostream& os) bool cmDocumentation::PrintHelpListGenerators(std::ostream& os) { - std::map<std::string, cmDocumentationSection*>::iterator si; - si = this->AllSections.find("Generators"); + const auto si = this->AllSections.find("Generators"); if (si != this->AllSections.end()) { this->Formatter.SetIndent(" "); - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } return true; } @@ -661,29 +616,27 @@ bool cmDocumentation::PrintHelpListVariables(std::ostream& os) bool cmDocumentation::PrintUsage(std::ostream& os) { - std::map<std::string, cmDocumentationSection*>::iterator si; - si = this->AllSections.find("Usage"); + const auto si = this->AllSections.find("Usage"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } return true; } bool cmDocumentation::PrintHelp(std::ostream& os) { - std::map<std::string, cmDocumentationSection*>::iterator si; - si = this->AllSections.find("Usage"); + auto si = this->AllSections.find("Usage"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } si = this->AllSections.find("Options"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } if (this->ShowGenerators) { si = this->AllSections.find("Generators"); if (si != this->AllSections.end()) { - this->Formatter.PrintSection(os, *si->second); + this->Formatter.PrintSection(os, si->second); } } return true; diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index c80bed1..b2ff01a 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -6,13 +6,13 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmDocumentationFormatter.h" +#include "cmDocumentationSection.h" #include <iosfwd> #include <map> #include <string> #include <vector> -class cmDocumentationSection; struct cmDocumentationEntry; /** Class to generate documentation. */ @@ -21,8 +21,6 @@ class cmDocumentation : public cmDocumentationEnums public: cmDocumentation(); - ~cmDocumentation(); - /** * Check command line arguments for documentation options. Returns * true if documentation options are found, and false otherwise. @@ -52,11 +50,11 @@ public: /** Set a section of the documentation. Typical sections include Name, Usage, Description, Options */ - void SetSection(const char* sectionName, cmDocumentationSection* section); + void SetSection(const char* sectionName, cmDocumentationSection section); void SetSection(const char* sectionName, std::vector<cmDocumentationEntry>& docs); void SetSection(const char* sectionName, const char* docs[][2]); - void SetSections(std::map<std::string, cmDocumentationSection*>& sections); + void SetSections(std::map<std::string, cmDocumentationSection> sections); /** Add the documentation to the beginning/end of the section */ void PrependSection(const char* sectionName, const char* docs[][2]); @@ -110,17 +108,15 @@ private: bool ShowGenerators; std::string NameString; - std::map<std::string, cmDocumentationSection*> AllSections; + std::map<std::string, cmDocumentationSection> AllSections; + cmDocumentationSection& SectionAtName(const char* name); std::string CurrentArgument; struct RequestedHelpItem { - RequestedHelpItem() - : HelpType(None) - { - } - cmDocumentationEnums::Type HelpType; + RequestedHelpItem() {} + cmDocumentationEnums::Type HelpType = None; std::string Filename; std::string Argument; }; diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 2267ef9..678e408 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -11,8 +11,6 @@ #include <vector> cmDocumentationFormatter::cmDocumentationFormatter() - : TextWidth(77) - , TextIndent("") { } diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 1f04250..17b63da 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -59,8 +59,8 @@ public: void SetIndent(const char* indent); private: - int TextWidth; - const char* TextIndent; + int TextWidth = 77; + const char* TextIndent = ""; }; #endif diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h index d9e8187..7031b52 100644 --- a/Source/cmDocumentationSection.h +++ b/Source/cmDocumentationSection.h @@ -19,7 +19,7 @@ class cmDocumentationSection { public: /** Create a cmSection, with a special name for man-output mode. */ - cmDocumentationSection(const char* name, const char*) + explicit cmDocumentationSection(const char* name) : Name(name) { } diff --git a/Source/cmExecutionStatus.h b/Source/cmExecutionStatus.h index ac5fe1d..1946231 100644 --- a/Source/cmExecutionStatus.h +++ b/Source/cmExecutionStatus.h @@ -11,13 +11,7 @@ class cmExecutionStatus { public: - cmExecutionStatus() - : ReturnInvoked(false) - , BreakInvoked(false) - , ContinueInvoked(false) - , NestedError(false) - { - } + cmExecutionStatus() {} void Clear() { @@ -40,10 +34,10 @@ public: bool GetNestedError() const { return this->NestedError; } private: - bool ReturnInvoked; - bool BreakInvoked; - bool ContinueInvoked; - bool NestedError; + bool ReturnInvoked = false; + bool BreakInvoked = false; + bool ContinueInvoked = false; + bool NestedError = false; }; #endif diff --git a/Source/cmExpandedCommandArgument.cxx b/Source/cmExpandedCommandArgument.cxx index 1c0a721..650a5ad 100644 --- a/Source/cmExpandedCommandArgument.cxx +++ b/Source/cmExpandedCommandArgument.cxx @@ -3,7 +3,6 @@ #include "cmExpandedCommandArgument.h" cmExpandedCommandArgument::cmExpandedCommandArgument() - : Quoted(false) { } diff --git a/Source/cmExpandedCommandArgument.h b/Source/cmExpandedCommandArgument.h index 302e8db..d71fc92 100644 --- a/Source/cmExpandedCommandArgument.h +++ b/Source/cmExpandedCommandArgument.h @@ -33,7 +33,7 @@ public: private: std::string Value; - bool Quoted; + bool Quoted = false; }; #endif diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index d12ad7f..ced27c9 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -11,11 +11,11 @@ #include "cmGeneratorTarget.h" #include "cmLinkItem.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator() { @@ -92,7 +92,7 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( } w << " set to OLD for target " << target->Target->GetName() << ". " << "The export will only work with CMP0022 set to NEW."; - target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } if (!properties.empty()) { os << "LOCAL_CPP_FEATURES := rtti exceptions\n"; diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 024e641..012355b 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -9,6 +9,7 @@ #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -55,7 +56,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) std::ostringstream e; e << "given target \"" << te->GetName() << "\" more than once."; this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, e.str(), + MessageType::FATAL_ERROR, e.str(), this->LG->GetMakefile()->GetBacktrace()); return false; } @@ -110,7 +111,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) std::string errorMessage; if (!this->PopulateExportProperties(gte, properties, errorMessage)) { this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, errorMessage, + MessageType::FATAL_ERROR, errorMessage, this->LG->GetMakefile()->GetBacktrace()); return false; } @@ -328,7 +329,8 @@ void cmExportBuildFileGenerator::ComplainAboutMissingTarget( << "consider using the APPEND option with multiple separate calls."; this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, e.str(), this->LG->GetMakefile()->GetBacktrace()); + MessageType::FATAL_ERROR, e.str(), + this->LG->GetMakefile()->GetBacktrace()); } std::string cmExportBuildFileGenerator::InstallNameDir( diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index f965a29..722831a 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -12,10 +12,10 @@ #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -25,9 +25,7 @@ class cmExecutionStatus; #endif cmExportCommand::cmExportCommand() - : cmCommand() - , ArgumentGroup() - , Targets(&Helper, "TARGETS") + : Targets(&Helper, "TARGETS") , Append(&Helper, "APPEND", &ArgumentGroup) , ExportSetName(&Helper, "EXPORT", &ArgumentGroup) , Namespace(&Helper, "NAMESPACE", &ArgumentGroup) @@ -281,7 +279,7 @@ void cmExportCommand::ReportRegistryError(std::string const& msg, e << "Windows reported:\n" << " " << cmsys::Encoding::ToNarrow(winmsg); } - this->Makefile->IssueMessage(cmake::WARNING, e.str()); + this->Makefile->IssueMessage(MessageType::WARNING, e.str()); } void cmExportCommand::StorePackageRegistryWin(std::string const& package, @@ -349,7 +347,7 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package, << " " << fname << "\n" << cmSystemTools::GetLastSystemError() << "\n"; /* clang-format on */ - this->Makefile->IssueMessage(cmake::WARNING, e.str()); + this->Makefile->IssueMessage(MessageType::WARNING, e.str()); } } } diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index df27c62..c6b66a3 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -9,6 +9,7 @@ #include "cmLinkItem.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmProperty.h" @@ -17,7 +18,6 @@ #include "cmSystemTools.h" #include "cmTarget.h" #include "cmTargetExport.h" -#include "cmake.h" #include "cmsys/FStream.hxx" #include <assert.h> @@ -214,13 +214,13 @@ static bool checkInterfaceDirs(const std::string& prepro, if (genexPos == 0) { continue; } - cmake::MessageType messageType = cmake::FATAL_ERROR; + MessageType messageType = MessageType::FATAL_ERROR; std::ostringstream e; if (genexPos != std::string::npos) { if (prop == "INTERFACE_INCLUDE_DIRECTORIES") { switch (target->GetPolicyStatusCMP0041()) { case cmPolicies::WARN: - messageType = cmake::WARNING; + messageType = MessageType::WARNING; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n"; break; case cmPolicies::OLD: @@ -275,8 +275,8 @@ static bool checkInterfaceDirs(const std::string& prepro, << (inBinary ? "build" : "source") << " tree:\n \"" << (inBinary ? topBinaryDir : topSourceDir) << "\"" << std::endl; - target->GetLocalGenerator()->IssueMessage(cmake::AUTHOR_WARNING, - s.str()); + target->GetLocalGenerator()->IssueMessage( + MessageType::AUTHOR_WARNING, s.str()); CM_FALLTHROUGH; } case cmPolicies::OLD: @@ -390,7 +390,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( "depend on the configuration, policy values or the link interface " "are " "not supported. Consider using target_include_directories instead."; - lg->IssueMessage(cmake::FATAL_ERROR, e.str()); + lg->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -520,7 +520,7 @@ void getCompatibleInterfaceProperties(cmGeneratorTarget* target, e << "Exporting the target \"" << target->GetName() << "\" is not " "allowed since its linker language cannot be determined"; - lg->IssueMessage(cmake::FATAL_ERROR, e.str()); + lg->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -727,7 +727,8 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpression( this->ReplaceInstallPrefix(input); if (!errorString.empty()) { - target->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, errorString); + target->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR, + errorString); } } @@ -780,7 +781,7 @@ void cmExportFileGenerator::SetImportLinkInterface( "but also has old-style LINK_INTERFACE_LIBRARIES properties " "populated, but it was exported without the " "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties"; - lg->IssueMessage(cmake::FATAL_ERROR, e.str()); + lg->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 93115b6..3821144 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -4,6 +4,7 @@ #include "cmAlgorithms.h" #include "cmExportSet.h" +#include "cmExportSetMap.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" @@ -21,8 +22,6 @@ #include <sstream> #include <utility> -class cmExportSetMap; - cmExportInstallFileGenerator::cmExportInstallFileGenerator( cmInstallExportGenerator* iegen) : IEGen(iegen) diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 07a60de..d70352f 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -33,7 +33,6 @@ http://forums.codeblocks.org/index.php/topic,6789.0.html */ cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator() - : cmExternalMakefileProjectGenerator() { } diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index 28106d1..2fa593c 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -21,9 +21,7 @@ #include <utility> cmExtraCodeLiteGenerator::cmExtraCodeLiteGenerator() - : cmExternalMakefileProjectGenerator() - , ConfigName("NoConfig") - , CpuCount(2) + : ConfigName("NoConfig") { } @@ -61,18 +59,17 @@ void cmExtraCodeLiteGenerator::Generate() // and extract the information for creating the worspace // root makefile for (auto const& it : projectMap) { - const cmMakefile* mf = it.second[0]->GetMakefile(); + cmLocalGenerator* lg = it.second[0]; + const cmMakefile* mf = lg->GetMakefile(); this->ConfigName = GetConfigurationName(mf); - if (it.second[0]->GetCurrentBinaryDirectory() == - it.second[0]->GetBinaryDirectory()) { - workspaceOutputDir = it.second[0]->GetCurrentBinaryDirectory(); - workspaceProjectName = it.second[0]->GetProjectName(); - workspaceSourcePath = it.second[0]->GetSourceDirectory(); + if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) { + workspaceOutputDir = lg->GetCurrentBinaryDirectory(); + workspaceProjectName = lg->GetProjectName(); + workspaceSourcePath = lg->GetSourceDirectory(); workspaceFileName = workspaceOutputDir + "/"; workspaceFileName += workspaceProjectName + ".workspace"; - this->WorkspacePath = it.second[0]->GetCurrentBinaryDirectory(); - ; + this->WorkspacePath = lg->GetCurrentBinaryDirectory(); break; } } diff --git a/Source/cmExtraCodeLiteGenerator.h b/Source/cmExtraCodeLiteGenerator.h index 029054f..dea7ebc 100644 --- a/Source/cmExtraCodeLiteGenerator.h +++ b/Source/cmExtraCodeLiteGenerator.h @@ -23,7 +23,7 @@ class cmExtraCodeLiteGenerator : public cmExternalMakefileProjectGenerator protected: std::string ConfigName; std::string WorkspacePath; - unsigned int CpuCount; + unsigned int CpuCount = 2; protected: std::string GetCodeLiteCompilerName(const cmMakefile* mf) const; diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index adb14ec..5833631 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -5,6 +5,7 @@ #include "cmsys/RegularExpression.hxx" #include <algorithm> #include <assert.h> +#include <map> #include <sstream> #include <stdio.h> #include <utility> @@ -15,6 +16,7 @@ #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSourceFile.h" #include "cmSourceGroup.h" #include "cmState.h" @@ -41,7 +43,6 @@ void AppendDictionary(cmXMLWriter& xml, const char* key, T const& value) } cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator() - : cmExternalMakefileProjectGenerator() { this->SupportsVirtualFolders = true; this->GenerateLinkedResources = true; @@ -134,7 +135,7 @@ void cmExtraEclipseCDT4Generator::Generate() if (!this->GenerateSourceProject && (mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"))) { mf->IssueMessage( - cmake::WARNING, + MessageType::WARNING, "ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT is set to TRUE, " "but this variable is not supported anymore since CMake 2.8.7.\n" "Enable CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT instead."); @@ -142,7 +143,7 @@ void cmExtraEclipseCDT4Generator::Generate() if (cmSystemTools::IsSubDirectory(this->HomeOutputDirectory, this->HomeDirectory)) { - mf->IssueMessage(cmake::WARNING, + mf->IssueMessage(MessageType::WARNING, "The build directory is a subdirectory " "of the source directory.\n" "This is not supported well by Eclipse. It is strongly " @@ -382,7 +383,6 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() xml.StartElement("natures"); xml.Element("nature", "org.eclipse.cdt.make.core.makeNature"); xml.Element("nature", "org.eclipse.cdt.make.core.ScannerConfigNature"); - ; for (std::string const& n : this->Natures) { xml.Element("nature", n); diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index 9410690..a9ed7fe 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -17,7 +17,6 @@ #include <vector> cmExtraKateGenerator::cmExtraKateGenerator() - : cmExternalMakefileProjectGenerator() { } diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 882d39f..739a177 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -14,6 +14,7 @@ #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSourceFile.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -55,7 +56,6 @@ cmExtraSublimeTextGenerator::GetFactory() } cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator() - : cmExternalMakefileProjectGenerator() { this->ExcludeBuildFolder = false; } @@ -155,7 +155,7 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile( e << "Could not parse Env Vars specified in " "\"CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS\"" << ", corrupted string " << t; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); } } fout << "\n\t\t}"; diff --git a/Source/cmFileAPICMakeFiles.cxx b/Source/cmFileAPICMakeFiles.cxx index 799a047..5590bc2 100644 --- a/Source/cmFileAPICMakeFiles.cxx +++ b/Source/cmFileAPICMakeFiles.cxx @@ -12,6 +12,7 @@ #include "cm_jsoncpp_value.h" #include <string> +#include <vector> namespace { diff --git a/Source/cmFileAPICache.cxx b/Source/cmFileAPICache.cxx index 074994a..f96bc90 100644 --- a/Source/cmFileAPICache.cxx +++ b/Source/cmFileAPICache.cxx @@ -10,6 +10,7 @@ #include <algorithm> #include <string> +#include <utility> #include <vector> namespace { diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index fb8e8d3..db2fde8 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -17,6 +17,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <utility> #include <vector> #include "cmAlgorithms.h" @@ -31,6 +32,7 @@ #include "cmInstallType.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSystemTools.h" #include "cmTimestamp.h" @@ -220,7 +222,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, // Set permissions to writable if (cmSystemTools::GetPermissions(fileName.c_str(), mode)) { #if defined(_MSC_VER) || defined(__MINGW32__) - writable = mode & S_IWRITE; + writable = (mode & S_IWRITE) != 0; mode_t newMode = mode | S_IWRITE; #else writable = mode & S_IWUSR; @@ -833,13 +835,13 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, // Generated build system depends on glob results if (!configureDepends && warnConfigureLate) { this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, "CONFIGURE_DEPENDS flag was given after a glob expression was " "already evaluated."); } if (workingMode != cmake::NORMAL_MODE) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "CONFIGURE_DEPENDS is invalid for script and find package modes."); return false; } @@ -870,12 +872,12 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, for (cmsys::Glob::Message const& globMessage : globMessages) { if (globMessage.type == cmsys::Glob::cyclicRecursion) { this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, "Cyclic recursion detected while globbing for '" + *i + "':\n" + globMessage.content); } else { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "Error has occurred while globbing for '" + *i + "' - " + globMessage.content); shouldExit = true; @@ -924,7 +926,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, // symlinks without being explicitly asked to: warn the author. if (warnFollowedSymlinks) { this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(cmPolicies::CMP0009)); } break; @@ -1095,13 +1097,9 @@ protected: // Properties set by pattern and regex match rules. struct MatchProperties { - bool Exclude; - mode_t Permissions; - MatchProperties() - : Exclude(false) - , Permissions(0) - { - } + bool Exclude = false; + mode_t Permissions = 0; + MatchProperties() {} }; struct MatchRule { @@ -2702,12 +2700,14 @@ private: #endif #define check_curl_result(result, errstr) \ - if (result != CURLE_OK) { \ - std::string e(errstr); \ - e += ::curl_easy_strerror(result); \ - this->SetError(e); \ - return false; \ - } + do { \ + if (result != CURLE_OK) { \ + std::string e(errstr); \ + e += ::curl_easy_strerror(result); \ + this->SetError(e); \ + return false; \ + } \ + } while (false) bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) { @@ -2856,7 +2856,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) // Do not return error for compatibility reason. std::string err = "Unexpected argument: "; err += *i; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, err); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, err); } ++i; } @@ -3172,7 +3172,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) // Do not return error for compatibility reason. std::string err = "Unexpected argument: "; err += *i; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, err); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, err); } ++i; @@ -3430,7 +3430,8 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) // Parse arguments if (args.size() < 2) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, "sub-command LOCK requires at least two arguments."); + MessageType::FATAL_ERROR, + "sub-command LOCK requires at least two arguments."); return false; } @@ -3444,7 +3445,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) ++i; const char* merr = "expected FUNCTION, FILE or PROCESS after GUARD"; if (i >= args.size()) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, merr); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, merr); return false; } if (args[i] == "FUNCTION") { @@ -3456,7 +3457,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) } else { std::ostringstream e; e << merr << ", but got:\n \"" << args[i] << "\"."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -3464,14 +3465,15 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) ++i; if (i >= args.size()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, "expected variable name after RESULT_VARIABLE"); + MessageType::FATAL_ERROR, + "expected variable name after RESULT_VARIABLE"); return false; } resultVariable = args[i]; } else if (args[i] == "TIMEOUT") { ++i; if (i >= args.size()) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "expected timeout value after TIMEOUT"); return false; } @@ -3480,7 +3482,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) scanned < 0) { std::ostringstream e; e << "TIMEOUT value \"" << args[i] << "\" is not an unsigned integer."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } timeout = static_cast<unsigned long>(scanned); @@ -3488,7 +3490,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) std::ostringstream e; e << "expected DIRECTORY, RELEASE, GUARD, RESULT_VARIABLE or TIMEOUT\n"; e << "but got: \"" << args[i] << "\"."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } } @@ -3510,7 +3512,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) std::ostringstream e; e << "directory\n \"" << parentDir << "\"\ncreation failed "; e << "(check permissions)."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return false; } @@ -3518,7 +3520,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) if (!file) { std::ostringstream e; e << "file\n \"" << path << "\"\ncreation failed (check permissions)."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return false; } @@ -3553,7 +3555,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) if (resultVariable.empty() && !fileLockResult.IsOk()) { std::ostringstream e; e << "error locking file\n \"" << path << "\"\n" << result << "."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return false; } diff --git a/Source/cmFileLock.h b/Source/cmFileLock.h index 6c9a7b8..491a40b 100644 --- a/Source/cmFileLock.h +++ b/Source/cmFileLock.h @@ -51,14 +51,13 @@ private: cmFileLockResult LockWithTimeout(unsigned long timeoutSec); #if defined(_WIN32) - typedef HANDLE FileId; + HANDLE File = INVALID_HANDLE_VALUE; BOOL LockFile(DWORD flags); #else - typedef int FileId; + int File = -1; int LockFile(int cmd, int type); #endif - FileId File; std::string Filename; }; diff --git a/Source/cmFileLockUnix.cxx b/Source/cmFileLockUnix.cxx index 7353b01..9b653e8 100644 --- a/Source/cmFileLockUnix.cxx +++ b/Source/cmFileLockUnix.cxx @@ -9,7 +9,6 @@ #include <unistd.h> cmFileLock::cmFileLock() - : File(-1) { } diff --git a/Source/cmFileLockWin32.cxx b/Source/cmFileLockWin32.cxx index 51ac249..a61d360 100644 --- a/Source/cmFileLockWin32.cxx +++ b/Source/cmFileLockWin32.cxx @@ -6,7 +6,6 @@ #include <windows.h> // CreateFileW cmFileLock::cmFileLock() - : File(INVALID_HANDLE_VALUE) { } diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 1e1ab14..bcf876d 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -7,6 +7,7 @@ #include <set> #include <stdio.h> #include <string.h> +#include <utility> #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -198,13 +199,10 @@ struct cmFindLibraryHelper // Current names under consideration. struct Name { - bool TryRaw; + bool TryRaw = false; std::string Raw; cmsys::RegularExpression Regex; - Name() - : TryRaw(false) - { - } + Name() {} }; std::vector<Name> Names; diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index bf928fc..8dc7ca2 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -21,12 +21,12 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSearchPath.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmVersion.h" -#include "cmake.h" #if defined(__HAIKU__) # include <FindDirectory.h> @@ -384,7 +384,8 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, if (this->Version.empty() && this->VersionExact) { this->VersionExact = false; this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, "Ignoring EXACT since no version is requested."); + MessageType::AUTHOR_WARNING, + "Ignoring EXACT since no version is requested."); } if (this->Version.empty() || components.empty()) { @@ -473,7 +474,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0074)); break; case cmPolicies::NEW: { @@ -536,7 +537,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, } aw << "\n" "(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.)"; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, aw.str()); } // No find module. Assume the project has a CMake config file. Use @@ -667,7 +668,7 @@ bool cmFindPackageCommand::FindModule(bool& found) case cmPolicies::WARN: { std::ostringstream e; e << cmPolicies::GetPolicyWarning(it->second) << "\n"; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); CM_FALLTHROUGH; } case cmPolicies::OLD: @@ -736,7 +737,8 @@ bool cmFindPackageCommand::HandlePackageMode() // Sanity check. if (fileFound && this->FileFound.empty()) { this->Makefile->IssueMessage( - cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!"); + MessageType::INTERNAL_ERROR, + "fileFound is true but FileFound is empty!"); fileFound = false; } } @@ -887,14 +889,15 @@ bool cmFindPackageCommand::HandlePackageMode() } } - this->Makefile->IssueMessage( - this->Required ? cmake::FATAL_ERROR : cmake::WARNING, e.str()); + this->Makefile->IssueMessage(this->Required ? MessageType::FATAL_ERROR + : MessageType::WARNING, + e.str()); if (this->Required) { cmSystemTools::SetFatalErrorOccured(); } if (!aw.str().empty()) { - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, aw.str()); } } // output result if in config mode but not in quiet mode @@ -1675,11 +1678,7 @@ private: class cmFileList { public: - cmFileList() - : First() - , Last(nullptr) - { - } + cmFileList() {} virtual ~cmFileList() {} cmFileList& operator/(cmFileListGeneratorBase const& rhs) { @@ -1703,15 +1702,14 @@ private: virtual bool Visit(std::string const& fullPath) = 0; friend class cmFileListGeneratorBase; std::unique_ptr<cmFileListGeneratorBase> First; - cmFileListGeneratorBase* Last; + cmFileListGeneratorBase* Last = nullptr; }; class cmFindPackageFileList : public cmFileList { public: cmFindPackageFileList(cmFindPackageCommand* fpc, bool use_suffixes = true) - : cmFileList() - , FPC(fpc) + : FPC(fpc) , UseSuffixes(use_suffixes) { } @@ -1753,13 +1751,11 @@ class cmFileListGeneratorFixed : public cmFileListGeneratorBase { public: cmFileListGeneratorFixed(std::string const& str) - : cmFileListGeneratorBase() - , String(str) + : String(str) { } cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r) - : cmFileListGeneratorBase() - , String(r.String) + : String(r.String) { } @@ -1782,13 +1778,11 @@ class cmFileListGeneratorEnumerate : public cmFileListGeneratorBase { public: cmFileListGeneratorEnumerate(std::vector<std::string> const& v) - : cmFileListGeneratorBase() - , Vector(v) + : Vector(v) { } cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r) - : cmFileListGeneratorBase() - , Vector(r.Vector) + : Vector(r.Vector) { } @@ -1817,14 +1811,12 @@ public: cmFileListGeneratorProject(std::vector<std::string> const& names, cmFindPackageCommand::SortOrderType so, cmFindPackageCommand::SortDirectionType sd) - : cmFileListGeneratorBase() - , Names(names) + : Names(names) { this->SetSort(so, sd); } cmFileListGeneratorProject(cmFileListGeneratorProject const& r) - : cmFileListGeneratorBase() - , Names(r.Names) + : Names(r.Names) { this->SetSort(r.SortOrder, r.SortDirection); } @@ -1888,14 +1880,12 @@ class cmFileListGeneratorMacProject : public cmFileListGeneratorBase public: cmFileListGeneratorMacProject(std::vector<std::string> const& names, const char* ext) - : cmFileListGeneratorBase() - , Names(names) + : Names(names) , Extension(ext) { } cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r) - : cmFileListGeneratorBase() - , Names(r.Names) + : Names(r.Names) , Extension(r.Extension) { } @@ -1941,14 +1931,12 @@ class cmFileListGeneratorCaseInsensitive : public cmFileListGeneratorBase { public: cmFileListGeneratorCaseInsensitive(std::string const& str) - : cmFileListGeneratorBase() - , String(str) + : String(str) { } cmFileListGeneratorCaseInsensitive( cmFileListGeneratorCaseInsensitive const& r) - : cmFileListGeneratorBase() - , String(r.String) + : String(r.String) { } @@ -1985,13 +1973,11 @@ class cmFileListGeneratorGlob : public cmFileListGeneratorBase { public: cmFileListGeneratorGlob(std::string const& str) - : cmFileListGeneratorBase() - , Pattern(str) + : Pattern(str) { } cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r) - : cmFileListGeneratorBase() - , Pattern(r.Pattern) + : Pattern(r.Pattern) { } diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx index 739c9c0..3047167 100644 --- a/Source/cmForEachCommand.cxx +++ b/Source/cmForEachCommand.cxx @@ -10,8 +10,8 @@ #include "cmAlgorithms.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" -#include "cmake.h" cmForEachFunctionBlocker::cmForEachFunctionBlocker(cmMakefile* mf) : Makefile(mf) @@ -210,7 +210,7 @@ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args) std::ostringstream e; e << "Unknown argument:\n" << " " << args[i] << "\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return true; } } diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 186ec8c..bf53dbf 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -12,8 +12,6 @@ #endif cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding) - : cmGeneratedFileStreamBase() - , Stream() { #ifdef CMAKE_BUILD_WITH_CMAKE if (encoding != codecvt::None) { @@ -105,22 +103,10 @@ void cmGeneratedFileStream::SetCompressionExtraExtension(bool ext) } cmGeneratedFileStreamBase::cmGeneratedFileStreamBase() - : Name() - , TempName() - , CopyIfDifferent(false) - , Okay(false) - , Compress(false) - , CompressExtraExtension(true) { } cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(std::string const& name) - : Name() - , TempName() - , CopyIfDifferent(false) - , Okay(false) - , Compress(false) - , CompressExtraExtension(true) { this->Open(name); } diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index dacd166..fd11889 100644 --- a/Source/cmGeneratedFileStream.h +++ b/Source/cmGeneratedFileStream.h @@ -45,16 +45,16 @@ protected: std::string TempName; // Whether to do a copy-if-different. - bool CopyIfDifferent; + bool CopyIfDifferent = false; // Whether the real file stream was valid when it was closed. - bool Okay; + bool Okay = false; // Whether the destination file is compressed - bool Compress; + bool Compress = false; // Whether the destination file is compressed - bool CompressExtraExtension; + bool CompressExtraExtension = true; }; /** \class cmGeneratedFileStream diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 2727d9a..96d4ad6 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -71,16 +71,11 @@ const std::string& cmCompiledGeneratorExpression::EvaluateWithContext( this->Output.clear(); - std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it = - this->Evaluators.begin(); - const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end = - this->Evaluators.end(); + for (const cmGeneratorExpressionEvaluator* it : this->Evaluators) { + this->Output += it->Evaluate(&context, dagChecker); - for (; it != end; ++it) { - this->Output += (*it)->Evaluate(&context, dagChecker); - - this->SeenTargetProperties.insert(context.SeenTargetProperties.begin(), - context.SeenTargetProperties.end()); + this->SeenTargetProperties.insert(context.SeenTargetProperties.cbegin(), + context.SeenTargetProperties.cend()); if (context.HadError) { this->Output.clear(); break; diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index 56eb2bf..61b798b 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -7,6 +7,7 @@ #include "cmGeneratorExpressionEvaluator.h" #include "cmGeneratorTarget.h" #include "cmLocalGenerator.h" +#include "cmMessageType.h" #include "cmake.h" #include <sstream> @@ -55,7 +56,7 @@ void cmGeneratorExpressionDAGChecker::Initialize() if (CheckResult == DAG && (CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD( - TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(clang-tidy) + TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(*) #undef TEST_TRANSITIVE_PROPERTY_METHOD { std::map<cmGeneratorTarget const*, std::set<std::string>>::const_iterator @@ -99,8 +100,8 @@ void cmGeneratorExpressionDAGChecker::ReportError( << " " << expr << "\n" << "Self reference on target \"" << context->HeadTarget->GetName() << "\".\n"; - context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - parent->Backtrace); + context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + e.str(), parent->Backtrace); return; } @@ -111,8 +112,8 @@ void cmGeneratorExpressionDAGChecker::ReportError( << " " << expr << "\n" << "Dependency loop found."; /* clang-format on */ - context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - context->Backtrace); + context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + e.str(), context->Backtrace); } int loopStep = 1; @@ -122,8 +123,8 @@ void cmGeneratorExpressionDAGChecker::ReportError( << " " << (parent->Content ? parent->Content->GetOriginalExpression() : expr) << "\n"; - context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - parent->Backtrace); + context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + e.str(), parent->Backtrace); parent = parent->Parent; ++loopStep; } diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index e7a55e0..1c33a6e 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -12,10 +12,10 @@ #include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSourceFile.h" #include "cmSourceFileLocationKind.h" #include "cmSystemTools.h" -#include "cmake.h" cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile( const std::string& input, @@ -48,7 +48,7 @@ void cmGeneratorExpressionEvaluationFile::Generate( << "\" did " "not evaluate to valid content. Got \"" << condResult << "\"."; - lg->IssueMessage(cmake::FATAL_ERROR, e.str()); + lg->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } } @@ -77,7 +77,7 @@ void cmGeneratorExpressionEvaluationFile::Generate( "This is generally caused by the content evaluating the " "configuration type, language, or location of object files:\n " << outputFileName; - lg->IssueMessage(cmake::FATAL_ERROR, e.str()); + lg->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -137,7 +137,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) if (!fin) { std::ostringstream e; e << "Evaluation file \"" << inputFileName << "\" cannot be read."; - lg->IssueMessage(cmake::FATAL_ERROR, e.str()); + lg->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -204,7 +204,7 @@ std::string cmGeneratorExpressionEvaluationFile::FixRelativePath( "undefined behavior will be used." ; /* clang-format on */ - lg->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + lg->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } CM_FALLTHROUGH; case cmPolicies::OLD: diff --git a/Source/cmGeneratorExpressionLexer.cxx b/Source/cmGeneratorExpressionLexer.cxx index e37f165..242915d 100644 --- a/Source/cmGeneratorExpressionLexer.cxx +++ b/Source/cmGeneratorExpressionLexer.cxx @@ -3,8 +3,6 @@ #include "cmGeneratorExpressionLexer.h" cmGeneratorExpressionLexer::cmGeneratorExpressionLexer() - : SawBeginExpression(false) - , SawGeneratorExpression(false) { } diff --git a/Source/cmGeneratorExpressionLexer.h b/Source/cmGeneratorExpressionLexer.h index e53f0b5..bf24308 100644 --- a/Source/cmGeneratorExpressionLexer.h +++ b/Source/cmGeneratorExpressionLexer.h @@ -46,8 +46,8 @@ public: } private: - bool SawBeginExpression; - bool SawGeneratorExpression; + bool SawBeginExpression = false; + bool SawGeneratorExpression = false; }; #endif diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index eb3df16..fe1b055 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -12,6 +12,7 @@ #include "cmLinkItem.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmStateTypes.h" @@ -304,7 +305,7 @@ static const struct InListNode : public cmGeneratorExpressionNode << "\nSearch Item:\n \"" << parameters.front() << "\"\nList:\n \"" << parameters[1] << "\"\n"; context->LG->GetCMakeInstance()->IssueMessage( - cmake::AUTHOR_WARNING, e.str(), context->Backtrace); + MessageType ::AUTHOR_WARNING, e.str(), context->Backtrace); return "0"; } if (values.empty()) { @@ -632,7 +633,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode std::ostringstream e; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044); context->LG->GetCMakeInstance()->IssueMessage( - cmake::AUTHOR_WARNING, e.str(), context->Backtrace); + MessageType::AUTHOR_WARNING, e.str(), context->Backtrace); CM_FALLTHROUGH; } case cmPolicies::OLD: @@ -1257,7 +1258,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode #define TRANSITIVE_PROPERTY_COMPARE(PROPERTY) \ (#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) || if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME( - TRANSITIVE_PROPERTY_COMPARE) false) { // NOLINT(clang-tidy) + TRANSITIVE_PROPERTY_COMPARE) false) { // NOLINT(*) reportError( context, content->GetOriginalExpression(), "$<TARGET_PROPERTY:...> expression in link libraries " @@ -1654,7 +1655,7 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode switch (statusForTarget(context->HeadTarget, policy)) { case cmPolicies::WARN: lg->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(policyForString(policy))); CM_FALLTHROUGH; case cmPolicies::REQUIRED_IF_USED: @@ -2096,6 +2097,6 @@ void reportError(cmGeneratorExpressionContext* context, << " " << expr << "\n" << result; /* clang-format on */ - context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - context->Backtrace); + context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + e.str(), context->Backtrace); } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 80d81d5..6515dfa 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -25,6 +25,7 @@ #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPropertyMap.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" @@ -340,7 +341,7 @@ std::string cmGeneratorTarget::GetOutputName( // An empty map entry indicates we have been called recursively // from the above block. this->LocalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.", this->GetBacktrace()); } @@ -435,14 +436,14 @@ static void handleSystemIncludesDep( /* clang-format off */ #define IMPLEMENT_VISIT(KIND) \ - { \ + do { \ KindedSources const& kinded = this->GetKindedSources(config); \ for (SourceAndKind const& s : kinded.Sources) { \ if (s.Kind == KIND) { \ data.push_back(s.Source.Value); \ } \ } \ - } + } while (false) /* clang-format on */ void cmGeneratorTarget::GetObjectSources( @@ -512,7 +513,7 @@ const char* cmGeneratorTarget::GetLinkPIEProperty( case cmPolicies::WARN: { std::ostringstream e; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0083); - this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); CM_FALLTHROUGH; } case cmPolicies::OLD: @@ -559,7 +560,7 @@ bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang, w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target " << "'" << this->GetName() << "'."; this->LocalGenerator->GetCMakeInstance()->IssueMessage( - cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace()); + MessageType::AUTHOR_WARNING, w.str(), this->GetBacktrace()); this->PolicyReportedCMP0069 = true; } @@ -590,7 +591,7 @@ bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang, this->PolicyReportedCMP0069 = true; this->LocalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, message, this->GetBacktrace()); + MessageType::FATAL_ERROR, message, this->GetBacktrace()); return false; } @@ -924,7 +925,7 @@ static bool processSources( if (fullPath.empty()) { if (!e.empty()) { cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance(); - cm->IssueMessage(cmake::FATAL_ERROR, e, tgt->GetBacktrace()); + cm->IssueMessage(MessageType::FATAL_ERROR, e, tgt->GetBacktrace()); } return contextDependent; } @@ -939,7 +940,8 @@ static bool processSources( err << "Found relative path while evaluating sources of \"" << tgt->GetName() << "\":\n \"" << src << "\"\n"; } - tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str()); + tgt->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR, + err.str()); return contextDependent; } src = fullPath; @@ -955,7 +957,7 @@ static bool processSources( } if (!usedSources.empty()) { tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::LOG, + MessageType::LOG, std::string("Used sources for target ") + tgt->GetName() + ":\n" + usedSources, entry->ge->GetBacktrace()); @@ -1129,7 +1131,7 @@ cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources( << "\" use a generator expression that depends on the " "SOURCES themselves."; this->GlobalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, e.str(), this->GetBacktrace()); + MessageType::FATAL_ERROR, e.str(), this->GetBacktrace()); static KindedSources empty; return empty; } @@ -1230,7 +1232,7 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, e << "but may contain only sources that compile, header files, and " "other files that would not affect linking of a normal library."; this->GlobalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, e.str(), this->GetBacktrace()); + MessageType::FATAL_ERROR, e.str(), this->GetBacktrace()); } } @@ -1388,7 +1390,7 @@ bool cmGeneratorTarget::NeedRelinkBeforeInstall( /* clang-format on */ cmake* cm = this->LocalGenerator->GetCMakeInstance(); - cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace()); + cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace()); } return have_rpath; @@ -1519,7 +1521,7 @@ bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir( w << " less than 10.5 or because CMake's platform configuration is"; w << " corrupt."; cmake* cm = this->LocalGenerator->GetCMakeInstance(); - cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace()); + cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace()); } return true; @@ -1819,13 +1821,13 @@ public: if (!item.Target) { if (item.AsStr().find("::") != std::string::npos) { bool noMessage = false; - cmake::MessageType messageType = cmake::FATAL_ERROR; + MessageType messageType = MessageType::FATAL_ERROR; std::ostringstream e; switch (this->Target->GetLocalGenerator()->GetPolicyStatus( cmPolicies::CMP0028)) { case cmPolicies::WARN: { e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n"; - messageType = cmake::AUTHOR_WARNING; + messageType = MessageType::AUTHOR_WARNING; } break; case cmPolicies::OLD: noMessage = true; @@ -1928,7 +1930,7 @@ public: } e << "Set the LINKER_LANGUAGE property for this target."; cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance(); - cm->IssueMessage(cmake::FATAL_ERROR, e.str(), + cm->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->Target->GetBacktrace()); } return *this->Preferred.begin(); @@ -2053,7 +2055,7 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo( msg += this->GetName(); msg += " which has type "; msg += cmState::GetTargetTypeName(this->GetType()); - this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); + this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); return nullptr; } @@ -2239,7 +2241,7 @@ cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target) << "\"\ndepends on the sources of a target it is used in. This " "is a dependency loop and is not allowed."; this->GeneratorTarget->LocalGenerator->IssueMessage( - cmake::FATAL_ERROR, e.str()); + MessageType::FATAL_ERROR, e.str()); return; } if (emitted.insert(sf).second && @@ -2551,14 +2553,14 @@ static void processIncludeDirectories( for (std::string& entryInclude : entryIncludes) { if (fromImported && !cmSystemTools::FileExists(entryInclude)) { std::ostringstream e; - cmake::MessageType messageType = cmake::FATAL_ERROR; + MessageType messageType = MessageType::FATAL_ERROR; if (checkCMP0027) { switch (tgt->GetPolicyStatusCMP0027()) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n"; CM_FALLTHROUGH; case cmPolicies::OLD: - messageType = cmake::AUTHOR_WARNING; + messageType = MessageType::AUTHOR_WARNING; break; case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_IF_USED: @@ -2584,7 +2586,7 @@ static void processIncludeDirectories( if (!cmSystemTools::FileIsFullPath(entryInclude)) { std::ostringstream e; bool noMessage = false; - cmake::MessageType messageType = cmake::FATAL_ERROR; + MessageType messageType = MessageType::FATAL_ERROR; if (!targetName.empty()) { /* clang-format off */ e << "Target \"" << targetName << "\" contains relative " @@ -2595,7 +2597,7 @@ static void processIncludeDirectories( switch (tgt->GetPolicyStatusCMP0021()) { case cmPolicies::WARN: { e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n"; - messageType = cmake::AUTHOR_WARNING; + messageType = MessageType::AUTHOR_WARNING; } break; case cmPolicies::OLD: noMessage = true; @@ -2611,7 +2613,7 @@ static void processIncludeDirectories( } if (!noMessage) { tgt->GetLocalGenerator()->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return; } } @@ -2631,7 +2633,7 @@ static void processIncludeDirectories( } if (!usedIncludes.empty()) { tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::LOG, + MessageType::LOG, std::string("Used includes for target ") + tgt->GetName() + ":\n" + usedIncludes, entry->ge->GetBacktrace()); @@ -2744,7 +2746,7 @@ static void processOptionsInternal( } if (!usedOptions.empty()) { tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::LOG, + MessageType::LOG, std::string("Used ") + logName + std::string(" for target ") + tgt->GetName() + ":\n" + usedOptions, entry->ge->GetBacktrace()); @@ -2946,7 +2948,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions( case cmPolicies::WARN: { std::ostringstream e; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043); - this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, + e.str()); CM_FALLTHROUGH; } case cmPolicies::OLD: { @@ -3085,7 +3088,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions( return item.find(SHELL) != std::string::npos; }) != linkerOptions.end()) { this->LocalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.", this->GetBacktrace()); return result; @@ -3219,7 +3222,7 @@ void processLinkDirectories( if (!cmSystemTools::FileIsFullPath(entryDirectory)) { std::ostringstream e; bool noMessage = false; - cmake::MessageType messageType = cmake::FATAL_ERROR; + MessageType messageType = MessageType::FATAL_ERROR; if (!targetName.empty()) { /* clang-format off */ e << "Target \"" << targetName << "\" contains relative " @@ -3230,7 +3233,7 @@ void processLinkDirectories( switch (tgt->GetPolicyStatusCMP0081()) { case cmPolicies::WARN: { e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n"; - messageType = cmake::AUTHOR_WARNING; + messageType = MessageType::AUTHOR_WARNING; } break; case cmPolicies::OLD: noMessage = true; @@ -3247,7 +3250,7 @@ void processLinkDirectories( } if (!noMessage) { tgt->GetLocalGenerator()->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return; } } @@ -3265,7 +3268,7 @@ void processLinkDirectories( } if (!usedDirectories.empty()) { tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::LOG, + MessageType::LOG, std::string("Used link directories for target ") + tgt->GetName() + ":\n" + usedDirectories, entry->ge->GetBacktrace()); @@ -3511,7 +3514,7 @@ std::string cmGeneratorTarget::NormalGetRealName( if (this->IsImported()) { std::string msg = "NormalGetRealName called on imported target: "; msg += this->GetName(); - this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); + this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); } if (this->GetType() == cmStateEnums::EXECUTABLE) { @@ -3545,7 +3548,7 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName, if (this->IsImported()) { std::string msg = "GetLibraryNames called on imported target: "; msg += this->GetName(); - this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); + this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); return; } @@ -3622,7 +3625,7 @@ void cmGeneratorTarget::GetExecutableNames(std::string& name, if (this->IsImported()) { std::string msg = "GetExecutableNames called on imported target: "; msg += this->GetName(); - this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); + this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); } // This versioning is supported only for executables and then only @@ -4123,7 +4126,8 @@ void checkPropertyConsistency(cmGeneratorTarget const* depender, "This is not allowed. Only user-defined properties may appear " "listed in the " << propName << " property."; - depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str()); + depender->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR, + e.str()); return; } if (emitted.insert(p).second) { @@ -4263,7 +4267,7 @@ void cmGeneratorTarget::CheckPropertyCompatibility( "in a boolean interpretation, a numeric minimum, a numeric maximum " "or a " "string interpretation, but not a mixture."; - this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str()); } } @@ -4863,7 +4867,8 @@ void cmGeneratorTarget::ReportPropertyOrigin( areport += result; areport += "\"):\n" + report; - this->LocalGenerator->GetCMakeInstance()->IssueMessage(cmake::LOG, areport); + this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG, + areport); } void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names, @@ -5092,7 +5097,7 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( msg += this->GetName(); msg += " which has type "; msg += cmState::GetTargetTypeName(this->GetType()); - this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); + this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); return nullptr; } @@ -5123,7 +5128,7 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( // An empty map entry indicates we have been called recursively // from the above block. this->LocalGenerator->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.", this->GetBacktrace()); return nullptr; @@ -5343,7 +5348,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries( linkIfaceProp << ":\n" " " << explicitLibraries << "\n"; /* clang-format on */ - this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); this->PolicyWarnedCMP0022 = true; } } @@ -5412,7 +5417,8 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries( "Link implementation:\n" " " << oldLibraries << "\n"; /* clang-format on */ - this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, + w.str()); this->PolicyWarnedCMP0022 = true; } } @@ -5720,7 +5726,7 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles( "Config \"" << *it << "\":\n" " " << thisConfigFiles << "\n"; /* clang-format on */ - this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } } @@ -5778,7 +5784,8 @@ std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n" << "Target \"" << this->GetName() << "\" links to item \"" << item << "\" which has leading or trailing whitespace."; - cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace()); + cm->IssueMessage(MessageType::AUTHOR_WARNING, w.str(), + this->GetBacktrace()); } case cmPolicies::OLD: break; @@ -5787,7 +5794,8 @@ std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const e << "Target \"" << this->GetName() << "\" links to item \"" << item << "\" which has leading or trailing whitespace. " << "This is now an error according to policy CMP0004."; - cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace()); + cm->IssueMessage(MessageType::FATAL_ERROR, e.str(), + this->GetBacktrace()); } break; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: { @@ -5795,7 +5803,8 @@ std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n" << "Target \"" << this->GetName() << "\" links to item \"" << item << "\" which has leading or trailing whitespace."; - cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace()); + cm->IssueMessage(MessageType::FATAL_ERROR, e.str(), + this->GetBacktrace()); } break; } } @@ -5959,12 +5968,12 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( if (name == this->GetName() || name.empty()) { if (name == this->GetName()) { bool noMessage = false; - cmake::MessageType messageType = cmake::FATAL_ERROR; + MessageType messageType = MessageType::FATAL_ERROR; std::ostringstream e; switch (this->GetPolicyStatusCMP0038()) { case cmPolicies::WARN: { e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n"; - messageType = cmake::AUTHOR_WARNING; + messageType = MessageType::AUTHOR_WARNING; } break; case cmPolicies::OLD: noMessage = true; @@ -5979,7 +5988,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( e << "Target \"" << this->GetName() << "\" links to itself."; this->LocalGenerator->GetCMakeInstance()->IssueMessage( messageType, e.str(), this->GetBacktrace()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return; } } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 52defee..cfd1df0 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -110,11 +110,8 @@ public: std::set<std::string> ExpectedResxHeaders; std::set<std::string> ExpectedXamlHeaders; std::set<std::string> ExpectedXamlSources; - bool Initialized; - KindedSources() - : Initialized(false) - { - } + bool Initialized = false; + KindedSources() {} }; /** Get all sources needed for a configuration with kinds assigned. */ @@ -565,13 +562,9 @@ public: }; struct SourceFileFlags { - SourceFileFlags() - : Type(SourceFileTypeNormal) - , MacFolder(nullptr) - { - } - SourceFileType Type; - const char* MacFolder; // location inside Mac content folders + SourceFileFlags() {} + SourceFileType Type = SourceFileTypeNormal; + const char* MacFolder = nullptr; // location inside Mac content folders }; void GetAutoUicOptions(std::vector<std::string>& result, const std::string& config) const; @@ -757,11 +750,8 @@ private: struct CompatibleInterfaces : public CompatibleInterfacesBase { - CompatibleInterfaces() - : Done(false) - { - } - bool Done; + CompatibleInterfaces() {} + bool Done = false; }; mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap; @@ -774,11 +764,8 @@ private: struct LinkImplClosure : public std::vector<cmGeneratorTarget const*> { - LinkImplClosure() - : Done(false) - { - } - bool Done; + LinkImplClosure() {} + bool Done = false; }; mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap; @@ -797,15 +784,10 @@ private: // Cache import information from properties for each configuration. struct ImportInfo { - ImportInfo() - : NoSOName(false) - , Managed(Native) - , Multiplicity(0) - { - } - bool NoSOName; - ManagedType Managed; - unsigned int Multiplicity; + ImportInfo() {} + bool NoSOName = false; + ManagedType Managed = Native; + unsigned int Multiplicity = 0; std::string Location; std::string SOName; std::string ImportLibrary; diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx index 0d4d653..a92eb71 100644 --- a/Source/cmGetDirectoryPropertyCommand.cxx +++ b/Source/cmGetDirectoryPropertyCommand.cxx @@ -4,9 +4,9 @@ #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -76,7 +76,7 @@ bool cmGetDirectoryPropertyCommand::InitialPass( switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0059)) { case cmPolicies::WARN: this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(cmPolicies::CMP0059)); CM_FALLTHROUGH; case cmPolicies::OLD: diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 1d812bd..039f439 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -8,6 +8,7 @@ #include "cmInstalledFile.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmProperty.h" #include "cmPropertyDefinition.h" @@ -230,7 +231,7 @@ bool cmGetPropertyCommand::HandleDirectoryMode() if (this->PropertyName == "DEFINITIONS") { switch (mf->GetPolicyStatus(cmPolicies::CMP0059)) { case cmPolicies::WARN: - mf->IssueMessage(cmake::AUTHOR_WARNING, + mf->IssueMessage(MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(cmPolicies::CMP0059)); CM_FALLTHROUGH; case cmPolicies::OLD: diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index ec485aa..fc0e9c6 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -6,10 +6,10 @@ #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmTarget.h" #include "cmTargetPropertyComputer.h" -#include "cmake.h" class cmExecutionStatus; class cmMessenger; @@ -52,7 +52,7 @@ bool cmGetTargetPropertyCommand::InitialPass( } else { bool issueMessage = false; std::ostringstream e; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0045)) { case cmPolicies::WARN: issueMessage = true; @@ -63,13 +63,13 @@ bool cmGetTargetPropertyCommand::InitialPass( case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: issueMessage = true; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (issueMessage) { e << "get_target_property() called with non-existent target \"" << targetName << "\"."; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 4d98d55..1a25633 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -196,7 +196,7 @@ void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string& config, std::string outputFilename(this->GetOutputFilename(config)); if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { - std::string const static_library_suffix = + std::string const& static_library_suffix = this->Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"); *this->GetFolderBuildStreams() << " -o \"" << outputDir << outputFilename << static_library_suffix @@ -478,10 +478,9 @@ void cmGhsMultiTargetGenerator::WriteSources( std::vector<cmSourceFile*> const& objectSources, std::map<const cmSourceFile*, std::string> const& objectNames) { - for (std::vector<cmSourceFile*>::const_iterator si = objectSources.begin(); - si != objectSources.end(); ++si) { + for (const cmSourceFile* sf : objectSources) { std::vector<cmSourceGroup> sourceGroups(this->Makefile->GetSourceGroups()); - std::string const& sourceFullPath = (*si)->GetFullPath(); + std::string const& sourceFullPath = sf->GetFullPath(); cmSourceGroup* sourceGroup = this->Makefile->FindSourceGroup(sourceFullPath, sourceGroups); std::string sgPath = sourceGroup->GetFullName(); @@ -491,8 +490,8 @@ void cmGhsMultiTargetGenerator::WriteSources( this->LocalGenerator->GetBinaryDirectory().c_str(), sgPath, GhsMultiGpj::SUBPROJECT, this->RelBuildFilePath); - std::string fullSourcePath((*si)->GetFullPath()); - if ((*si)->GetExtension() == "int" || (*si)->GetExtension() == "bsp") { + std::string fullSourcePath(sf->GetFullPath()); + if (sf->GetExtension() == "int" || sf->GetExtension() == "bsp") { *this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl; } else { // WORKAROUND: GHS MULTI needs the path to use backslashes without quotes @@ -501,12 +500,12 @@ void cmGhsMultiTargetGenerator::WriteSources( *this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl; } - if ("ld" != (*si)->GetExtension() && "int" != (*si)->GetExtension() && - "bsp" != (*si)->GetExtension()) { - this->WriteObjectLangOverride(this->FolderBuildStreams[sgPath], (*si)); - if (objectNames.end() != objectNames.find(*si)) { + if ("ld" != sf->GetExtension() && "int" != sf->GetExtension() && + "bsp" != sf->GetExtension()) { + this->WriteObjectLangOverride(this->FolderBuildStreams[sgPath], sf); + if (objectNames.end() != objectNames.find(sf)) { *this->FolderBuildStreams[sgPath] - << " -o \"" << objectNames.find(*si)->second << "\"" << std::endl; + << " -o \"" << objectNames.find(sf)->second << "\"" << std::endl; } this->WriteObjectDir(this->FolderBuildStreams[sgPath], @@ -516,7 +515,7 @@ void cmGhsMultiTargetGenerator::WriteSources( } void cmGhsMultiTargetGenerator::WriteObjectLangOverride( - cmGeneratedFileStream* fileStream, cmSourceFile* sourceFile) + cmGeneratedFileStream* fileStream, const cmSourceFile* sourceFile) { const char* rawLangProp = sourceFile->GetProperty("LANGUAGE"); if (NULL != rawLangProp) { diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h index 2cdf68e..e936b08 100644 --- a/Source/cmGhsMultiTargetGenerator.h +++ b/Source/cmGhsMultiTargetGenerator.h @@ -86,7 +86,7 @@ private: cmLocalGhsMultiGenerator* localGhsMultiGenerator, cmGeneratorTarget* generatorTarget); static void WriteObjectLangOverride(cmGeneratedFileStream* fileStream, - cmSourceFile* sourceFile); + const cmSourceFile* sourceFile); static void WriteObjectDir(cmGeneratedFileStream* fileStream, std::string const& dir); std::string GetOutputDirectory(const std::string& config) const; diff --git a/Source/cmGlobVerificationManager.h b/Source/cmGlobVerificationManager.h index cf04c97..cdbd275 100644 --- a/Source/cmGlobVerificationManager.h +++ b/Source/cmGlobVerificationManager.h @@ -70,13 +70,10 @@ private: struct CacheEntryValue { - bool Initialized; + bool Initialized = false; std::vector<std::string> Files; std::vector<std::pair<std::string, cmListFileBacktrace>> Backtraces; - CacheEntryValue() - : Initialized(false) - { - } + CacheEntryValue() {} }; typedef std::map<CacheEntryKey, CacheEntryValue> CacheEntryMap; diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx index 2389103..56714b1 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.cxx +++ b/Source/cmGlobalBorlandMakefileGenerator.cxx @@ -5,6 +5,7 @@ #include "cmDocumentationEntry.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmake.h" diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 35d716c..85c2345 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -32,6 +32,7 @@ #include "cmLocalGenerator.h" #include "cmMSVC60LinkLineComputer.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmSourceFile.h" @@ -137,7 +138,7 @@ bool cmGlobalGenerator::SetGeneratorInstance(std::string const& i, " " << i << "\n" "was specified."; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -157,7 +158,7 @@ bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p, " " << p << "\n" "was specified."; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -176,7 +177,7 @@ bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts, " " << ts << "\n" "was specified."; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -319,8 +320,8 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const if (srcs.empty()) { std::ostringstream e; e << "No SOURCES given to target: " << target->GetName(); - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - target->GetBacktrace()); + this->GetCMakeInstance()->IssueMessage( + MessageType::FATAL_ERROR, e.str(), target->GetBacktrace()); failed = true; } } @@ -454,7 +455,7 @@ void cmGlobalGenerator::EnableLanguage( e << "Language '" << li << "' is currently being enabled. " "Recursive call not allowed."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return; } @@ -471,7 +472,7 @@ void cmGlobalGenerator::EnableLanguage( std::ostringstream e; e << "The test project needs language " << lang << " which is not enabled."; - this->TryCompileOuterMakefile->IssueMessage(cmake::FATAL_ERROR, + this->TryCompileOuterMakefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return; @@ -775,7 +776,7 @@ void cmGlobalGenerator::EnableLanguage( if (!this->CMakeInstance->GetIsInTryCompile()) { this->PrintCompilerAdvice(noCompiler, lang, mf->GetDefinition(compilerEnv)); - mf->IssueMessage(cmake::FATAL_ERROR, noCompiler.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, noCompiler.str()); fatalError = true; } } @@ -903,7 +904,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( " compiler id \"AppleClang\" to \"Clang\" for compatibility." ; /* clang-format on */ - mf->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } CM_FALLTHROUGH; case cmPolicies::OLD: @@ -913,7 +914,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: mf->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0025)); case cmPolicies::NEW: // NEW behavior is to keep AppleClang. @@ -933,7 +934,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( " compiler id \"QCC\" to \"GNU\" for compatibility." ; /* clang-format on */ - mf->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } CM_FALLTHROUGH; case cmPolicies::OLD: @@ -948,7 +949,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: mf->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0047)); CM_FALLTHROUGH; case cmPolicies::NEW: @@ -1410,13 +1411,13 @@ void cmGlobalGenerator::Generate() if (!this->GenerateCPackPropertiesFile()) { this->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, "Could not write CPack properties file."); + MessageType::FATAL_ERROR, "Could not write CPack properties file."); } for (auto& buildExpSet : this->BuildExportSets) { if (!buildExpSet.second->GenerateImportFile()) { if (!cmSystemTools::GetErrorOccuredFlag()) { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, "Could not write export file."); } return; @@ -1439,7 +1440,8 @@ void cmGlobalGenerator::Generate() for (std::string const& t : this->CMP0042WarnTargets) { w << " " << t << "\n"; } - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING, + w.str()); } if (!this->CMP0068WarnTargets.empty()) { @@ -1455,7 +1457,8 @@ void cmGlobalGenerator::Generate() for (std::string const& t : this->CMP0068WarnTargets) { w << " " << t << "\n"; } - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING, + w.str()); } this->CMakeInstance->UpdateProgress("Generating done", -1); @@ -2233,7 +2236,7 @@ bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName, if (!tgt) { return true; } - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; std::ostringstream e; bool issueMessage = false; switch (tgt->GetPolicyStatusCMP0037()) { @@ -2247,18 +2250,18 @@ bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: issueMessage = true; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; break; } if (issueMessage) { e << "The target name \"" << targetName << "\" is reserved " << reason << "."; - if (messageType == cmake::AUTHOR_WARNING) { + if (messageType == MessageType::AUTHOR_WARNING) { e << " It may result in undefined behavior."; } this->GetCMakeInstance()->IssueMessage(messageType, e.str(), tgt->GetBacktrace()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } @@ -2453,7 +2456,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install( bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES"); if (this->InstallTargetEnabled && skipInstallRules) { this->CMakeInstance->IssueMessage( - cmake::WARNING, + MessageType::WARNING, "CMAKE_SKIP_INSTALL_RULES was enabled even though " "installation rules have been specified", mf->GetBacktrace()); @@ -3023,11 +3026,23 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) std::string cmGlobalGenerator::EscapeJSON(const std::string& s) { std::string result; + result.reserve(s.size()); for (char i : s) { - if (i == '"' || i == '\\') { - result += '\\'; + switch (i) { + case '"': + case '\\': + result += '\\'; + result += i; + break; + case '\n': + result += "\\n"; + break; + case '\t': + result += "\\t"; + break; + default: + result += i; } - result += i; } return result; } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 4e6b6de..36d3d10 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -478,11 +478,8 @@ protected: cmCustomCommandLines CommandLines; std::vector<std::string> Depends; std::string WorkingDir; - bool UsesTerminal; - GlobalTargetInfo() - : UsesTerminal(false) - { - } + bool UsesTerminal = false; + GlobalTargetInfo() {} }; void CreateDefaultGlobalTargets(std::vector<GlobalTargetInfo>& targets); @@ -608,13 +605,10 @@ private: // Cache directory content and target files to be built. struct DirectoryContent { - long LastDiskTime; + long LastDiskTime = -1; std::set<std::string> All; std::set<std::string> Generated; - DirectoryContent() - : LastDiskTime(-1) - { - } + DirectoryContent() {} }; std::map<std::string, DirectoryContent> DirectoryContentMap; diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index a9742c5..831c4a9 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -12,6 +12,7 @@ #include "cmLocalGhsMultiGenerator.h" #include "cmMakefile.h" #include "cmVersion.h" +#include "cmake.h" const char* cmGlobalGhsMultiGenerator::FILE_EXTENSION = ".gpj"; const char* cmGlobalGhsMultiGenerator::DEFAULT_BUILD_PROGRAM = "gbuild.exe"; diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index 13c5113..a5aff73 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -25,13 +25,13 @@ public: } ///! create the correct local generator - virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf); + cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override; /// @return the name of this generator. static std::string GetActualName() { return "Green Hills MULTI"; } ///! Get the name for this generator - virtual std::string GetName() const { return this->GetActualName(); } + std::string GetName() const override { return this->GetActualName(); } /// Overloaded methods. @see cmGlobalGenerator::GetDocumentation() static void GetDocumentation(cmDocumentationEntry& entry); @@ -49,15 +49,15 @@ public: static bool SupportsPlatform() { return true; } // Toolset / Platform Support - virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf); - virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf); + bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override; + bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override; /** * Try to determine system information such as shared library * extension, pthreads, byte order etc. */ - virtual void EnableLanguage(std::vector<std::string> const& languages, - cmMakefile*, bool optional); + void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*, + bool optional) override; /* * Determine what program to use for building the project. */ @@ -88,13 +88,16 @@ public: inline bool IsOSDirRelative() { return this->OSDirRelative; } protected: - virtual void Generate(); - virtual void GenerateBuildCommand( - std::vector<std::string>& makeCommand, const std::string& makeProgram, - const std::string& projectName, const std::string& projectDir, - const std::string& targetName, const std::string& config, bool fast, - int jobs, bool verbose, - std::vector<std::string> const& makeOptions = std::vector<std::string>()); + void Generate() override; + void GenerateBuildCommand(std::vector<std::string>& makeCommand, + const std::string& makeProgram, + const std::string& projectName, + const std::string& projectDir, + const std::string& targetName, + const std::string& config, bool fast, int jobs, + bool verbose, + std::vector<std::string> const& makeOptions = + std::vector<std::string>()) override; private: void GetToolset(cmMakefile* mf, std::string& tsd, std::string& ts); diff --git a/Source/cmGlobalJOMMakefileGenerator.cxx b/Source/cmGlobalJOMMakefileGenerator.cxx index 0f41ea1..9c805a8 100644 --- a/Source/cmGlobalJOMMakefileGenerator.cxx +++ b/Source/cmGlobalJOMMakefileGenerator.cxx @@ -6,6 +6,7 @@ #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" #include "cmState.h" +#include "cmake.h" cmGlobalJOMMakefileGenerator::cmGlobalJOMMakefileGenerator(cmake* cm) : cmGlobalUnixMakefileGenerator3(cm) diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index 3f22382..3c24556 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -7,6 +7,7 @@ #include "cmDocumentationEntry.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmake.h" diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx index 3c3a5d1d..c6d46e9 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.cxx +++ b/Source/cmGlobalMinGWMakefileGenerator.cxx @@ -6,6 +6,7 @@ #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" #include "cmState.h" +#include "cmake.h" cmGlobalMinGWMakefileGenerator::cmGlobalMinGWMakefileGenerator(cmake* cm) : cmGlobalUnixMakefileGenerator3(cm) diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx index eb66bd1..5235be7 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.cxx +++ b/Source/cmGlobalNMakeMakefileGenerator.cxx @@ -6,6 +6,7 @@ #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" #include "cmState.h" +#include "cmake.h" cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator(cmake* cm) : cmGlobalUnixMakefileGenerator3(cm) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 5316b19..57d341a 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -23,6 +23,7 @@ #include "cmLocalGenerator.h" #include "cmLocalNinjaGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmNinjaLinkLineComputer.h" #include "cmOutputConverter.h" #include "cmState.h" @@ -447,8 +448,6 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm) , BuildFileStream(nullptr) , RulesFileStream(nullptr) , CompileCommandsStream(nullptr) - , Rules() - , AllDependencies() , UsingGCCOnWindows(false) , ComputingUnknownDependencies(false) , PolicyCMP0058(cmPolicies::WARN) @@ -504,7 +503,8 @@ void cmGlobalNinjaGenerator::Generate() msg << "The detected version of Ninja (" << this->NinjaVersion; msg << ") is less than the version of Ninja required by CMake ("; msg << cmGlobalNinjaGenerator::RequiredNinjaVersion() << ")."; - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str()); + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + msg.str()); return; } this->OpenBuildFileStream(); @@ -556,7 +556,7 @@ bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf) if (!cmSystemTools::RunSingleCommand(command, &version, &error, nullptr, nullptr, cmSystemTools::OUTPUT_NONE)) { - mf->IssueMessage(cmake::FATAL_ERROR, + mf->IssueMessage(MessageType::FATAL_ERROR, "Running\n '" + cmJoin(command, "' '") + "'\n" "failed with:\n " + @@ -636,7 +636,7 @@ bool cmGlobalNinjaGenerator::CheckFortran(cmMakefile* mf) const ; /* clang-format on */ } - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return false; } @@ -1302,7 +1302,8 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) "options to the custom commands that produce these files." ; /* clang-format on */ - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING, + w.str()); } } @@ -1430,7 +1431,8 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) << "\n"; msg << "Any pre-check scripts, such as those generated for file(GLOB " "CONFIGURE_DEPENDS), will not be run by Ninja."; - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); + this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING, + msg.str()); } std::sort(implicitDeps.begin(), implicitDeps.end()); diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index db72353..ceee500 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -7,6 +7,7 @@ #include <sstream> #include <utility> +#include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" @@ -494,6 +495,7 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( const std::string& targetName, const std::string& /*config*/, bool fast, int jobs, bool /*verbose*/, std::vector<std::string> const& makeOptions) { + std::unique_ptr<cmMakefile> mfu; cmMakefile* mf; if (!this->Makefiles.empty()) { mf = this->Makefiles[0]; @@ -504,7 +506,8 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( snapshot.GetDirectory().SetCurrentBinary( this->CMakeInstance->GetHomeOutputDirectory()); snapshot.SetDefaultDefinitions(); - mf = new cmMakefile(this, snapshot); + mfu = cm::make_unique<cmMakefile>(this, snapshot); + mf = mfu.get(); } makeCommand.push_back(this->SelectMakeProgram(makeProgram)); @@ -529,9 +532,6 @@ void cmGlobalUnixMakefileGenerator3::GenerateBuildCommand( cmSystemTools::ConvertToOutputSlashes(tname); makeCommand.push_back(std::move(tname)); } - if (this->Makefiles.empty()) { - delete mf; - } } void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules( diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index a2ad095..6199586 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -217,11 +217,8 @@ protected: // Store per-target progress counters. struct TargetProgress { - TargetProgress() - : NumberOfActions(0) - { - } - unsigned long NumberOfActions; + TargetProgress() {} + unsigned long NumberOfActions = 0; std::string VariableFile; std::vector<unsigned long> Marks; void WriteProgressVariables(unsigned long total, unsigned long& current); diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index c9c6938..79757a8 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -7,6 +7,7 @@ #include "cmGeneratorTarget.h" #include "cmLocalVisualStudio10Generator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSourceFile.h" #include "cmVersion.h" #include "cmVisualStudioSlnData.h" @@ -90,8 +91,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory() } cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator( - cmake* cm, const std::string& name, const std::string& platformName) - : cmGlobalVisualStudio8Generator(cm, name, platformName) + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio8Generator(cm, name, platformInGeneratorName) { std::string vc10Express; this->ExpressEdition = cmSystemTools::ReadRegistryValue( @@ -178,7 +180,7 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( std::ostringstream e; e << this->GetName() << " Windows CE version '" << this->SystemVersion << "' requires CMAKE_GENERATOR_TOOLSET to be set."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -251,7 +253,7 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( "contains an invalid version specification." ; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); // Clear the configured tool-set this->GeneratorToolsetVersion.clear(); @@ -278,7 +280,7 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset( " " << toolsetPath; ; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); // Clear the configured tool-set this->GeneratorToolsetVersion.clear(); @@ -332,7 +334,7 @@ bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset( "that contains a field after the first ',' with no '='." ; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } std::string const key = fi->substr(0, pos); @@ -348,7 +350,7 @@ bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset( "that contains duplicate field key '" << key << "'." ; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } if (!this->ProcessGeneratorToolsetField(key, value)) { @@ -362,7 +364,7 @@ bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset( "that contains invalid field '" << *fi << "'." ; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } } @@ -406,16 +408,16 @@ bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf) return false; } } else if (this->SystemName == "Android") { - if (this->DefaultPlatformName != "Win32") { + if (this->PlatformInGeneratorName) { std::ostringstream e; e << "CMAKE_SYSTEM_NAME is 'Android' but CMAKE_GENERATOR " << "specifies a platform too: '" << this->GetName() << "'"; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } std::string v = this->GetInstalledNsightTegraVersion(); if (v.empty()) { - mf->IssueMessage(cmake::FATAL_ERROR, + mf->IssueMessage(MessageType::FATAL_ERROR, "CMAKE_SYSTEM_NAME is 'Android' but " "'NVIDIA Nsight Tegra Visual Studio Edition' " "is not installed."); @@ -437,11 +439,11 @@ bool cmGlobalVisualStudio10Generator::InitializeWindows(cmMakefile*) bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf) { - if (this->DefaultPlatformName != "Win32") { + if (this->PlatformInGeneratorName) { std::ostringstream e; e << "CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR " << "specifies a platform too: '" << this->GetName() << "'"; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -454,7 +456,7 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf) { std::ostringstream e; e << this->GetName() << " does not support Windows Phone."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -462,7 +464,7 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf) { std::ostringstream e; e << this->GetName() << " does not support Windows Store."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -488,16 +490,6 @@ std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const return ""; } -void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout) -{ - fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n"; - if (this->ExpressEdition) { - fout << "# Visual C++ Express 2010\n"; - } else { - fout << "# Visual Studio 2010\n"; - } -} - ///! Create a local generator appropriate to this Global Generator cmLocalGenerator* cmGlobalVisualStudio10Generator::CreateLocalGenerator( cmMakefile* mf) @@ -533,7 +525,7 @@ void cmGlobalVisualStudio10Generator::Generate() "To avoid this problem CMake must use a full path for this file " "which then triggers the VS 10 property dialog bug."; /* clang-format on */ - lg->IssueMessage(cmake::WARNING, e.str().c_str()); + lg->IssueMessage(MessageType::WARNING, e.str().c_str()); } } @@ -716,7 +708,7 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) // Prepare the work directory. if (!cmSystemTools::MakeDirectory(wd)) { std::string e = "Failed to make directory:\n " + wd; - mf->IssueMessage(cmake::FATAL_ERROR, e.c_str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.c_str()); cmSystemTools::SetFatalErrorOccured(); return false; } @@ -838,7 +830,7 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) if (ret != 0) { e << "Exit code: " << ret << "\n"; } - mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str()); cmSystemTools::SetFatalErrorOccured(); return false; } @@ -982,7 +974,7 @@ bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf) << "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n" << " http://msdn.microsoft.com/en-us/windows/bb980924.aspx"; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str()); cmSystemTools::SetFatalErrorOccured(); return false; } @@ -1024,6 +1016,29 @@ std::string cmGlobalVisualStudio10Generator::Encoding() return "utf-8"; } +const char* cmGlobalVisualStudio10Generator::GetToolsVersion() const +{ + switch (this->Version) { + case cmGlobalVisualStudioGenerator::VS9: + case cmGlobalVisualStudioGenerator::VS10: + case cmGlobalVisualStudioGenerator::VS11: + return "4.0"; + + // in Visual Studio 2013 they detached the MSBuild tools version + // from the .Net Framework version and instead made it have it's own + // version number + case cmGlobalVisualStudioGenerator::VS12: + return "12.0"; + case cmGlobalVisualStudioGenerator::VS14: + return "14.0"; + case cmGlobalVisualStudioGenerator::VS15: + return "15.0"; + case cmGlobalVisualStudioGenerator::VS16: + return "16.0"; + } + return ""; +} + bool cmGlobalVisualStudio10Generator::IsNsightTegra() const { return !this->NsightTegraVersion.empty(); @@ -1123,14 +1138,32 @@ static cmIDEFlagTable const* cmLoadFlagTableJson( return ret; } +static std::string cmGetFlagTableName(std::string const& toolsetName, + std::string const& table) +{ + return cmSystemTools::GetCMakeRoot() + "/Templates/MSBuild/FlagTables/" + + toolsetName + "_" + table + ".json"; +} + cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable( - std::string const& flagTableName, std::string const& table) const + std::string const& optionsName, std::string const& toolsetName, + std::string const& defaultName, std::string const& table) const { cmIDEFlagTable const* ret = nullptr; - std::string filename = cmSystemTools::GetCMakeRoot() + - "/Templates/MSBuild/FlagTables/" + flagTableName + "_" + table + ".json"; - ret = cmLoadFlagTableJson(filename); + std::string filename; + if (!optionsName.empty()) { + filename = cmGetFlagTableName(optionsName, table); + ret = cmLoadFlagTableJson(filename); + } else { + filename = cmGetFlagTableName(toolsetName, table); + if (cmSystemTools::FileExists(filename)) { + ret = cmLoadFlagTableJson(filename); + } else { + filename = cmGetFlagTableName(defaultName, table); + ret = cmLoadFlagTableJson(filename); + } + } if (!ret) { cmMakefile* mf = this->GetCurrentMakefile(); @@ -1140,78 +1173,102 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable( e << "JSON flag table \"" << filename << "\" could not be loaded.\n"; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str()); } return ret; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const { - std::string flagTableName = this->ToolsetOptions.GetClFlagTableName( - this->GetPlatformName(), this->GetPlatformToolsetString(), - this->DefaultCLFlagTableName); - - return LoadFlagTable(flagTableName, "CL"); + std::string optionsName = this->ToolsetOptions.GetClFlagTableName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultCLFlagTableName); + return LoadFlagTable(optionsName, toolsetName, defaultName, "CL"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable() const { - std::string flagTableName = this->ToolsetOptions.GetCSharpFlagTableName( - this->GetPlatformName(), this->GetPlatformToolsetString(), - this->DefaultCSharpFlagTableName); - - return LoadFlagTable(flagTableName, "CSharp"); + std::string optionsName = this->ToolsetOptions.GetCSharpFlagTableName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultCSharpFlagTableName); + return LoadFlagTable(optionsName, toolsetName, defaultName, "CSharp"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const { - std::string flagTableName = this->ToolsetOptions.GetRcFlagTableName( - this->GetPlatformName(), this->GetPlatformToolsetString(), - this->DefaultRCFlagTableName); - - return LoadFlagTable(flagTableName, "RC"); + std::string optionsName = this->ToolsetOptions.GetRcFlagTableName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultRCFlagTableName); + return LoadFlagTable(optionsName, toolsetName, defaultName, "RC"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const { - std::string flagTableName = this->ToolsetOptions.GetLibFlagTableName( - this->GetPlatformName(), this->GetPlatformToolsetString(), - this->DefaultLibFlagTableName); - - return LoadFlagTable(flagTableName, "LIB"); + std::string optionsName = this->ToolsetOptions.GetLibFlagTableName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultLibFlagTableName); + return LoadFlagTable(optionsName, toolsetName, defaultName, "LIB"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const { - std::string flagTableName = this->ToolsetOptions.GetLinkFlagTableName( - this->GetPlatformName(), this->GetPlatformToolsetString(), - this->DefaultLinkFlagTableName); - - return LoadFlagTable(flagTableName, "Link"); + std::string optionsName = this->ToolsetOptions.GetLinkFlagTableName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultLinkFlagTableName); + return LoadFlagTable(optionsName, toolsetName, defaultName, "Link"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const { - return LoadFlagTable(this->DefaultCudaFlagTableName, "Cuda"); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultCudaFlagTableName); + return LoadFlagTable("", toolsetName, defaultName, "Cuda"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable() const { - return LoadFlagTable(this->DefaultCudaHostFlagTableName, "CudaHost"); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultCudaHostFlagTableName); + return LoadFlagTable("", toolsetName, defaultName, "CudaHost"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const { - std::string flagTableName = this->ToolsetOptions.GetMasmFlagTableName( - this->GetPlatformName(), this->GetPlatformToolsetString(), - this->DefaultMasmFlagTableName); - - return LoadFlagTable(flagTableName, "MASM"); + std::string optionsName = this->ToolsetOptions.GetMasmFlagTableName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultMasmFlagTableName); + return LoadFlagTable(optionsName, toolsetName, defaultName, "MASM"); } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const { - return LoadFlagTable(this->DefaultNasmFlagTableName, "NASM"); + std::string toolsetName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->GetPlatformToolsetString()); + std::string defaultName = this->ToolsetOptions.GetToolsetName( + this->GetPlatformName(), this->DefaultNasmFlagTableName); + return LoadFlagTable("", toolsetName, defaultName, "NASM"); } diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 6c4a9e6..7c8918a 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -14,8 +14,6 @@ class cmGlobalVisualStudio10Generator : public cmGlobalVisualStudio8Generator { public: - cmGlobalVisualStudio10Generator(cmake* cm, const std::string& name, - const std::string& platformName); static cmGlobalGeneratorFactory* NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; @@ -43,7 +41,6 @@ public: */ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*, bool optional) override; - void WriteSLNHeader(std::ostream& fout) override; bool IsCudaEnabled() const { return this->CudaEnabled; } @@ -86,7 +83,7 @@ public: } /** Return true if building for WindowsCE */ - bool TargetsWindowsCE() const { return this->SystemIsWindowsCE; } + bool TargetsWindowsCE() const override { return this->SystemIsWindowsCE; } /** Return true if building for WindowsPhone */ bool TargetsWindowsPhone() const { return this->SystemIsWindowsPhone; } @@ -104,7 +101,7 @@ public: std::string const& sfRel); std::string Encoding() override; - virtual const char* GetToolsVersion() { return "4.0"; } + const char* GetToolsVersion() const; virtual bool IsDefaultToolset(const std::string& version) const; virtual std::string GetAuxiliaryToolset() const; @@ -126,6 +123,9 @@ public: cmIDEFlagTable const* GetNasmFlagTable() const; protected: + cmGlobalVisualStudio10Generator(cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); + void Generate() override; virtual bool InitializeSystem(cmMakefile* mf); virtual bool InitializeWindows(cmMakefile* mf); @@ -140,11 +140,11 @@ protected: virtual bool SelectWindowsPhoneToolset(std::string& toolset) const; virtual bool SelectWindowsStoreToolset(std::string& toolset) const; - const char* GetIDEVersion() override { return "10.0"; } - std::string const& GetMSBuildCommand(); - cmIDEFlagTable const* LoadFlagTable(std::string const& flagTableName, + cmIDEFlagTable const* LoadFlagTable(std::string const& optionsName, + std::string const& toolsetName, + std::string const& defaultName, std::string const& table) const; std::string GeneratorToolset; @@ -171,6 +171,8 @@ protected: private: class Factory; + friend class Factory; + struct LongestSourcePath { LongestSourcePath() diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx index e40023d..36eb492 100644 --- a/Source/cmGlobalVisualStudio11Generator.cxx +++ b/Source/cmGlobalVisualStudio11Generator.cxx @@ -92,8 +92,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory() } cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator( - cmake* cm, const std::string& name, const std::string& platformName) - : cmGlobalVisualStudio10Generator(cm, name, platformName) + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio10Generator(cm, name, platformInGeneratorName) { std::string vc11Express; this->ExpressEdition = cmSystemTools::ReadRegistryValue( @@ -132,7 +133,7 @@ bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf) << "Desktop SDK as well as the Windows Phone '" << this->SystemVersion << "' SDK. Please make sure that you have both installed"; } - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } return true; @@ -150,7 +151,7 @@ bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf) << "Desktop SDK as well as the Windows Store '" << this->SystemVersion << "' SDK. Please make sure that you have both installed"; } - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } return true; @@ -188,17 +189,7 @@ bool cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset( toolset); } -void cmGlobalVisualStudio11Generator::WriteSLNHeader(std::ostream& fout) -{ - fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; - if (this->ExpressEdition) { - fout << "# Visual Studio Express 2012 for Windows Desktop\n"; - } else { - fout << "# Visual Studio 2012\n"; - } -} - -bool cmGlobalVisualStudio11Generator::UseFolderProperty() +bool cmGlobalVisualStudio11Generator::UseFolderProperty() const { // Intentionally skip up to the top-level class implementation. // Folders are not supported by the Express editions in VS10 and earlier, diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h index 40f02fb..8b4c8b7 100644 --- a/Source/cmGlobalVisualStudio11Generator.h +++ b/Source/cmGlobalVisualStudio11Generator.h @@ -20,15 +20,14 @@ class cmake; class cmGlobalVisualStudio11Generator : public cmGlobalVisualStudio10Generator { public: - cmGlobalVisualStudio11Generator(cmake* cm, const std::string& name, - const std::string& platformName); static cmGlobalGeneratorFactory* NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; - void WriteSLNHeader(std::ostream& fout) override; - protected: + cmGlobalVisualStudio11Generator(cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); + bool InitializeWindowsPhone(cmMakefile* mf) override; bool InitializeWindowsStore(cmMakefile* mf) override; bool SelectWindowsPhoneToolset(std::string& toolset) const override; @@ -43,8 +42,7 @@ protected: bool IsWindowsPhoneToolsetInstalled() const; bool IsWindowsStoreToolsetInstalled() const; - const char* GetIDEVersion() override { return "11.0"; } - bool UseFolderProperty(); + bool UseFolderProperty() const override; static std::set<std::string> GetInstalledWindowsCESDKs(); /** Return true if the configuration needs to be deployed */ diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index 3be7d24..61034a7 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -75,8 +75,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory() } cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator( - cmake* cm, const std::string& name, const std::string& platformName) - : cmGlobalVisualStudio11Generator(cm, name, platformName) + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio11Generator(cm, name, platformInGeneratorName) { std::string vc12Express; this->ExpressEdition = cmSystemTools::ReadRegistryValue( @@ -128,7 +129,7 @@ bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf) << "Desktop SDK as well as the Windows Phone '" << this->SystemVersion << "' SDK. Please make sure that you have both installed"; } - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } return true; @@ -148,7 +149,7 @@ bool cmGlobalVisualStudio12Generator::InitializeWindowsStore(cmMakefile* mf) << "Desktop SDK as well as the Windows Store '" << this->SystemVersion << "' SDK. Please make sure that you have both installed"; } - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } return true; @@ -186,16 +187,6 @@ bool cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset( toolset); } -void cmGlobalVisualStudio12Generator::WriteSLNHeader(std::ostream& fout) -{ - fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; - if (this->ExpressEdition) { - fout << "# Visual Studio Express 2013 for Windows Desktop\n"; - } else { - fout << "# Visual Studio 2013\n"; - } -} - bool cmGlobalVisualStudio12Generator::IsWindowsDesktopToolsetInstalled() const { const char desktop81Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h index 9d6554a..53b7091 100644 --- a/Source/cmGlobalVisualStudio12Generator.h +++ b/Source/cmGlobalVisualStudio12Generator.h @@ -18,20 +18,14 @@ class cmake; class cmGlobalVisualStudio12Generator : public cmGlobalVisualStudio11Generator { public: - cmGlobalVisualStudio12Generator(cmake* cm, const std::string& name, - const std::string& platformName); static cmGlobalGeneratorFactory* NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; - void WriteSLNHeader(std::ostream& fout) override; - - // in Visual Studio 2013 they detached the MSBuild tools version - // from the .Net Framework version and instead made it have it's own - // version number - const char* GetToolsVersion() override { return "12.0"; } - protected: + cmGlobalVisualStudio12Generator(cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); + bool ProcessGeneratorToolsetField(std::string const& key, std::string const& value) override; @@ -48,9 +42,9 @@ protected: // of the toolset is installed bool IsWindowsPhoneToolsetInstalled() const; bool IsWindowsStoreToolsetInstalled() const; - const char* GetIDEVersion() override { return "12.0"; } private: class Factory; + friend class Factory; }; #endif diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index ac969e8..5ea5e67 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -75,8 +75,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory() } cmGlobalVisualStudio14Generator::cmGlobalVisualStudio14Generator( - cmake* cm, const std::string& name, const std::string& platformName) - : cmGlobalVisualStudio12Generator(cm, name, platformName) + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio12Generator(cm, name, platformInGeneratorName) { std::string vc14Express; this->ExpressEdition = cmSystemTools::ReadRegistryValue( @@ -125,7 +126,7 @@ bool cmGlobalVisualStudio14Generator::InitializeWindowsStore(cmMakefile* mf) << "Desktop SDK as well as the Windows Store '" << this->SystemVersion << "' SDK. Please make sure that you have both installed"; } - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) { @@ -143,7 +144,7 @@ bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf, std::ostringstream e; e << "Could not find an appropriate version of the Windows 10 SDK" << " installed on this machine"; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } if (!cmSystemTools::VersionCompareEqual(this->WindowsTargetPlatformVersion, @@ -174,17 +175,6 @@ bool cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( toolset); } -void cmGlobalVisualStudio14Generator::WriteSLNHeader(std::ostream& fout) -{ - // Visual Studio 14 writes .sln format 12.00 - fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; - if (this->ExpressEdition) { - fout << "# Visual Studio Express 14 for Windows Desktop\n"; - } else { - fout << "# Visual Studio 14\n"; - } -} - bool cmGlobalVisualStudio14Generator::IsWindowsDesktopToolsetInstalled() const { const char desktop10Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index 9f5bb4e..32008b0 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -18,17 +18,14 @@ class cmake; class cmGlobalVisualStudio14Generator : public cmGlobalVisualStudio12Generator { public: - cmGlobalVisualStudio14Generator(cmake* cm, const std::string& name, - const std::string& platformName); static cmGlobalGeneratorFactory* NewFactory(); bool MatchesGeneratorName(const std::string& name) const override; - void WriteSLNHeader(std::ostream& fout) override; - - const char* GetToolsVersion() override { return "14.0"; } - protected: + cmGlobalVisualStudio14Generator(cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); + bool InitializeWindows(cmMakefile* mf) override; bool InitializeWindowsStore(cmMakefile* mf) override; bool SelectWindowsStoreToolset(std::string& toolset) const override; @@ -41,7 +38,6 @@ protected: // version of the toolset. virtual std::string GetWindows10SDKMaxVersion() const; - const char* GetIDEVersion() override { return "14.0"; } virtual bool SelectWindows10SDK(cmMakefile* mf, bool required); // Used to verify that the Desktop toolset for the current generator is @@ -52,5 +48,6 @@ protected: private: class Factory; + friend class Factory; }; #endif diff --git a/Source/cmGlobalVisualStudio15Generator.cxx b/Source/cmGlobalVisualStudio15Generator.cxx deleted file mode 100644 index 2853283..0000000 --- a/Source/cmGlobalVisualStudio15Generator.cxx +++ /dev/null @@ -1,295 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmGlobalVisualStudio15Generator.h" - -#include "cmAlgorithms.h" -#include "cmDocumentationEntry.h" -#include "cmLocalVisualStudio10Generator.h" -#include "cmMakefile.h" -#include "cmVSSetupHelper.h" - -static const char vs15generatorName[] = "Visual Studio 15 2017"; - -// Map generator name without year to name with year. -static const char* cmVS15GenName(const std::string& name, std::string& genName) -{ - if (strncmp(name.c_str(), vs15generatorName, - sizeof(vs15generatorName) - 6) != 0) { - return 0; - } - const char* p = name.c_str() + sizeof(vs15generatorName) - 6; - if (cmHasLiteralPrefix(p, " 2017")) { - p += 5; - } - genName = std::string(vs15generatorName) + p; - return p; -} - -class cmGlobalVisualStudio15Generator::Factory - : public cmGlobalGeneratorFactory -{ -public: - virtual cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const - { - std::string genName; - const char* p = cmVS15GenName(name, genName); - if (!p) { - return 0; - } - if (!*p) { - return new cmGlobalVisualStudio15Generator(cm, genName, ""); - } - if (*p++ != ' ') { - return 0; - } - if (strcmp(p, "Win64") == 0) { - return new cmGlobalVisualStudio15Generator(cm, genName, "x64"); - } - if (strcmp(p, "ARM") == 0) { - return new cmGlobalVisualStudio15Generator(cm, genName, "ARM"); - } - return 0; - } - - virtual void GetDocumentation(cmDocumentationEntry& entry) const - { - entry.Name = std::string(vs15generatorName) + " [arch]"; - entry.Brief = "Generates Visual Studio 2017 project files. " - "Optional [arch] can be \"Win64\" or \"ARM\"."; - } - - virtual void GetGenerators(std::vector<std::string>& names) const - { - names.push_back(vs15generatorName); - names.push_back(vs15generatorName + std::string(" ARM")); - names.push_back(vs15generatorName + std::string(" Win64")); - } - - bool SupportsToolset() const override { return true; } - bool SupportsPlatform() const override { return true; } -}; - -cmGlobalGeneratorFactory* cmGlobalVisualStudio15Generator::NewFactory() -{ - return new Factory; -} - -cmGlobalVisualStudio15Generator::cmGlobalVisualStudio15Generator( - cmake* cm, const std::string& name, const std::string& platformName) - : cmGlobalVisualStudio14Generator(cm, name, platformName) -{ - this->ExpressEdition = false; - this->DefaultPlatformToolset = "v141"; - this->DefaultCLFlagTableName = "v141"; - this->DefaultCSharpFlagTableName = "v141"; - this->DefaultLinkFlagTableName = "v141"; - this->Version = VS15; -} - -bool cmGlobalVisualStudio15Generator::MatchesGeneratorName( - const std::string& name) const -{ - std::string genName; - if (cmVS15GenName(name, genName)) { - return genName == this->GetName(); - } - return false; -} - -void cmGlobalVisualStudio15Generator::WriteSLNHeader(std::ostream& fout) -{ - // Visual Studio 15 writes .sln format 12.00 - fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; - if (this->ExpressEdition) { - fout << "# Visual Studio Express 15 for Windows Desktop\n"; - } else { - fout << "# Visual Studio 15\n"; - } -} - -bool cmGlobalVisualStudio15Generator::SetGeneratorInstance( - std::string const& i, cmMakefile* mf) -{ - if (!i.empty()) { - if (!this->vsSetupAPIHelper.SetVSInstance(i)) { - std::ostringstream e; - /* clang-format off */ - e << - "Generator\n" - " " << this->GetName() << "\n" - "could not find specified instance of Visual Studio:\n" - " " << i; - /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); - return false; - } - } - - std::string vsInstance; - if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) { - std::ostringstream e; - /* clang-format off */ - e << - "Generator\n" - " " << this->GetName() << "\n" - "could not find any instance of Visual Studio.\n"; - /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); - return false; - } - - // Save the selected instance persistently. - std::string genInstance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE"); - if (vsInstance != genInstance) { - this->CMakeInstance->AddCacheEntry( - "CMAKE_GENERATOR_INSTANCE", vsInstance.c_str(), - "Generator instance identifier.", cmStateEnums::INTERNAL); - } - - return true; -} - -bool cmGlobalVisualStudio15Generator::GetVSInstance(std::string& dir) const -{ - return vsSetupAPIHelper.GetVSInstanceInfo(dir); -} - -bool cmGlobalVisualStudio15Generator::IsDefaultToolset( - const std::string& version) const -{ - if (version.empty()) { - return true; - } - - std::string vcToolsetVersion; - if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) { - - cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9]+"); - if (regex.find(version) && regex.find(vcToolsetVersion)) { - const auto majorMinorEnd = vcToolsetVersion.find('.', 3); - const auto majorMinor = vcToolsetVersion.substr(0, majorMinorEnd); - return version == majorMinor; - } - } - - return false; -} - -std::string cmGlobalVisualStudio15Generator::GetAuxiliaryToolset() const -{ - const char* version = this->GetPlatformToolsetVersion(); - if (version) { - std::string instancePath; - GetVSInstance(instancePath); - std::stringstream path; - path << instancePath; - path << "/VC/Auxiliary/Build/"; - path << version; - path << "/Microsoft.VCToolsVersion." << version << ".props"; - - std::string toolsetPath = path.str(); - cmSystemTools::ConvertToUnixSlashes(toolsetPath); - return toolsetPath; - } - return {}; -} - -bool cmGlobalVisualStudio15Generator::InitializeWindows(cmMakefile* mf) -{ - // If the Win 8.1 SDK is installed then we can select a SDK matching - // the target Windows version. - if (this->IsWin81SDKInstalled()) { - return cmGlobalVisualStudio14Generator::InitializeWindows(mf); - } - // Otherwise we must choose a Win 10 SDK even if we are not targeting - // Windows 10. - return this->SelectWindows10SDK(mf, false); -} - -bool cmGlobalVisualStudio15Generator::SelectWindowsStoreToolset( - std::string& toolset) const -{ - if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) { - if (this->IsWindowsStoreToolsetInstalled() && - this->IsWindowsDesktopToolsetInstalled()) { - toolset = "v141"; // VS 15 uses v141 toolset - return true; - } else { - return false; - } - } - return this->cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( - toolset); -} - -bool cmGlobalVisualStudio15Generator::IsWindowsDesktopToolsetInstalled() const -{ - return vsSetupAPIHelper.IsVS2017Installed(); -} - -bool cmGlobalVisualStudio15Generator::IsWindowsStoreToolsetInstalled() const -{ - return vsSetupAPIHelper.IsWin10SDKInstalled(); -} - -bool cmGlobalVisualStudio15Generator::IsWin81SDKInstalled() const -{ - // Does the VS installer tool know about one? - if (vsSetupAPIHelper.IsWin81SDKInstalled()) { - return true; - } - - // Does the registry know about one (e.g. from VS 2015)? - std::string win81Root; - if (cmSystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" - "Windows Kits\\Installed Roots;KitsRoot81", - win81Root, cmSystemTools::KeyWOW64_32) || - cmSystemTools::ReadRegistryValue( - "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\" - "Windows Kits\\Installed Roots;KitsRoot81", - win81Root, cmSystemTools::KeyWOW64_32)) { - return cmSystemTools::FileExists(win81Root + "/um/windows.h", true); - } - return false; -} - -std::string cmGlobalVisualStudio15Generator::GetWindows10SDKMaxVersion() const -{ - return std::string(); -} - -std::string cmGlobalVisualStudio15Generator::FindMSBuildCommand() -{ - std::string msbuild; - - // Ask Visual Studio Installer tool. - std::string vs; - if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { - msbuild = vs + "/MSBuild/15.0/Bin/MSBuild.exe"; - if (cmSystemTools::FileExists(msbuild)) { - return msbuild; - } - } - - msbuild = "MSBuild.exe"; - return msbuild; -} - -std::string cmGlobalVisualStudio15Generator::FindDevEnvCommand() -{ - std::string devenv; - - // Ask Visual Studio Installer tool. - std::string vs; - if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { - devenv = vs + "/Common7/IDE/devenv.com"; - if (cmSystemTools::FileExists(devenv)) { - return devenv; - } - } - - devenv = "devenv.com"; - return devenv; -} diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index 3be09b0..16796cf 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -6,7 +6,7 @@ #include "cmGeneratorTarget.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" -#include "cmake.h" +#include "cmMessageType.h" cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator( cmake* cm, const std::string& platformName) @@ -217,9 +217,3 @@ void cmGlobalVisualStudio71Generator::WriteProjectConfigurations( } } } - -// output standard header for dsw file -void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout) -{ - fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n"; -} diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h index b6e3131..85755af 100644 --- a/Source/cmGlobalVisualStudio71Generator.h +++ b/Source/cmGlobalVisualStudio71Generator.h @@ -34,10 +34,9 @@ protected: void WriteExternalProject(std::ostream& fout, const std::string& name, const char* path, const char* typeGuid, const std::set<BT<std::string>>& depends) override; - void WriteSLNHeader(std::ostream& fout) override; // Folders are not supported by VS 7.1. - virtual bool UseFolderProperty() { return false; } + bool UseFolderProperty() const override { return false; } std::string ProjectConfigurationSectionName; }; diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 3648086..cae46e1 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -6,6 +6,7 @@ #include "cmGeneratorTarget.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmUuid.h" #include "cmake.h" @@ -41,19 +42,13 @@ static cmVS7FlagTable cmVS7ExtraFlagTable[] = { }; cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( - cmake* cm, const std::string& platformName) - : cmGlobalVisualStudioGenerator(cm) + cmake* cm, std::string const& platformInGeneratorName) + : cmGlobalVisualStudioGenerator(cm, platformInGeneratorName) { this->IntelProjectVersion = 0; this->DevEnvCommandInitialized = false; this->MasmEnabled = false; this->NasmEnabled = false; - - if (platformName.empty()) { - this->DefaultPlatformName = "Win32"; - } else { - this->DefaultPlatformName = platformName; - } this->ExtraFlagTable = cmVS7ExtraFlagTable; } @@ -263,14 +258,6 @@ Json::Value cmGlobalVisualStudio7Generator::GetJson() const } #endif -std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const -{ - if (!this->GeneratorPlatform.empty()) { - return this->GeneratorPlatform; - } - return this->DefaultPlatformName; -} - bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s, cmMakefile* mf) { @@ -279,18 +266,6 @@ bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s, return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf); } -bool cmGlobalVisualStudio7Generator::SetGeneratorPlatform(std::string const& p, - cmMakefile* mf) -{ - if (this->GetPlatformName() == "x64") { - mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE"); - } else if (this->GetPlatformName() == "Itanium") { - mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE"); - } - mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str()); - return this->cmGlobalVisualStudioGenerator::SetGeneratorPlatform(p, mf); -} - void cmGlobalVisualStudio7Generator::Generate() { // first do the superclass method diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 59e7a98..d2a2a38 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -18,13 +18,8 @@ struct cmIDEFlagTable; class cmGlobalVisualStudio7Generator : public cmGlobalVisualStudioGenerator { public: - cmGlobalVisualStudio7Generator(cmake* cm, - const std::string& platformName = ""); ~cmGlobalVisualStudio7Generator(); - ///! Get the name for the platform. - std::string const& GetPlatformName() const; - ///! Create a local generator appropriate to this Global Generator cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override; @@ -34,8 +29,6 @@ public: bool SetSystemName(std::string const& s, cmMakefile* mf) override; - bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override; - /** * Utilized by the generator factory to determine if this generator * supports toolsets. @@ -110,8 +103,10 @@ public: cmIDEFlagTable const* ExtraFlagTable; protected: + cmGlobalVisualStudio7Generator(cmake* cm, + std::string const& platformInGeneratorName); + void Generate() override; - virtual const char* GetIDEVersion() = 0; std::string const& GetDevEnvCommand(); virtual std::string FindDevEnvCommand(); @@ -135,7 +130,6 @@ protected: virtual void WriteSLNGlobalSections(std::ostream& fout, cmLocalGenerator* root); virtual void WriteSLNFooter(std::ostream& fout); - virtual void WriteSLNHeader(std::ostream& fout) = 0; std::string WriteUtilityDepend(const cmGeneratorTarget* target) override; virtual void WriteTargetsToSolution( @@ -168,8 +162,6 @@ protected: // Set during OutputSLNFile with the name of the current project. // There is one SLN file per project. std::string CurrentProject; - std::string GeneratorPlatform; - std::string DefaultPlatformName; bool MasmEnabled; bool NasmEnabled; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 097d7e2..4d165c2 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -7,13 +7,15 @@ #include "cmGeneratorTarget.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSourceFile.h" #include "cmVisualStudioWCEPlatformParser.h" #include "cmake.h" cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator( - cmake* cm, const std::string& name, const std::string& platformName) - : cmGlobalVisualStudio71Generator(cm, platformName) + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio71Generator(cm, platformInGeneratorName) { this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms"; this->Name = name; @@ -60,7 +62,7 @@ void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf) bool cmGlobalVisualStudio8Generator::SetGeneratorPlatform(std::string const& p, cmMakefile* mf) { - if (this->DefaultPlatformName == "Win32") { + if (!this->PlatformInGeneratorName) { this->GeneratorPlatform = p; return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform("", mf); } else { @@ -78,7 +80,7 @@ void cmGlobalVisualStudio8Generator::Configure() this->cmGlobalVisualStudio7Generator::Configure(); } -bool cmGlobalVisualStudio8Generator::UseFolderProperty() +bool cmGlobalVisualStudio8Generator::UseFolderProperty() const { return IsExpressEdition() ? false : cmGlobalGenerator::UseFolderProperty(); } diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index 6f64b9c..8719bf3 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -13,9 +13,6 @@ class cmGlobalVisualStudio8Generator : public cmGlobalVisualStudio71Generator { public: - cmGlobalVisualStudio8Generator(cmake* cm, const std::string& name, - const std::string& platformName); - ///! Get the name for the generator. std::string GetName() const override { return this->Name; } @@ -44,12 +41,11 @@ public: return !this->WindowsCEVersion.empty(); } - /** Is the installed VS an Express edition? */ - bool IsExpressEdition() const { return this->ExpressEdition; } - protected: + cmGlobalVisualStudio8Generator(cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); + void AddExtraIDETargets() override; - const char* GetIDEVersion() override { return "8.0"; } std::string FindDevEnvCommand() override; @@ -73,10 +69,9 @@ protected: const char* path, const cmGeneratorTarget* t) override; - bool UseFolderProperty(); + bool UseFolderProperty() const override; std::string Name; std::string WindowsCEVersion; - bool ExpressEdition; }; #endif diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx index 7ac3a6f..445b40c 100644 --- a/Source/cmGlobalVisualStudio9Generator.cxx +++ b/Source/cmGlobalVisualStudio9Generator.cxx @@ -5,8 +5,8 @@ #include "cmDocumentationEntry.h" #include "cmLocalVisualStudio7Generator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmVisualStudioWCEPlatformParser.h" -#include "cmake.h" static const char vs9generatorName[] = "Visual Studio 9 2008"; @@ -83,8 +83,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory() } cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator( - cmake* cm, const std::string& name, const std::string& platformName) - : cmGlobalVisualStudio8Generator(cm, name, platformName) + cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio8Generator(cm, name, platformInGeneratorName) { this->Version = VS9; std::string vc9Express; @@ -94,12 +95,6 @@ cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator( vc9Express, cmSystemTools::KeyWOW64_32); } -void cmGlobalVisualStudio9Generator::WriteSLNHeader(std::ostream& fout) -{ - fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n"; - fout << "# Visual Studio 2008\n"; -} - std::string cmGlobalVisualStudio9Generator::GetUserMacrosDirectory() { std::string base; diff --git a/Source/cmGlobalVisualStudio9Generator.h b/Source/cmGlobalVisualStudio9Generator.h index 2aa6a91..7bebfd6 100644 --- a/Source/cmGlobalVisualStudio9Generator.h +++ b/Source/cmGlobalVisualStudio9Generator.h @@ -13,17 +13,9 @@ class cmGlobalVisualStudio9Generator : public cmGlobalVisualStudio8Generator { public: - cmGlobalVisualStudio9Generator(cmake* cm, const std::string& name, - const std::string& platformName); static cmGlobalGeneratorFactory* NewFactory(); /** - * Try to determine system information such as shared library - * extension, pthreads, byte order etc. - */ - void WriteSLNHeader(std::ostream& fout) override; - - /** * Where does this version of Visual Studio look for macros for the * current user? Returns the empty string if this version of Visual * Studio does not implement support for VB macros. @@ -37,7 +29,8 @@ public: std::string GetUserMacrosRegKeyBase() override; protected: - const char* GetIDEVersion() override { return "9.0"; } + cmGlobalVisualStudio9Generator(cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); private: class Factory; diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index da3daf8..41d961c 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -19,13 +19,22 @@ #include "cmSourceFile.h" #include "cmState.h" #include "cmTarget.h" +#include "cmake.h" -cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(cmake* cm) +cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator( + cmake* cm, std::string const& platformInGeneratorName) : cmGlobalGenerator(cm) { cm->GetState()->SetIsGeneratorMultiConfig(true); cm->GetState()->SetWindowsShell(true); cm->GetState()->SetWindowsVSIDE(true); + + if (platformInGeneratorName.empty()) { + this->DefaultPlatformName = "Win32"; + } else { + this->DefaultPlatformName = platformInGeneratorName; + this->PlatformInGeneratorName = true; + } } cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator() @@ -43,6 +52,108 @@ void cmGlobalVisualStudioGenerator::SetVersion(VSVersion v) this->Version = v; } +bool cmGlobalVisualStudioGenerator::SetGeneratorPlatform(std::string const& p, + cmMakefile* mf) +{ + if (this->GetPlatformName() == "x64") { + mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE"); + } else if (this->GetPlatformName() == "Itanium") { + mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE"); + } + mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str()); + return this->cmGlobalGenerator::SetGeneratorPlatform(p, mf); +} + +std::string const& cmGlobalVisualStudioGenerator::GetPlatformName() const +{ + if (!this->GeneratorPlatform.empty()) { + return this->GeneratorPlatform; + } + return this->DefaultPlatformName; +} + +const char* cmGlobalVisualStudioGenerator::GetIDEVersion() const +{ + switch (this->Version) { + case cmGlobalVisualStudioGenerator::VS9: + return "9.0"; + case cmGlobalVisualStudioGenerator::VS10: + return "10.0"; + case cmGlobalVisualStudioGenerator::VS11: + return "11.0"; + case cmGlobalVisualStudioGenerator::VS12: + return "12.0"; + case cmGlobalVisualStudioGenerator::VS14: + return "14.0"; + case cmGlobalVisualStudioGenerator::VS15: + return "15.0"; + case cmGlobalVisualStudioGenerator::VS16: + return "16.0"; + } + return ""; +} + +void cmGlobalVisualStudioGenerator::WriteSLNHeader(std::ostream& fout) +{ + switch (this->Version) { + case cmGlobalVisualStudioGenerator::VS9: + fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n"; + fout << "# Visual Studio 2008\n"; + break; + case cmGlobalVisualStudioGenerator::VS10: + fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n"; + if (this->ExpressEdition) { + fout << "# Visual C++ Express 2010\n"; + } else { + fout << "# Visual Studio 2010\n"; + } + break; + case cmGlobalVisualStudioGenerator::VS11: + fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; + if (this->ExpressEdition) { + fout << "# Visual Studio Express 2012 for Windows Desktop\n"; + } else { + fout << "# Visual Studio 2012\n"; + } + break; + case cmGlobalVisualStudioGenerator::VS12: + fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; + if (this->ExpressEdition) { + fout << "# Visual Studio Express 2013 for Windows Desktop\n"; + } else { + fout << "# Visual Studio 2013\n"; + } + break; + case cmGlobalVisualStudioGenerator::VS14: + // Visual Studio 14 writes .sln format 12.00 + fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; + if (this->ExpressEdition) { + fout << "# Visual Studio Express 14 for Windows Desktop\n"; + } else { + fout << "# Visual Studio 14\n"; + } + break; + case cmGlobalVisualStudioGenerator::VS15: + // Visual Studio 15 writes .sln format 12.00 + fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; + if (this->ExpressEdition) { + fout << "# Visual Studio Express 15 for Windows Desktop\n"; + } else { + fout << "# Visual Studio 15\n"; + } + break; + case cmGlobalVisualStudioGenerator::VS16: + // Visual Studio 16 writes .sln format 12.00 + fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n"; + if (this->ExpressEdition) { + fout << "# Visual Studio Express 16 for Windows Desktop\n"; + } else { + fout << "# Visual Studio 16\n"; + } + break; + } +} + std::string cmGlobalVisualStudioGenerator::GetRegistryBase() { return cmGlobalVisualStudioGenerator::GetRegistryBase(this->GetIDEVersion()); @@ -413,7 +524,7 @@ std::string cmGlobalVisualStudioGenerator::GetStartupProjectName( return startup; } else { root->GetMakefile()->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, "Directory property VS_STARTUP_PROJECT specifies target " "'" + startup + "' that does not exist. Ignoring."); diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index 07bc9a3..039191c 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -38,15 +38,26 @@ public: VS12 = 120, /* VS13 = 130 was skipped */ VS14 = 140, - VS15 = 150 + VS15 = 150, + VS16 = 160 }; - cmGlobalVisualStudioGenerator(cmake* cm); virtual ~cmGlobalVisualStudioGenerator(); VSVersion GetVersion() const; void SetVersion(VSVersion v); + /** Is the installed VS an Express edition? */ + bool IsExpressEdition() const { return this->ExpressEdition; } + + bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override; + + /** + * Get the name of the target platform (architecture) for which we generate. + * The names are as defined by VS, e.g. "Win32", "x64", "Itanium", "ARM". + */ + std::string const& GetPlatformName() const; + /** * Configure CMake's Visual Studio macros file into the user's Visual * Studio macros directory. @@ -118,7 +129,7 @@ public: std::string ExpandCFGIntDir(const std::string& str, const std::string& config) const override; - void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const; + void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override; std::string GetStartupProjectName(cmLocalGenerator const* root) const; @@ -130,6 +141,9 @@ public: bool dryRun) override; protected: + cmGlobalVisualStudioGenerator(cmake* cm, + std::string const& platformInGeneratorName); + void AddExtraIDETargets() override; // Does this VS version link targets to each other if there are @@ -137,7 +151,9 @@ protected: // below 8. virtual bool VSLinksDependencies() const { return true; } - virtual const char* GetIDEVersion() = 0; + const char* GetIDEVersion() const; + + void WriteSLNHeader(std::ostream& fout); bool ComputeTargetDepends() override; class VSDependSet : public std::set<std::string> @@ -159,11 +175,16 @@ protected: protected: VSVersion Version; + bool ExpressEdition; + + std::string GeneratorPlatform; + std::string DefaultPlatformName; + bool PlatformInGeneratorName = false; private: virtual std::string GetVSMakeProgram() = 0; void PrintCompilerAdvice(std::ostream&, std::string const&, - const char*) const + const char*) const override { } diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx new file mode 100644 index 0000000..99f9503 --- /dev/null +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -0,0 +1,439 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmGlobalVisualStudioVersionedGenerator.h" + +#include "cmAlgorithms.h" +#include "cmDocumentationEntry.h" +#include "cmLocalVisualStudio10Generator.h" +#include "cmMakefile.h" +#include "cmVSSetupHelper.h" +#include "cmake.h" + +#if defined(_M_ARM64) +# define HOST_PLATFORM_NAME "ARM64"; +#elif defined(_M_ARM) +# define HOST_PLATFORM_NAME "ARM"; +#elif defined(_M_IA64) +# define HOST_PLATFORM_NAME "Itanium"; +#else +# include "cmsys/SystemInformation.hxx" +#endif + +static unsigned int VSVersionToMajor( + cmGlobalVisualStudioGenerator::VSVersion v) +{ + switch (v) { + case cmGlobalVisualStudioGenerator::VS9: + return 9; + case cmGlobalVisualStudioGenerator::VS10: + return 10; + case cmGlobalVisualStudioGenerator::VS11: + return 11; + case cmGlobalVisualStudioGenerator::VS12: + return 12; + case cmGlobalVisualStudioGenerator::VS14: + return 14; + case cmGlobalVisualStudioGenerator::VS15: + return 15; + case cmGlobalVisualStudioGenerator::VS16: + return 16; + } + return 0; +} + +static const char* VSVersionToToolset( + cmGlobalVisualStudioGenerator::VSVersion v) +{ + switch (v) { + case cmGlobalVisualStudioGenerator::VS9: + return "v90"; + case cmGlobalVisualStudioGenerator::VS10: + return "v100"; + case cmGlobalVisualStudioGenerator::VS11: + return "v110"; + case cmGlobalVisualStudioGenerator::VS12: + return "v120"; + case cmGlobalVisualStudioGenerator::VS14: + return "v140"; + case cmGlobalVisualStudioGenerator::VS15: + return "v141"; + case cmGlobalVisualStudioGenerator::VS16: + // FIXME: VS 2019 Preview 1.1 uses v141 but preview 2 will use v142. + return "v141"; + } + return ""; +} + +static const char vs15generatorName[] = "Visual Studio 15 2017"; + +// Map generator name without year to name with year. +static const char* cmVS15GenName(const std::string& name, std::string& genName) +{ + if (strncmp(name.c_str(), vs15generatorName, + sizeof(vs15generatorName) - 6) != 0) { + return 0; + } + const char* p = name.c_str() + sizeof(vs15generatorName) - 6; + if (cmHasLiteralPrefix(p, " 2017")) { + p += 5; + } + genName = std::string(vs15generatorName) + p; + return p; +} + +class cmGlobalVisualStudioVersionedGenerator::Factory15 + : public cmGlobalGeneratorFactory +{ +public: + cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, + cmake* cm) const override + { + std::string genName; + const char* p = cmVS15GenName(name, genName); + if (!p) { + return 0; + } + if (!*p) { + return new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS15, cm, genName, ""); + } + if (*p++ != ' ') { + return 0; + } + if (strcmp(p, "Win64") == 0) { + return new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS15, cm, genName, "x64"); + } + if (strcmp(p, "ARM") == 0) { + return new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS15, cm, genName, "ARM"); + } + return 0; + } + + void GetDocumentation(cmDocumentationEntry& entry) const override + { + entry.Name = std::string(vs15generatorName) + " [arch]"; + entry.Brief = "Generates Visual Studio 2017 project files. " + "Optional [arch] can be \"Win64\" or \"ARM\"."; + } + + void GetGenerators(std::vector<std::string>& names) const override + { + names.push_back(vs15generatorName); + names.push_back(vs15generatorName + std::string(" ARM")); + names.push_back(vs15generatorName + std::string(" Win64")); + } + + bool SupportsToolset() const override { return true; } + bool SupportsPlatform() const override { return true; } +}; + +cmGlobalGeneratorFactory* +cmGlobalVisualStudioVersionedGenerator::NewFactory15() +{ + return new Factory15; +} + +static const char vs16generatorName[] = "Visual Studio 16 2019"; + +// Map generator name without year to name with year. +static const char* cmVS16GenName(const std::string& name, std::string& genName) +{ + if (strncmp(name.c_str(), vs16generatorName, + sizeof(vs16generatorName) - 6) != 0) { + return 0; + } + const char* p = name.c_str() + sizeof(vs16generatorName) - 6; + if (cmHasLiteralPrefix(p, " 2019")) { + p += 5; + } + genName = std::string(vs16generatorName) + p; + return p; +} + +class cmGlobalVisualStudioVersionedGenerator::Factory16 + : public cmGlobalGeneratorFactory +{ +public: + virtual cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, + cmake* cm) const + { + std::string genName; + const char* p = cmVS16GenName(name, genName); + if (!p) { + return 0; + } + if (!*p) { + return new cmGlobalVisualStudioVersionedGenerator( + cmGlobalVisualStudioGenerator::VS16, cm, genName, ""); + } + return 0; + } + + virtual void GetDocumentation(cmDocumentationEntry& entry) const + { + entry.Name = std::string(vs16generatorName); + entry.Brief = "Generates Visual Studio 2019 project files. " + "Use -A option to specify architecture."; + } + + virtual void GetGenerators(std::vector<std::string>& names) const + { + names.push_back(vs16generatorName); + } + + bool SupportsToolset() const override { return true; } + bool SupportsPlatform() const override { return true; } +}; + +cmGlobalGeneratorFactory* +cmGlobalVisualStudioVersionedGenerator::NewFactory16() +{ + return new Factory16; +} + +cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator( + VSVersion version, cmake* cm, const std::string& name, + std::string const& platformInGeneratorName) + : cmGlobalVisualStudio14Generator(cm, name, platformInGeneratorName) + , vsSetupAPIHelper(VSVersionToMajor(version)) +{ + this->Version = version; + this->ExpressEdition = false; + this->DefaultPlatformToolset = VSVersionToToolset(this->Version); + this->DefaultCLFlagTableName = VSVersionToToolset(this->Version); + this->DefaultCSharpFlagTableName = VSVersionToToolset(this->Version); + this->DefaultLinkFlagTableName = VSVersionToToolset(this->Version); + if (this->Version >= cmGlobalVisualStudioGenerator::VS16) { +#ifdef HOST_PLATFORM_NAME + this->DefaultPlatformName = HOST_PLATFORM_NAME; +#else + cmsys::SystemInformation info; + if (info.Is64Bits()) { + this->DefaultPlatformName = "x64"; + } else { + this->DefaultPlatformName = "Win32"; + } +#endif + } +} + +bool cmGlobalVisualStudioVersionedGenerator::MatchesGeneratorName( + const std::string& name) const +{ + std::string genName; + switch (this->Version) { + case cmGlobalVisualStudioGenerator::VS9: + case cmGlobalVisualStudioGenerator::VS10: + case cmGlobalVisualStudioGenerator::VS11: + case cmGlobalVisualStudioGenerator::VS12: + case cmGlobalVisualStudioGenerator::VS14: + break; + case cmGlobalVisualStudioGenerator::VS15: + if (cmVS15GenName(name, genName)) { + return genName == this->GetName(); + } + break; + case cmGlobalVisualStudioGenerator::VS16: + if (cmVS16GenName(name, genName)) { + return genName == this->GetName(); + } + break; + } + return false; +} + +bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance( + std::string const& i, cmMakefile* mf) +{ + if (!i.empty()) { + if (!this->vsSetupAPIHelper.SetVSInstance(i)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "could not find specified instance of Visual Studio:\n" + " " << i; + /* clang-format on */ + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return false; + } + } + + std::string vsInstance; + if (!this->vsSetupAPIHelper.GetVSInstanceInfo(vsInstance)) { + std::ostringstream e; + /* clang-format off */ + e << + "Generator\n" + " " << this->GetName() << "\n" + "could not find any instance of Visual Studio.\n"; + /* clang-format on */ + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return false; + } + + // Save the selected instance persistently. + std::string genInstance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE"); + if (vsInstance != genInstance) { + this->CMakeInstance->AddCacheEntry( + "CMAKE_GENERATOR_INSTANCE", vsInstance.c_str(), + "Generator instance identifier.", cmStateEnums::INTERNAL); + } + + return true; +} + +bool cmGlobalVisualStudioVersionedGenerator::GetVSInstance( + std::string& dir) const +{ + return vsSetupAPIHelper.GetVSInstanceInfo(dir); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsDefaultToolset( + const std::string& version) const +{ + if (version.empty()) { + return true; + } + + std::string vcToolsetVersion; + if (this->vsSetupAPIHelper.GetVCToolsetVersion(vcToolsetVersion)) { + + cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9]+"); + if (regex.find(version) && regex.find(vcToolsetVersion)) { + const auto majorMinorEnd = vcToolsetVersion.find('.', 3); + const auto majorMinor = vcToolsetVersion.substr(0, majorMinorEnd); + return version == majorMinor; + } + } + + return false; +} + +std::string cmGlobalVisualStudioVersionedGenerator::GetAuxiliaryToolset() const +{ + const char* version = this->GetPlatformToolsetVersion(); + if (version) { + std::string instancePath; + GetVSInstance(instancePath); + std::stringstream path; + path << instancePath; + path << "/VC/Auxiliary/Build/"; + path << version; + path << "/Microsoft.VCToolsVersion." << version << ".props"; + + std::string toolsetPath = path.str(); + cmSystemTools::ConvertToUnixSlashes(toolsetPath); + return toolsetPath; + } + return {}; +} + +bool cmGlobalVisualStudioVersionedGenerator::InitializeWindows(cmMakefile* mf) +{ + // If the Win 8.1 SDK is installed then we can select a SDK matching + // the target Windows version. + if (this->IsWin81SDKInstalled()) { + return cmGlobalVisualStudio14Generator::InitializeWindows(mf); + } + // Otherwise we must choose a Win 10 SDK even if we are not targeting + // Windows 10. + return this->SelectWindows10SDK(mf, false); +} + +bool cmGlobalVisualStudioVersionedGenerator::SelectWindowsStoreToolset( + std::string& toolset) const +{ + if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) { + if (this->IsWindowsStoreToolsetInstalled() && + this->IsWindowsDesktopToolsetInstalled()) { + toolset = VSVersionToToolset(this->Version); + return true; + } else { + return false; + } + } + return this->cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( + toolset); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsWindowsDesktopToolsetInstalled() + const +{ + return vsSetupAPIHelper.IsVSInstalled(); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsWindowsStoreToolsetInstalled() + const +{ + return vsSetupAPIHelper.IsWin10SDKInstalled(); +} + +bool cmGlobalVisualStudioVersionedGenerator::IsWin81SDKInstalled() const +{ + // Does the VS installer tool know about one? + if (vsSetupAPIHelper.IsWin81SDKInstalled()) { + return true; + } + + // Does the registry know about one (e.g. from VS 2015)? + std::string win81Root; + if (cmSystemTools::ReadRegistryValue( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + "Windows Kits\\Installed Roots;KitsRoot81", + win81Root, cmSystemTools::KeyWOW64_32) || + cmSystemTools::ReadRegistryValue( + "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\" + "Windows Kits\\Installed Roots;KitsRoot81", + win81Root, cmSystemTools::KeyWOW64_32)) { + return cmSystemTools::FileExists(win81Root + "/um/windows.h", true); + } + return false; +} + +std::string cmGlobalVisualStudioVersionedGenerator::GetWindows10SDKMaxVersion() + const +{ + return std::string(); +} + +std::string cmGlobalVisualStudioVersionedGenerator::FindMSBuildCommand() +{ + std::string msbuild; + + // Ask Visual Studio Installer tool. + std::string vs; + if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { + msbuild = vs + "/MSBuild/Current/Bin/MSBuild.exe"; + if (cmSystemTools::FileExists(msbuild)) { + return msbuild; + } + msbuild = vs + "/MSBuild/15.0/Bin/MSBuild.exe"; + if (cmSystemTools::FileExists(msbuild)) { + return msbuild; + } + } + + msbuild = "MSBuild.exe"; + return msbuild; +} + +std::string cmGlobalVisualStudioVersionedGenerator::FindDevEnvCommand() +{ + std::string devenv; + + // Ask Visual Studio Installer tool. + std::string vs; + if (vsSetupAPIHelper.GetVSInstanceInfo(vs)) { + devenv = vs + "/Common7/IDE/devenv.com"; + if (cmSystemTools::FileExists(devenv)) { + return devenv; + } + } + + devenv = "devenv.com"; + return devenv; +} diff --git a/Source/cmGlobalVisualStudio15Generator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index 8ab63f1..466816b 100644 --- a/Source/cmGlobalVisualStudio15Generator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -1,7 +1,7 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmGlobalVisualStudio15Generator_h -#define cmGlobalVisualStudio15Generator_h +#ifndef cmGlobalVisualStudioVersionedGenerator_h +#define cmGlobalVisualStudioVersionedGenerator_h #include "cmConfigure.h" // IWYU pragma: keep @@ -14,20 +14,16 @@ class cmGlobalGeneratorFactory; class cmake; -/** \class cmGlobalVisualStudio15Generator */ -class cmGlobalVisualStudio15Generator : public cmGlobalVisualStudio14Generator +/** \class cmGlobalVisualStudioVersionedGenerator */ +class cmGlobalVisualStudioVersionedGenerator + : public cmGlobalVisualStudio14Generator { public: - cmGlobalVisualStudio15Generator(cmake* cm, const std::string& name, - const std::string& platformName); - static cmGlobalGeneratorFactory* NewFactory(); + static cmGlobalGeneratorFactory* NewFactory15(); + static cmGlobalGeneratorFactory* NewFactory16(); bool MatchesGeneratorName(const std::string& name) const override; - void WriteSLNHeader(std::ostream& fout) override; - - const char* GetToolsVersion() override { return "15.0"; } - bool SetGeneratorInstance(std::string const& i, cmMakefile* mf) override; bool GetVSInstance(std::string& dir) const; @@ -36,11 +32,13 @@ public: std::string GetAuxiliaryToolset() const override; protected: + cmGlobalVisualStudioVersionedGenerator( + VSVersion version, cmake* cm, const std::string& name, + std::string const& platformInGeneratorName); + bool InitializeWindows(cmMakefile* mf) override; bool SelectWindowsStoreToolset(std::string& toolset) const override; - const char* GetIDEVersion() override { return "15.0"; } - // Used to verify that the Desktop toolset for the current generator is // installed on the machine. bool IsWindowsDesktopToolsetInstalled() const override; @@ -58,7 +56,10 @@ protected: std::string FindDevEnvCommand() override; private: - class Factory; + class Factory15; + friend class Factory15; + class Factory16; + friend class Factory16; mutable cmVSSetupAPIHelper vsSetupAPIHelper; }; #endif diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index d6ab769..6618351 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -21,6 +21,7 @@ #include "cmLocalGenerator.h" #include "cmLocalXCodeGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmSourceFile.h" #include "cmSourceGroup.h" @@ -201,7 +202,7 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( unsigned int version_number = 10 * v[0] + v[1]; if (version_number < 30) { - cm->IssueMessage(cmake::FATAL_ERROR, + cm->IssueMessage(MessageType::FATAL_ERROR, "Xcode " + version_string + " not supported."); return nullptr; } @@ -263,7 +264,7 @@ bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts, " " << ts << "\n" "that was specified."; /* clang-format on */ - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } this->GeneratorToolset = ts; @@ -774,7 +775,7 @@ public: "specified for source:\n" " " << this->SourceFile->GetFullPath() << "\n"; /* clang-format on */ - this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str()); } return processed; diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 754fa7d..199c8e2 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -198,12 +198,12 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, std::cout << "Reading GraphViz options file: " << inFileName << std::endl; #define __set_if_set(var, cmakeDefinition) \ - { \ + do { \ const char* value = mf.GetDefinition(cmakeDefinition); \ if (value) { \ (var) = value; \ } \ - } + } while (false) __set_if_set(this->GraphType, "GRAPHVIZ_GRAPH_TYPE"); __set_if_set(this->GraphName, "GRAPHVIZ_GRAPH_NAME"); @@ -211,12 +211,12 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, __set_if_set(this->GraphNodePrefix, "GRAPHVIZ_NODE_PREFIX"); #define __set_bool_if_set(var, cmakeDefinition) \ - { \ + do { \ const char* value = mf.GetDefinition(cmakeDefinition); \ if (value) { \ (var) = mf.IsOn(cmakeDefinition); \ } \ - } + } while (false) __set_bool_if_set(this->GenerateForExecutables, "GRAPHVIZ_EXECUTABLES"); __set_bool_if_set(this->GenerateForStaticLibs, "GRAPHVIZ_STATIC_LIBS"); diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 5d952da..d1f8f58 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -6,6 +6,7 @@ #include "cmExecutionStatus.h" #include "cmExpandedCommandArgument.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmSystemTools.h" #include "cmake.h" @@ -60,7 +61,7 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, if (this->ElseSeen) { cmListFileBacktrace bt = mf.GetBacktrace(func); mf.GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "A duplicate ELSE command was found inside an IF block.", bt); cmSystemTools::SetFatalErrorOccured(); return true; @@ -79,7 +80,7 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, if (this->ElseSeen) { cmListFileBacktrace bt = mf.GetBacktrace(func); mf.GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "An ELSEIF command was found after an ELSE command.", bt); cmSystemTools::SetFatalErrorOccured(); return true; @@ -98,7 +99,7 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, std::vector<cmExpandedCommandArgument> expandedArguments; mf.ExpandArguments(func.Arguments, expandedArguments); - cmake::MessageType messType; + MessageType messType; cmListFileContext conditionContext = cmListFileContext::FromCommandContext( @@ -115,7 +116,7 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, err += errorString; cmListFileBacktrace bt = mf.GetBacktrace(func); mf.GetCMakeInstance()->IssueMessage(messType, err, bt); - if (messType == cmake::FATAL_ERROR) { + if (messType == MessageType::FATAL_ERROR) { cmSystemTools::SetFatalErrorOccured(); return true; } @@ -181,7 +182,7 @@ bool cmIfCommand::InvokeInitialPass( std::vector<cmExpandedCommandArgument> expandedArguments; this->Makefile->ExpandArguments(args, expandedArguments); - cmake::MessageType status; + MessageType status; cmConditionEvaluator conditionEvaluator( *(this->Makefile), this->Makefile->GetExecutionContext(), @@ -193,8 +194,8 @@ bool cmIfCommand::InvokeInitialPass( if (!errorString.empty()) { std::string err = "if " + cmIfCommandError(expandedArguments); err += errorString; - if (status == cmake::FATAL_ERROR) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, err); + if (status == MessageType::FATAL_ERROR) { + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err); cmSystemTools::SetFatalErrorOccured(); return true; } diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx index f862578..594c310 100644 --- a/Source/cmIncludeCommand.cxx +++ b/Source/cmIncludeCommand.cxx @@ -6,9 +6,9 @@ #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -58,7 +58,7 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args, } if (fname.empty()) { - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, "include() given empty file name (ignored)."); return true; } @@ -80,7 +80,7 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args, if (gg->IsExportedTargetsFile(fname_abs)) { const char* modal = nullptr; std::ostringstream e; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0024)) { case cmPolicies::WARN: @@ -92,7 +92,7 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args, case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: modal = "may"; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (modal) { e << "The file\n " << fname_abs @@ -103,7 +103,7 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args, "include() command. Use ALIAS targets instead to refer to targets " "by alternative names.\n"; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index caec67d..549a263 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -4,6 +4,7 @@ #include <algorithm> #include <set> +#include <utility> #include "cmGeneratorExpression.h" #include "cmMakefile.h" diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx index c9217d3..b224d09 100644 --- a/Source/cmIncludeExternalMSProjectCommand.cxx +++ b/Source/cmIncludeExternalMSProjectCommand.cxx @@ -8,6 +8,7 @@ # include "cmStateTypes.h" # include "cmSystemTools.h" # include "cmTarget.h" +# include "cmake.h" #endif class cmExecutionStatus; diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 7c8458a..c6f4064 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -23,12 +23,12 @@ #include "cmInstallTargetGenerator.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" #include "cmTargetExport.h" -#include "cmake.h" class cmExecutionStatus; @@ -864,7 +864,7 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) if (gg->IsExportedTargetsFile(file)) { const char* modal = nullptr; std::ostringstream e; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (status) { case cmPolicies::WARN: @@ -876,7 +876,7 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: modal = "may"; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (modal) { e << "The file\n " << file @@ -887,7 +887,7 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) "install() command. Use the install(EXPORT) mechanism " "instead. See the cmake-packages(7) manual for more.\n"; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } @@ -1495,7 +1495,7 @@ bool cmInstallCommand::CheckCMP0006(bool& failure) switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0006)) { case cmPolicies::WARN: this->Makefile->IssueMessage( - cmake::AUTHOR_WARNING, + MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(cmPolicies::CMP0006)); CM_FALLTHROUGH; case cmPolicies::OLD: @@ -1508,7 +1508,7 @@ bool cmInstallCommand::CheckCMP0006(bool& failure) case cmPolicies::REQUIRED_ALWAYS: failure = true; this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0006)); break; } diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx index 06eb8a6..538aa9f 100644 --- a/Source/cmInstallCommandArguments.cxx +++ b/Source/cmInstallCommandArguments.cxx @@ -17,9 +17,7 @@ const std::string cmInstallCommandArguments::EmptyString; cmInstallCommandArguments::cmInstallCommandArguments( const std::string& defaultComponent) - : Parser() - , ArgumentGroup() - , Destination(&Parser, "DESTINATION", &ArgumentGroup) + : Destination(&Parser, "DESTINATION", &ArgumentGroup) , Component(&Parser, "COMPONENT", &ArgumentGroup) , NamelinkComponent(&Parser, "NAMELINK_COMPONENT", &ArgumentGroup) , ExcludeFromAll(&Parser, "EXCLUDE_FROM_ALL", &ArgumentGroup) diff --git a/Source/cmInstallExportAndroidMKGenerator.cxx b/Source/cmInstallExportAndroidMKGenerator.cxx index dd85b88..85b7021 100644 --- a/Source/cmInstallExportAndroidMKGenerator.cxx +++ b/Source/cmInstallExportAndroidMKGenerator.cxx @@ -13,7 +13,7 @@ #include "cmInstallTargetGenerator.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" -#include "cmake.h" +#include "cmMessageType.h" cmInstallExportAndroidMKGenerator::cmInstallExportAndroidMKGenerator( cmExportSet* exportSet, const char* destination, diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index d441e41..4cc081c 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -3,6 +3,7 @@ #include "cmInstallExportGenerator.h" #include <algorithm> +#include <map> #include <sstream> #include <utility> diff --git a/Source/cmInstallScriptGenerator.cxx b/Source/cmInstallScriptGenerator.cxx index 7d77b7c..12e87c7 100644 --- a/Source/cmInstallScriptGenerator.cxx +++ b/Source/cmInstallScriptGenerator.cxx @@ -2,11 +2,15 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallScriptGenerator.h" -#include "cmScriptGenerator.h" - #include <ostream> #include <vector> +#include "cmGeneratorExpression.h" +#include "cmLocalGenerator.h" +#include "cmMessageType.h" +#include "cmPolicies.h" +#include "cmScriptGenerator.h" + cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script, bool code, const char* component, @@ -15,25 +19,71 @@ cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script, MessageDefault, exclude_from_all) , Script(script) , Code(code) + , AllowGenex(false) { + // We need per-config actions if the script has generator expressions. + if (cmGeneratorExpression::Find(Script) != std::string::npos) { + this->ActionsPerConfig = true; + } } cmInstallScriptGenerator::~cmInstallScriptGenerator() { } -void cmInstallScriptGenerator::GenerateScript(std::ostream& os) +void cmInstallScriptGenerator::Compute(cmLocalGenerator* lg) { - Indent indent; - std::string component_test = - this->CreateComponentTest(this->Component.c_str(), this->ExcludeFromAll); - os << indent << "if(" << component_test << ")\n"; + this->LocalGenerator = lg; + if (this->ActionsPerConfig) { + switch (this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0087)) { + case cmPolicies::WARN: + this->LocalGenerator->IssueMessage( + MessageType::AUTHOR_WARNING, + cmPolicies::GetPolicyWarning(cmPolicies::CMP0087)); + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + this->AllowGenex = true; + break; + } + } +} + +void cmInstallScriptGenerator::AddScriptInstallRule(std::ostream& os, + Indent indent, + std::string const& script) +{ if (this->Code) { - os << indent << this->Script << "\n"; + os << indent << script << "\n"; } else { - os << indent << "include(\"" << this->Script << "\")\n"; + os << indent << "include(\"" << script << "\")\n"; } +} - os << indent << "endif()\n\n"; +void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os, + Indent indent) +{ + if (this->AllowGenex && this->ActionsPerConfig) { + this->cmInstallGenerator::GenerateScriptActions(os, indent); + } else { + this->AddScriptInstallRule(os, indent, this->Script); + } +} + +void cmInstallScriptGenerator::GenerateScriptForConfig( + std::ostream& os, const std::string& config, Indent indent) +{ + if (this->AllowGenex) { + cmGeneratorExpression ge; + std::unique_ptr<cmCompiledGeneratorExpression> cge = + ge.Parse(this->Script); + this->AddScriptInstallRule(os, indent, + cge->Evaluate(this->LocalGenerator, config)); + } else { + this->AddScriptInstallRule(os, indent, this->Script); + } } diff --git a/Source/cmInstallScriptGenerator.h b/Source/cmInstallScriptGenerator.h index fe0f7c6..05199d7 100644 --- a/Source/cmInstallScriptGenerator.h +++ b/Source/cmInstallScriptGenerator.h @@ -6,10 +6,13 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmInstallGenerator.h" +#include "cmScriptGenerator.h" #include <iosfwd> #include <string> +class cmLocalGenerator; + /** \class cmInstallScriptGenerator * \brief Generate target installation rules. */ @@ -20,10 +23,19 @@ public: const char* component, bool exclude_from_all); ~cmInstallScriptGenerator() override; + void Compute(cmLocalGenerator* lg) override; + protected: - void GenerateScript(std::ostream& os) override; + void GenerateScriptActions(std::ostream& os, Indent indent) override; + void GenerateScriptForConfig(std::ostream& os, const std::string& config, + Indent indent) override; + void AddScriptInstallRule(std::ostream& os, Indent indent, + std::string const& script); + std::string Script; bool Code; + cmLocalGenerator* LocalGenerator; + bool AllowGenex; }; #endif diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index ea3d522..86c6a58 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -15,6 +15,7 @@ #include "cmInstallType.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" @@ -91,7 +92,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( case cmStateEnums::GLOBAL_TARGET: case cmStateEnums::UNKNOWN_LIBRARY: this->Target->GetLocalGenerator()->IssueMessage( - cmake::INTERNAL_ERROR, + MessageType::INTERNAL_ERROR, "cmInstallTargetGenerator created with non-installable target."); return; } @@ -695,7 +696,7 @@ void cmInstallTargetGenerator::AddChrpathPatchRule( << "Therefore, runtime paths will not be changed when installing. " << "CMAKE_BUILD_WITH_INSTALL_RPATH may be used to work around" " this limitation."; - mf->IssueMessage(cmake::WARNING, msg.str()); + mf->IssueMessage(MessageType::WARNING, msg.str()); } else { // Note: These paths are kept unique to avoid // install_name_tool corruption. diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx index 0e06029..9f61e5b 100644 --- a/Source/cmInstalledFile.cxx +++ b/Source/cmInstalledFile.cxx @@ -10,7 +10,6 @@ #include <utility> cmInstalledFile::cmInstalledFile() - : NameExpression(nullptr) { } diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h index 47a4959..070b954 100644 --- a/Source/cmInstalledFile.h +++ b/Source/cmInstalledFile.h @@ -68,7 +68,7 @@ public: private: std::string Name; - cmCompiledGeneratorExpression* NameExpression; + cmCompiledGeneratorExpression* NameExpression = nullptr; PropertyMapType Properties; }; diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index 0da6f4f..bb56714 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -14,6 +14,7 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmProperty.h" +#include "cmPropertyMap.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStateDirectory.h" diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx index 10425fd..7850977 100644 --- a/Source/cmLinkDirectoriesCommand.cxx +++ b/Source/cmLinkDirectoriesCommand.cxx @@ -7,9 +7,9 @@ #include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -59,7 +59,7 @@ void cmLinkDirectoriesCommand::AddLinkDir( switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015); - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); break; case cmPolicies::OLD: // OLD behavior does not convert @@ -67,7 +67,7 @@ void cmLinkDirectoriesCommand::AddLinkDir( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015); - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); CM_FALLTHROUGH; case cmPolicies::NEW: // NEW behavior converts diff --git a/Source/cmLinkItem.cxx b/Source/cmLinkItem.cxx index 121731d..12a07f6 100644 --- a/Source/cmLinkItem.cxx +++ b/Source/cmLinkItem.cxx @@ -7,22 +7,18 @@ #include <utility> // IWYU pragma: keep cmLinkItem::cmLinkItem() - : String() - , Target(nullptr) { } cmLinkItem::cmLinkItem(std::string const& n, cmListFileBacktrace const& bt) : String(n) - , Target(nullptr) , Backtrace(bt) { } cmLinkItem::cmLinkItem(cmGeneratorTarget const* t, cmListFileBacktrace const& bt) - : String() - , Target(t) + : Target(t) , Backtrace(bt) { } @@ -61,7 +57,6 @@ std::ostream& operator<<(std::ostream& os, cmLinkItem const& item) cmLinkImplItem::cmLinkImplItem() : cmLinkItem() - , FromGenex(false) { } diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index e1ddd22..b841509 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -27,7 +27,7 @@ public: cmLinkItem(std::string const& s, cmListFileBacktrace const& bt); cmLinkItem(cmGeneratorTarget const* t, cmListFileBacktrace const& bt); std::string const& AsStr() const; - cmGeneratorTarget const* Target; + cmGeneratorTarget const* Target = nullptr; cmListFileBacktrace Backtrace; friend bool operator<(cmLinkItem const& l, cmLinkItem const& r); friend bool operator==(cmLinkItem const& l, cmLinkItem const& r); @@ -39,7 +39,7 @@ class cmLinkImplItem : public cmLinkItem public: cmLinkImplItem(); cmLinkImplItem(cmLinkItem item, bool fromGenex); - bool FromGenex; + bool FromGenex = false; }; /** The link implementation specifies the direct library @@ -70,36 +70,25 @@ struct cmLinkInterface : public cmLinkInterfaceLibraries // Number of repetitions of a strongly connected component of two // or more static libraries. - unsigned int Multiplicity; + unsigned int Multiplicity = 0; // Libraries listed for other configurations. // Needed only for OLD behavior of CMP0003. std::vector<cmLinkItem> WrongConfigLibraries; - bool ImplementationIsInterface; + bool ImplementationIsInterface = false; - cmLinkInterface() - : Multiplicity(0) - , ImplementationIsInterface(false) - { - } + cmLinkInterface() {} }; struct cmOptionalLinkInterface : public cmLinkInterface { - cmOptionalLinkInterface() - : LibrariesDone(false) - , AllDone(false) - , Exists(false) - , HadHeadSensitiveCondition(false) - , ExplicitLibraries(nullptr) - { - } - bool LibrariesDone; - bool AllDone; - bool Exists; - bool HadHeadSensitiveCondition; - const char* ExplicitLibraries; + cmOptionalLinkInterface() {} + bool LibrariesDone = false; + bool AllDone = false; + bool Exists = false; + bool HadHeadSensitiveCondition = false; + const char* ExplicitLibraries = nullptr; }; struct cmHeadToLinkInterfaceMap @@ -116,15 +105,10 @@ struct cmLinkImplementation : public cmLinkImplementationLibraries // Cache link implementation computation from each configuration. struct cmOptionalLinkImplementation : public cmLinkImplementation { - cmOptionalLinkImplementation() - : LibrariesDone(false) - , LanguagesDone(false) - , HadHeadSensitiveCondition(false) - { - } - bool LibrariesDone; - bool LanguagesDone; - bool HadHeadSensitiveCondition; + cmOptionalLinkImplementation() {} + bool LibrariesDone = false; + bool LanguagesDone = false; + bool HadHeadSensitiveCondition = false; }; /** Compute the link type to use for the given configuration. */ diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h index 975f052..099fb6d 100644 --- a/Source/cmLinkedTree.h +++ b/Source/cmLinkedTree.h @@ -6,7 +6,6 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <assert.h> -#include <iterator> #include <vector> /** @@ -33,7 +32,7 @@ class cmLinkedTree typedef T& ReferenceType; public: - class iterator : public std::iterator<std::forward_iterator_tag, T> + class iterator { friend class cmLinkedTree; cmLinkedTree* Tree; diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 9b63d24..b826795 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -12,14 +12,15 @@ #include <stdexcept> #include <stdio.h> #include <stdlib.h> // required for atoi +#include <utility> #include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmStringReplaceHelper.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -122,7 +123,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list, warn += " List has value = ["; warn += listString; warn += "]."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, warn); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, warn); return true; } case cmPolicies::OLD: @@ -137,7 +138,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0007)); return false; } diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 4689f42..9aa1f32 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -3,11 +3,11 @@ #include "cmListFileCache.h" #include "cmListFileLexer.h" +#include "cmMessageType.h" #include "cmMessenger.h" #include "cmOutputConverter.h" #include "cmState.h" #include "cmSystemTools.h" -#include "cmake.h" #include <assert.h> #include <memory> @@ -66,7 +66,8 @@ cmListFileParser::~cmListFileParser() void cmListFileParser::IssueFileOpenError(const std::string& text) const { - this->Messenger->IssueMessage(cmake::FATAL_ERROR, text, this->Backtrace); + this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text, + this->Backtrace); } void cmListFileParser::IssueError(const std::string& text) const @@ -76,7 +77,7 @@ void cmListFileParser::IssueError(const std::string& text) const lfc.Line = cmListFileLexer_GetCurrentLine(this->Lexer); cmListFileBacktrace lfbt = this->Backtrace; lfbt = lfbt.Push(lfc); - this->Messenger->IssueMessage(cmake::FATAL_ERROR, text, lfbt); + this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text, lfbt); cmSystemTools::SetFatalErrorOccured(); } @@ -254,7 +255,7 @@ bool cmListFileParser::ParseFunction(const char* name, long line) lfbt = lfbt.Push(lfc); error << "Parse error. Function missing ending \")\". " << "End of file reached."; - this->Messenger->IssueMessage(cmake::FATAL_ERROR, error.str(), lfbt); + this->Messenger->IssueMessage(MessageType::FATAL_ERROR, error.str(), lfbt); return false; } @@ -279,10 +280,10 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, << "Argument not separated from preceding token by whitespace."; /* clang-format on */ if (isError) { - this->Messenger->IssueMessage(cmake::FATAL_ERROR, m.str(), lfbt); + this->Messenger->IssueMessage(MessageType::FATAL_ERROR, m.str(), lfbt); return false; } - this->Messenger->IssueMessage(cmake::AUTHOR_WARNING, m.str(), lfbt); + this->Messenger->IssueMessage(MessageType::AUTHOR_WARNING, m.str(), lfbt); return true; } diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 9e4a833..4a247ba 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -33,11 +33,8 @@ struct cmCommandContext cmCommandName(std::string const& name) { *this = name; } cmCommandName& operator=(std::string const& name); } Name; - long Line; - cmCommandContext() - : Line(0) - { - } + long Line = 0; + cmCommandContext() {} cmCommandContext(const char* name, int line) : Name(name) , Line(line) @@ -53,12 +50,7 @@ struct cmListFileArgument Quoted, Bracket }; - cmListFileArgument() - : Value() - , Delim(Unquoted) - , Line(0) - { - } + cmListFileArgument() {} cmListFileArgument(const std::string& v, Delimiter d, long line) : Value(v) , Delim(d) @@ -71,8 +63,8 @@ struct cmListFileArgument } bool operator!=(const cmListFileArgument& r) const { return !(*this == r); } std::string Value; - Delimiter Delim; - long Line; + Delimiter Delim = Unquoted; + long Line = 0; }; class cmListFileContext @@ -80,13 +72,8 @@ class cmListFileContext public: std::string Name; std::string FilePath; - long Line; - cmListFileContext() - : Name() - , FilePath() - , Line(0) - { - } + long Line = 0; + cmListFileContext() {} static cmListFileContext FromCommandContext(cmCommandContext const& lfcc, std::string const& fileName) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index da48950..797add9 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -165,7 +165,7 @@ cmLocalGenerator::~cmLocalGenerator() cmDeleteAll(this->OwnedImportedGeneratorTargets); } -void cmLocalGenerator::IssueMessage(cmake::MessageType t, +void cmLocalGenerator::IssueMessage(MessageType t, std::string const& text) const { this->GetCMakeInstance()->IssueMessage(t, text, this->DirectoryBacktrace); @@ -190,14 +190,14 @@ void cmLocalGenerator::ComputeObjectMaxPath() w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax << ", which is less than the minimum of 128. " << "The value will be ignored."; - this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } } else { std::ostringstream w; w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen << "\", which fails to parse as a positive integer. " << "The value will be ignored."; - this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } } this->ObjectMaxPathViolations.clear(); @@ -565,7 +565,7 @@ void cmLocalGenerator::GenerateInstallRules() "CMAKE_POLICY_WARNING_CMP0082")) { std::ostringstream e; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0082) << "\n"; - this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } CM_FALLTHROUGH; case cmPolicies::OLD: { @@ -874,7 +874,7 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, "on " "and be depended on by the link implementation." << std::endl; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } } @@ -1387,7 +1387,7 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065( "additional flags may be added to export symbols on all " "executables regardless of their ENABLE_EXPORTS property."; /* clang-format on */ - this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } CM_FALLTHROUGH; case cmPolicies::OLD: @@ -1397,7 +1397,7 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065)); CM_FALLTHROUGH; case cmPolicies::NEW: @@ -1670,7 +1670,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag( << (ext ? "(with compiler extensions)" : "") << ", but CMake " "does not know the compile flags to use to enable it."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); } else { std::vector<std::string> optVec; cmSystemTools::ExpandListArgument(opt, optVec); @@ -1709,7 +1709,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag( std::string e = lang + "_STANDARD is set to invalid value '" + standard + "'"; this->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, e, target->GetBacktrace()); + MessageType::FATAL_ERROR, e, target->GetBacktrace()); return; } @@ -1719,7 +1719,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag( std::string e = "CMAKE_" + lang + "_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) + "'"; - this->IssueMessage(cmake::INTERNAL_ERROR, e); + this->IssueMessage(MessageType::INTERNAL_ERROR, e); return; } @@ -1857,7 +1857,7 @@ void cmLocalGenerator::AddVisibilityPresetFlags( "For compatibility CMake is not honoring them for this target."; /* clang-format on */ target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( - cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace()); + MessageType::AUTHOR_WARNING, w.str(), target->GetBacktrace()); } } @@ -1916,7 +1916,7 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared, << flagsVar << " was removed.\n" << cmPolicies::GetPolicyWarning(cmPolicies::CMP0018); - this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); CM_FALLTHROUGH; } case cmPolicies::OLD: @@ -2044,8 +2044,14 @@ void cmLocalGenerator::AppendPositionIndependentLinkerFlags( return; } - std::string name = "CMAKE_" + lang + "_LINK_OPTIONS_"; - name += cmSystemTools::IsOn(PICValue) ? "PIE" : "NO_PIE"; + const std::string mode = cmSystemTools::IsOn(PICValue) ? "PIE" : "NO_PIE"; + + std::string supported = "CMAKE_" + lang + "_LINK_" + mode + "_SUPPORTED"; + if (cmSystemTools::IsOff(this->Makefile->GetDefinition(supported))) { + return; + } + + std::string name = "CMAKE_" + lang + "_LINK_OPTIONS_" + mode; auto pieFlags = this->Makefile->GetSafeDefinition(name); if (pieFlags.empty()) { @@ -2124,7 +2130,7 @@ void cmLocalGenerator::AppendIncludeDirectories( << sourceFile.GetLocation().GetName() << "\":\n \"" << include << "\"\n"; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -2494,7 +2500,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName( << "cannot be safely placed under this directory. " << "The build may not work correctly."; /* clang-format on */ - this->IssueMessage(cmake::WARNING, m.str()); + this->IssueMessage(MessageType::WARNING, m.str()); } } #else diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 2fa0070..dc54314 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -14,10 +14,10 @@ #include <vector> #include "cmListFileCache.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmStateSnapshot.h" -#include "cmake.h" class cmComputeLinkInformation; class cmCustomCommandGenerator; @@ -28,6 +28,7 @@ class cmMakefile; class cmRulePlaceholderExpander; class cmSourceFile; class cmState; +class cmake; /** \class cmLocalGenerator * \brief Create required build files for a directory. @@ -359,7 +360,7 @@ public: bool IsMinGWMake() const; bool IsNMake() const; - void IssueMessage(cmake::MessageType t, std::string const& text) const; + void IssueMessage(MessageType t, std::string const& text) const; void CreateEvaluationFileOutputs(const std::string& config); void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles); diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 869ef1e..ee6b37b 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -264,13 +264,9 @@ private: struct LocalObjectEntry { - cmGeneratorTarget* Target; + cmGeneratorTarget* Target = nullptr; std::string Language; - LocalObjectEntry() - : Target(nullptr) - , Language() - { - } + LocalObjectEntry() {} LocalObjectEntry(cmGeneratorTarget* t, const std::string& lang) : Target(t) , Language(lang) @@ -279,15 +275,10 @@ private: }; struct LocalObjectInfo : public std::vector<LocalObjectEntry> { - bool HasSourceExtension; - bool HasPreprocessRule; - bool HasAssembleRule; - LocalObjectInfo() - : HasSourceExtension(false) - , HasPreprocessRule(false) - , HasAssembleRule(false) - { - } + bool HasSourceExtension = false; + bool HasPreprocessRule = false; + bool HasAssembleRule = false; + LocalObjectInfo() {} }; void GetLocalObjectFiles( std::map<std::string, LocalObjectInfo>& localObjectFiles); diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index 0c2c64e..d45c335 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -7,6 +7,7 @@ #include "cmMakefile.h" #include "cmVisualStudio10TargetGenerator.h" #include "cmXMLParser.h" +#include "cmake.h" #include "cm_expat.h" diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index fee9dd6..677d033 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -6,6 +6,7 @@ #include "cmGeneratorTarget.h" #include "cmGlobalVisualStudio7Generator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSourceFile.h" #include "cmSystemTools.h" #include "cmXMLParser.h" diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx index 7294c1c..7368812 100644 --- a/Source/cmMachO.cxx +++ b/Source/cmMachO.cxx @@ -52,10 +52,7 @@ bool peek(cmsys::ifstream& fin, T& v) template <typename T> bool read(cmsys::ifstream& fin, T& v) { - if (!fin.read(reinterpret_cast<char*>(&v), sizeof(T))) { - return false; - } - return true; + return !!fin.read(reinterpret_cast<char*>(&v), sizeof(T)); } // read from the file and fill multiple data structures where @@ -67,10 +64,7 @@ bool read(cmsys::ifstream& fin, std::vector<T>& v) if (v.empty()) { return true; } - if (!fin.read(reinterpret_cast<char*>(&v[0]), sizeof(T) * v.size())) { - return false; - } - return true; + return !!fin.read(reinterpret_cast<char*>(&v[0]), sizeof(T) * v.size()); } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5cd6ba5..274c631 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -30,6 +30,7 @@ #include "cmInstallGenerator.h" // IWYU pragma: keep #include "cmInstallSubdirectoryGenerator.h" #include "cmListFileCache.h" +#include "cmMessageType.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmState.h" @@ -129,11 +130,11 @@ cmDirectoryId cmMakefile::GetDirectoryId() const return std::string(buf); } -void cmMakefile::IssueMessage(cmake::MessageType t, - std::string const& text) const +void cmMakefile::IssueMessage(MessageType t, std::string const& text) const { if (!this->ExecutionStatusStack.empty()) { - if ((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR)) { + if ((t == MessageType::FATAL_ERROR) || + (t == MessageType::INTERNAL_ERROR)) { this->ExecutionStatusStack.back()->SetNestedError(); } } @@ -143,7 +144,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t, bool cmMakefile::CheckCMP0037(std::string const& targetName, cmStateEnums::TargetType targetType) const { - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; std::ostringstream e; bool issueMessage = false; switch (this->GetPolicyStatus(cmPolicies::CMP0037)) { @@ -159,7 +160,7 @@ bool cmMakefile::CheckCMP0037(std::string const& targetName, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: issueMessage = true; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; break; } if (issueMessage) { @@ -169,7 +170,7 @@ bool cmMakefile::CheckCMP0037(std::string const& targetName, "in undefined behavior."; this->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } @@ -198,7 +199,7 @@ void cmMakefile::MaybeWarnCMP0074(std::string const& pkg) << " " << env << "\n"; } w << "For compatibility, CMake is ignoring the variable."; - this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } } @@ -381,7 +382,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, // The command invocation requested that we report an error. std::string const error = std::string(lff.Name.Original) + " " + pcmd->GetError(); - this->IssueMessage(cmake::FATAL_ERROR, error); + this->IssueMessage(MessageType::FATAL_ERROR, error); } result = false; if (this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE) { @@ -397,7 +398,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, std::string error = "Unknown CMake command \""; error += lff.Name.Original; error += "\"."; - this->IssueMessage(cmake::FATAL_ERROR, error); + this->IssueMessage(MessageType::FATAL_ERROR, error); result = false; cmSystemTools::SetFatalErrorOccured(); } @@ -509,7 +510,7 @@ void cmMakefile::IncludeScope::EnforceCMP0011() << "affects policy settings. " << "CMake is implying the NO_POLICY_SCOPE option for compatibility, " << "so the effects are applied to the including context."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } break; case cmPolicies::REQUIRED_IF_USED: @@ -521,7 +522,7 @@ void cmMakefile::IncludeScope::EnforceCMP0011() << this->Makefile->GetExecutionFilePath() << "\n" << "affects policy settings, so it requires this policy to be set."; /* clang-format on */ - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } break; case cmPolicies::OLD: case cmPolicies::NEW: @@ -665,7 +666,7 @@ void cmMakefile::EnforceDirectoryLevelRules() const case cmPolicies::WARN: // Warn because the user did not provide a minimum required // version. - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, + this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING, msg.str(), this->Backtrace); case cmPolicies::OLD: // OLD behavior is to use policy version 2.4 set in @@ -675,8 +676,8 @@ void cmMakefile::EnforceDirectoryLevelRules() const case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::NEW: // NEW behavior is to issue an error. - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str(), - this->Backtrace); + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + msg.str(), this->Backtrace); cmSystemTools::SetFatalErrorOccured(); return; } @@ -764,7 +765,7 @@ void cmMakefile::ConfigureFinalPass() if (oldValue && cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, oldValue, "2.4")) { this->GetCMakeInstance()->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less " "than 2.4. This version of CMake only supports backwards compatibility " "with CMake 2.4 or later. For compatibility with older versions please " @@ -785,7 +786,7 @@ void cmMakefile::AddCustomCommandToTarget( cmTargets::iterator ti = this->Targets.find(target); if (ti == this->Targets.end()) { - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; bool issueMessage = false; std::ostringstream e; switch (this->GetPolicyStatus(cmPolicies::CMP0040)) { @@ -798,7 +799,7 @@ void cmMakefile::AddCustomCommandToTarget( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: issueMessage = true; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (issueMessage) { @@ -826,7 +827,7 @@ void cmMakefile::AddCustomCommandToTarget( e << "Target \"" << target << "\" is an OBJECT library " "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (t.GetType() == cmStateEnums::INTERFACE_LIBRARY) { @@ -834,7 +835,7 @@ void cmMakefile::AddCustomCommandToTarget( e << "Target \"" << target << "\" is an INTERFACE library " "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -886,7 +887,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( if (!cl.empty() && !cl[0].empty() && cl[0][0] == '"') { std::ostringstream e; e << "COMMAND may not contain literal quotes:\n " << cl[0] << "\n"; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return nullptr; } } @@ -1278,7 +1279,7 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) // This definition has a non-trivial value. switch (this->GetPolicyStatus(cmPolicies::CMP0005)) { case cmPolicies::WARN: - this->IssueMessage(cmake::AUTHOR_WARNING, + this->IssueMessage(MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(cmPolicies::CMP0005)); CM_FALLTHROUGH; case cmPolicies::OLD: @@ -1288,7 +1289,7 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0005)); return false; case cmPolicies::NEW: @@ -1617,7 +1618,7 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf) << "\n" << cmPolicies::GetPolicyWarning(cmPolicies::CMP0014); /* clang-format on */ - this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); case cmPolicies::OLD: // OLD behavior does not warn. break; @@ -1627,7 +1628,7 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf) CM_FALLTHROUGH; case cmPolicies::NEW: // NEW behavior prints the error. - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); } return; } @@ -1837,6 +1838,23 @@ bool cmMakefile::VariableInitialized(const std::string& var) const return this->StateSnapshot.IsInitialized(var); } +void cmMakefile::MaybeWarnUninitialized(std::string const& variable, + const char* sourceFilename) const +{ + // check to see if we need to print a warning + // if strict mode is on and the variable has + // not been "cleared"/initialized with a set(foo ) call + if (this->GetCMakeInstance()->GetWarnUninitialized() && + !this->VariableInitialized(variable)) { + if (this->CheckSystemVars || + (sourceFilename && this->IsProjectFile(sourceFilename))) { + std::ostringstream msg; + msg << "uninitialized variable \'" << variable << "\'"; + this->IssueMessage(MessageType::AUTHOR_WARNING, msg.str()); + } + } +} + void cmMakefile::LogUnused(const char* reason, const std::string& name) const { if (this->WarnUnused) { @@ -1848,14 +1866,10 @@ void cmMakefile::LogUnused(const char* reason, const std::string& name) const path += "/CMakeLists.txt"; } - if (this->CheckSystemVars || - cmSystemTools::IsSubDirectory(path, this->GetHomeDirectory()) || - (cmSystemTools::IsSubDirectory(path, this->GetHomeOutputDirectory()) && - !cmSystemTools::IsSubDirectory(path, - cmake::GetCMakeFilesDirectory()))) { + if (this->CheckSystemVars || this->IsProjectFile(path.c_str())) { std::ostringstream msg; msg << "unused variable (" << reason << ") \'" << name << "\'"; - this->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, msg.str()); } } } @@ -2261,8 +2275,8 @@ void cmMakefile::ExpandVariablesCMP0019() << "The following variable evaluations were encountered:\n" << w.str(); /* clang-format on */ - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, m.str(), - this->Backtrace); + this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING, + m.str(), this->Backtrace); } } @@ -2481,7 +2495,7 @@ const std::string& cmMakefile::ExpandVariablesInString( const char* filename, long line, bool removeEmpty, bool replaceAt) const { bool compareResults = false; - cmake::MessageType mtype = cmake::LOG; + MessageType mtype = MessageType::LOG; std::string errorstr; std::string original; @@ -2489,7 +2503,7 @@ const std::string& cmMakefile::ExpandVariablesInString( if (atOnly && (!noEscapes || !removeEmpty)) { // This case should never be called. At-only is for // configure-file/string which always does no escapes. - this->IssueMessage(cmake::INTERNAL_ERROR, + this->IssueMessage(MessageType::INTERNAL_ERROR, "ExpandVariablesInString @ONLY called " "on something with escapes."); return source; @@ -2498,7 +2512,7 @@ const std::string& cmMakefile::ExpandVariablesInString( // Variables used in the WARN case. std::string newResult; std::string newErrorstr; - cmake::MessageType newError = cmake::LOG; + MessageType newError = MessageType::LOG; switch (this->GetPolicyStatus(cmPolicies::CMP0053)) { case cmPolicies::WARN: { @@ -2509,9 +2523,9 @@ const std::string& cmMakefile::ExpandVariablesInString( // Suppress variable watches to avoid calling hooks twice. Suppress new // dereferences since the OLD behavior is still what is actually used. this->SuppressSideEffects = true; - newError = ExpandVariablesInStringNew( - newErrorstr, newResult, escapeQuotes, noEscapes, atOnly, filename, - line, removeEmpty, replaceAt); + newError = ExpandVariablesInStringNew(newErrorstr, newResult, + escapeQuotes, noEscapes, atOnly, + filename, line, replaceAt); this->SuppressSideEffects = false; CM_FALLTHROUGH; } @@ -2524,15 +2538,15 @@ const std::string& cmMakefile::ExpandVariablesInString( case cmPolicies::REQUIRED_ALWAYS: // Messaging here would be *very* verbose. case cmPolicies::NEW: - mtype = ExpandVariablesInStringNew(errorstr, source, escapeQuotes, - noEscapes, atOnly, filename, line, - removeEmpty, replaceAt); + mtype = + ExpandVariablesInStringNew(errorstr, source, escapeQuotes, noEscapes, + atOnly, filename, line, replaceAt); break; } // If it's an error in either case, just report the error... - if (mtype != cmake::LOG) { - if (mtype == cmake::FATAL_ERROR) { + if (mtype != MessageType::LOG) { + if (mtype == MessageType::FATAL_ERROR) { cmSystemTools::SetFatalErrorOccured(); } this->IssueMessage(mtype, errorstr); @@ -2571,20 +2585,20 @@ const std::string& cmMakefile::ExpandVariablesInString( msg += "Using the old result for compatibility since the policy is not set."; - this->IssueMessage(cmake::AUTHOR_WARNING, msg); + this->IssueMessage(MessageType::AUTHOR_WARNING, msg); } return source; } -cmake::MessageType cmMakefile::ExpandVariablesInStringOld( +MessageType cmMakefile::ExpandVariablesInStringOld( std::string& errorstr, std::string& source, bool escapeQuotes, bool noEscapes, bool atOnly, const char* filename, long line, bool removeEmpty, bool replaceAt) const { // Fast path strings without any special characters. if (source.find_first_of("$@\\") == std::string::npos) { - return cmake::LOG; + return MessageType::LOG; } // Special-case the @ONLY mode. @@ -2623,7 +2637,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld( // Append the rest of the unchanged part of the string. source.append(in); - return cmake::LOG; + return MessageType::LOG; } // This method replaces ${VAR} and @VAR@ where VAR is looked up @@ -2640,7 +2654,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld( parser.SetRemoveEmpty(removeEmpty); int res = parser.ParseString(source.c_str(), 0); const char* emsg = parser.GetError(); - cmake::MessageType mtype = cmake::LOG; + MessageType mtype = MessageType::LOG; if (res && !emsg[0]) { source = parser.GetResult(); } else { @@ -2663,7 +2677,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld( // parser reported an error message without failing because the // helper implementation is unhappy, which has always reported an // error. - mtype = cmake::FATAL_ERROR; + mtype = MessageType::FATAL_ERROR; if (!res) { // This is a real argument parsing error. Use policy CMP0010 to // decide whether it is an error. @@ -2673,7 +2687,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld( CM_FALLTHROUGH; case cmPolicies::OLD: // OLD behavior is to just warn and continue. - mtype = cmake::AUTHOR_WARNING; + mtype = MessageType::AUTHOR_WARNING; break; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: @@ -2697,19 +2711,23 @@ typedef enum } t_domain; struct t_lookup { - t_lookup() - : domain(NORMAL) - , loc(0) - { - } - t_domain domain; - size_t loc; + t_lookup() {} + t_domain domain = NORMAL; + size_t loc = 0; }; -cmake::MessageType cmMakefile::ExpandVariablesInStringNew( +bool cmMakefile::IsProjectFile(const char* filename) const +{ + return cmSystemTools::IsSubDirectory(filename, this->GetHomeDirectory()) || + (cmSystemTools::IsSubDirectory(filename, this->GetHomeOutputDirectory()) && + !cmSystemTools::IsSubDirectory(filename, + cmake::GetCMakeFilesDirectory())); +} + +MessageType cmMakefile::ExpandVariablesInStringNew( std::string& errorstr, std::string& source, bool escapeQuotes, bool noEscapes, bool atOnly, const char* filename, long line, - bool removeEmpty, bool replaceAt) const + bool replaceAt) const { // This method replaces ${VAR} and @VAR@ where VAR is looked up // with GetDefinition(), if not found in the map, nothing is expanded. @@ -2723,7 +2741,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( std::vector<t_lookup> openstack; bool error = false; bool done = false; - cmake::MessageType mtype = cmake::LOG; + MessageType mtype = MessageType::LOG; cmState* state = this->GetCMakeInstance()->GetState(); @@ -2766,23 +2784,8 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( } else { varresult = value; } - } else if (!removeEmpty && !this->SuppressSideEffects) { - // check to see if we need to print a warning - // if strict mode is on and the variable has - // not been "cleared"/initialized with a set(foo ) call - if (this->GetCMakeInstance()->GetWarnUninitialized() && - !this->VariableInitialized(lookup)) { - if (this->CheckSystemVars || - (filename && - (cmSystemTools::IsSubDirectory(filename, - this->GetHomeDirectory()) || - cmSystemTools::IsSubDirectory( - filename, this->GetHomeOutputDirectory())))) { - std::ostringstream msg; - msg << "uninitialized variable \'" << lookup << "\'"; - this->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); - } - } + } else if (!this->SuppressSideEffects) { + this->MaybeWarnUninitialized(lookup, filename); } result.replace(var.loc, result.size() - var.loc, varresult); // Start looking from here on out. @@ -2817,7 +2820,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( std::string(next, this->cmNamedCurly.end()) + "{} is not supported. Only ${}, $ENV{}, " "and $CACHE{} are allowed."; - mtype = cmake::FATAL_ERROR; + mtype = MessageType::FATAL_ERROR; error = true; } } @@ -2894,7 +2897,12 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( if (filename && variable == lineVar) { varresult = std::to_string(line); } else { - varresult = this->GetSafeDefinition(variable); + const std::string* def = this->GetDef(variable); + if (def) { + varresult = *def; + } else if (!this->SuppressSideEffects) { + this->MaybeWarnUninitialized(variable, filename); + } } if (escapeQuotes) { @@ -2920,7 +2928,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( errorstr += "\') in a variable name: " "'" + result.substr(openstack.back().loc) + "'"; - mtype = cmake::FATAL_ERROR; + mtype = MessageType::FATAL_ERROR; error = true; } break; @@ -2951,7 +2959,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( emsg << "when parsing string\n" << " " << source << "\n"; emsg << errorstr; - mtype = cmake::FATAL_ERROR; + mtype = MessageType::FATAL_ERROR; errorstr = emsg.str(); } else { // Append the rest of the unchanged part of the string. @@ -3045,7 +3053,7 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError) << " " << lfc << "\n" << "is not closed."; /* clang-format on */ - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); reportError = false; } } @@ -3198,7 +3206,7 @@ std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( << " " << closingContext << "\n" << "with mis-matching arguments."; /* clang-format on */ - this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } cmFunctionBlocker* b = *pos; this->FunctionBlockers.erase(pos); @@ -3355,7 +3363,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, // use the cmake object instead of calling cmake cmWorkingDirectory workdir(bindir); if (workdir.Failed()) { - this->IssueMessage(cmake::FATAL_ERROR, + this->IssueMessage(MessageType::FATAL_ERROR, "Failed to set working directory to " + bindir + " : " + std::strerror(workdir.GetLastResult())); cmSystemTools::SetFatalErrorOccured(); @@ -3371,7 +3379,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, cmGlobalGenerator* gg = cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName()); if (!gg) { - this->IssueMessage(cmake::INTERNAL_ERROR, + this->IssueMessage(MessageType::INTERNAL_ERROR, "Global generator '" + this->GetGlobalGenerator()->GetName() + "' could not be created."); @@ -3437,7 +3445,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, cmStateEnums::INTERNAL); } if (cm.Configure() != 0) { - this->IssueMessage(cmake::FATAL_ERROR, + this->IssueMessage(MessageType::FATAL_ERROR, "Failed to configure test project build system."); cmSystemTools::SetFatalErrorOccured(); this->IsSourceFileTryCompile = false; @@ -3445,7 +3453,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, } if (cm.Generate() != 0) { - this->IssueMessage(cmake::FATAL_ERROR, + this->IssueMessage(MessageType::FATAL_ERROR, "Failed to generate test project build system."); cmSystemTools::SetFatalErrorOccured(); this->IsSourceFileTryCompile = false; @@ -3577,7 +3585,7 @@ std::string cmMakefile::GetModulesFile(const char* filename, << cmPolicies::GetPolicyWarning(cmPolicies::CMP0017); /* clang-format on */ - this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); CM_FALLTHROUGH; } case cmPolicies::OLD: @@ -3733,7 +3741,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, std::ostringstream e; e << "File starts with a Byte-Order-Mark that is not UTF-8:\n " << sinfile; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return 0; } // rewind to copy BOM to output file @@ -3930,7 +3938,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char* varDef) if (!this->StateSnapshot.RaiseScope(var, varDef)) { std::ostringstream m; m << "Cannot set \"" << var << "\": current scope has no parent."; - this->IssueMessage(cmake::AUTHOR_WARNING, m.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, m.str()); return; } @@ -4015,7 +4023,7 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg, // target names must be globally unique switch (this->GetPolicyStatus(cmPolicies::CMP0002)) { case cmPolicies::WARN: - this->IssueMessage(cmake::AUTHOR_WARNING, + this->IssueMessage(MessageType::AUTHOR_WARNING, cmPolicies::GetPolicyWarning(cmPolicies::CMP0002)); CM_FALLTHROUGH; case cmPolicies::OLD: @@ -4023,7 +4031,7 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: this->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0002)); return true; case cmPolicies::NEW: @@ -4102,7 +4110,7 @@ bool cmMakefile::EnforceUniqueDir(const std::string& srcPath, << "to work accidentally and is being allowed for " << "compatibility."; /* clang-format on */ - this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); CM_FALLTHROUGH; case cmPolicies::OLD: // OLD behavior does not warn. @@ -4121,7 +4129,7 @@ bool cmMakefile::EnforceUniqueDir(const std::string& srcPath, << " " << srcPath << "\n" << "Specify a unique binary directory name."; /* clang-format on */ - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); break; } @@ -4206,7 +4214,7 @@ bool cmMakefile::SetPolicy(const char* id, cmPolicies::PolicyStatus status) if (!cmPolicies::GetPolicyID(id, /* out */ pid)) { std::ostringstream e; e << "Policy \"" << id << "\" is not known to this version of CMake."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } return this->SetPolicy(pid, status); @@ -4219,14 +4227,18 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, if (status != cmPolicies::NEW && cmPolicies::GetPolicyStatus(id) == cmPolicies::REQUIRED_ALWAYS) { std::string msg = cmPolicies::GetRequiredAlwaysPolicyError(id); - this->IssueMessage(cmake::FATAL_ERROR, msg); + this->IssueMessage(MessageType::FATAL_ERROR, msg); return false; } // Deprecate old policies, especially those that require a lot // of code to maintain the old behavior. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0063) { - this->IssueMessage(cmake::DEPRECATION_WARNING, + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0065 && + !(this->GetCMakeInstance()->GetIsInTryCompile() && + ( + // Policies set by cmCoreTryCompile::TryCompileCode. + id == cmPolicies::CMP0065))) { + this->IssueMessage(MessageType::DEPRECATION_WARNING, cmPolicies::GetPolicyDeprecatedWarning(id)); } @@ -4253,7 +4265,7 @@ void cmMakefile::PushPolicy(bool weak, cmPolicies::PolicyMap const& pm) void cmMakefile::PopPolicy() { if (!this->StateSnapshot.PopPolicy()) { - this->IssueMessage(cmake::FATAL_ERROR, + this->IssueMessage(MessageType::FATAL_ERROR, "cmake_policy POP without matching PUSH"); } } @@ -4265,7 +4277,7 @@ void cmMakefile::PopSnapshot(bool reportError) // reject any still-open nested policy scopes with an error. while (!this->StateSnapshot.CanPopPolicyScope()) { if (reportError) { - this->IssueMessage(cmake::FATAL_ERROR, + this->IssueMessage(MessageType::FATAL_ERROR, "cmake_policy PUSH without matching POP"); reportError = false; } @@ -4358,7 +4370,7 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target, if (error) { *error = e.str(); } else { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->Backtrace); } return false; @@ -4405,7 +4417,7 @@ bool cmMakefile::CompileFeatureKnown(cmTarget const* target, if (error) { *error = e.str(); } else { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->Backtrace); } return false; @@ -4425,7 +4437,7 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang, if (error) { *error = e.str(); } else { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->Backtrace); } return nullptr; @@ -4448,7 +4460,7 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang, if (error) { *error = e.str(); } else { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->Backtrace); } return nullptr; @@ -4473,7 +4485,7 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target, std::ostringstream e; e << "CMAKE_C_STANDARD_DEFAULT is not set. COMPILE_FEATURES support " "not fully configured for this compiler."; - this->IssueMessage(cmake::INTERNAL_ERROR, e.str()); + this->IssueMessage(MessageType::INTERNAL_ERROR, e.str()); // Return true so the caller does not try to lookup the default standard. return true; } @@ -4483,7 +4495,7 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target, e << "The CMAKE_C_STANDARD_DEFAULT variable contains an " "invalid value: \"" << defaultCStandard << "\"."; - this->IssueMessage(cmake::INTERNAL_ERROR, e.str()); + this->IssueMessage(MessageType::INTERNAL_ERROR, e.str()); return false; } @@ -4503,7 +4515,7 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target, std::ostringstream e; e << "The C_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCStandard << "\"."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -4557,7 +4569,7 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, std::ostringstream e; e << "CMAKE_CXX_STANDARD_DEFAULT is not set. COMPILE_FEATURES support " "not fully configured for this compiler."; - this->IssueMessage(cmake::INTERNAL_ERROR, e.str()); + this->IssueMessage(MessageType::INTERNAL_ERROR, e.str()); // Return true so the caller does not try to lookup the default standard. return true; } @@ -4567,7 +4579,7 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, e << "The CMAKE_CXX_STANDARD_DEFAULT variable contains an " "invalid value: \"" << defaultCxxStandard << "\"."; - this->IssueMessage(cmake::INTERNAL_ERROR, e.str()); + this->IssueMessage(MessageType::INTERNAL_ERROR, e.str()); return false; } @@ -4591,7 +4603,7 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, std::ostringstream e; e << "The CXX_STANDARD property on target \"" << target->GetName() << "\" contained an invalid value: \"" << existingCxxStandard << "\"."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -4671,8 +4683,8 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, if (error) { *error = e.str(); } else { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - this->Backtrace); + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + e.str(), this->Backtrace); } return false; } @@ -4692,8 +4704,8 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, if (error) { *error = e.str(); } else { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - this->Backtrace); + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + e.str(), this->Backtrace); } return false; } @@ -4770,8 +4782,8 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target, if (error) { *error = e.str(); } else { - this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), - this->Backtrace); + this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, + e.str(), this->Backtrace); } return false; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index aa94054..ec36972 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -18,13 +18,13 @@ #include "cmAlgorithms.h" #include "cmListFileCache.h" +#include "cmMessageType.h" #include "cmNewLineStyle.h" #include "cmPolicies.h" #include "cmSourceFileLocationKind.h" #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmTarget.h" -#include "cmake.h" #if defined(CMAKE_BUILD_WITH_CMAKE) # include "cmSourceGroup.h" @@ -46,6 +46,7 @@ class cmState; class cmTest; class cmTestGenerator; class cmVariableWatch; +class cmake; /** A type-safe wrapper for a string representing a directory id. */ class cmDirectoryId @@ -793,7 +794,7 @@ public: cmMakefile* Makefile; }; - void IssueMessage(cmake::MessageType t, std::string const& text) const; + void IssueMessage(MessageType t, std::string const& text) const; /** Set whether or not to report a CMP0000 violation. */ void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; } @@ -866,6 +867,9 @@ public: std::deque<std::vector<std::string>> FindPackageRootPathStack; void MaybeWarnCMP0074(std::string const& pkg); + void MaybeWarnUninitialized(std::string const& variable, + const char* sourceFilename) const; + bool IsProjectFile(const char* filename) const; protected: // add link libraries and directories to the target @@ -979,15 +983,18 @@ private: friend class BuildsystemFileScope; // CMP0053 == old - cmake::MessageType ExpandVariablesInStringOld( - std::string& errorstr, std::string& source, bool escapeQuotes, - bool noEscapes, bool atOnly, const char* filename, long line, - bool removeEmpty, bool replaceAt) const; + MessageType ExpandVariablesInStringOld(std::string& errorstr, + std::string& source, + bool escapeQuotes, bool noEscapes, + bool atOnly, const char* filename, + long line, bool removeEmpty, + bool replaceAt) const; // CMP0053 == new - cmake::MessageType ExpandVariablesInStringNew( - std::string& errorstr, std::string& source, bool escapeQuotes, - bool noEscapes, bool atOnly, const char* filename, long line, - bool removeEmpty, bool replaceAt) const; + MessageType ExpandVariablesInStringNew(std::string& errorstr, + std::string& source, + bool escapeQuotes, bool noEscapes, + bool atOnly, const char* filename, + long line, bool replaceAt) const; /** * Old version of GetSourceFileWithOutput(const std::string&) kept for * backward-compatibility. It implements a linear search and support diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 846b12c..92eeb2e 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -6,6 +6,7 @@ #include <memory> // IWYU pragma: keep #include <sstream> #include <string> +#include <utility> #include <vector> #include "cmGeneratedFileStream.h" diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 2d2915c..0c2d7b3 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -6,6 +6,7 @@ #include <memory> // IWYU pragma: keep #include <sstream> #include <stddef.h> +#include <utility> #include <vector> #include "cmGeneratedFileStream.h" diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index cb41c28..d1dcd81 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -687,6 +687,17 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( std::string langIncludes = std::string("$(") + lang + "_INCLUDES)"; compileCommand.replace(compileCommand.find(langIncludes), langIncludes.size(), this->GetIncludes(lang)); + + const char* eliminate[] = { + this->Makefile->GetDefinition("CMAKE_START_TEMP_FILE"), + this->Makefile->GetDefinition("CMAKE_END_TEMP_FILE") + }; + for (const char* el : eliminate) { + if (el) { + cmSystemTools::ReplaceString(compileCommand, el, ""); + } + } + this->GlobalGenerator->AddCXXCompileCommand( source.GetFullPath(), workingDirectory, compileCommand); } diff --git a/Source/cmMathCommand.cxx b/Source/cmMathCommand.cxx index a50e5fc..48b9a27 100644 --- a/Source/cmMathCommand.cxx +++ b/Source/cmMathCommand.cxx @@ -4,8 +4,8 @@ #include "cmExprParserHelper.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cm_kwiml.h" -#include "cmake.h" #include <stdio.h> @@ -104,7 +104,7 @@ bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args) std::string const& w = helper.GetWarning(); if (!w.empty()) { - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w); } this->Makefile->AddDefinition(outputVariable, buffer); diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 5a341bd..4c26c66 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -4,9 +4,9 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmMessenger.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -20,26 +20,26 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, } std::vector<std::string>::const_iterator i = args.begin(); - cmake::MessageType type = cmake::MESSAGE; + MessageType type = MessageType::MESSAGE; bool status = false; bool fatal = false; if (*i == "SEND_ERROR") { - type = cmake::FATAL_ERROR; + type = MessageType::FATAL_ERROR; ++i; } else if (*i == "FATAL_ERROR") { fatal = true; - type = cmake::FATAL_ERROR; + type = MessageType::FATAL_ERROR; ++i; } else if (*i == "WARNING") { - type = cmake::WARNING; + type = MessageType::WARNING; ++i; } else if (*i == "AUTHOR_WARNING") { if (this->Makefile->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") && !this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS")) { fatal = true; - type = cmake::AUTHOR_ERROR; + type = MessageType::AUTHOR_ERROR; } else if (!this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) { - type = cmake::AUTHOR_WARNING; + type = MessageType::AUTHOR_WARNING; } else { return true; } @@ -50,10 +50,10 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, } else if (*i == "DEPRECATION") { if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED")) { fatal = true; - type = cmake::DEPRECATION_ERROR; + type = MessageType::DEPRECATION_ERROR; } else if ((!this->Makefile->IsSet("CMAKE_WARN_DEPRECATED") || this->Makefile->IsOn("CMAKE_WARN_DEPRECATED"))) { - type = cmake::DEPRECATION_WARNING; + type = MessageType::DEPRECATION_WARNING; } else { return true; } @@ -62,7 +62,7 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args, std::string message = cmJoin(cmMakeRange(i, args.end()), std::string()); - if (type != cmake::MESSAGE) { + if (type != MessageType::MESSAGE) { // we've overridden the message type, above, so display it directly cmMessenger* m = this->Makefile->GetMessenger(); m->DisplayMessage(type, message, this->Makefile->GetBacktrace()); diff --git a/Source/cmMessageType.h b/Source/cmMessageType.h new file mode 100644 index 0000000..b57b86b --- /dev/null +++ b/Source/cmMessageType.h @@ -0,0 +1,21 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmMessageType_h +#define cmMessageType_h + +#include "cmConfigure.h" // IWYU pragma: keep + +enum class MessageType +{ + AUTHOR_WARNING, + AUTHOR_ERROR, + FATAL_ERROR, + INTERNAL_ERROR, + MESSAGE, + WARNING, + LOG, + DEPRECATION_ERROR, + DEPRECATION_WARNING +}; + +#endif diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index a81428a..3d788f6 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -4,7 +4,6 @@ #include "cmAlgorithms.h" #include "cmDocumentationFormatter.h" -#include "cmState.h" #include "cmSystemTools.h" #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -13,47 +12,47 @@ #include <sstream> -cmake::MessageType cmMessenger::ConvertMessageType(cmake::MessageType t) const +MessageType cmMessenger::ConvertMessageType(MessageType t) const { bool warningsAsErrors; - if (t == cmake::AUTHOR_WARNING || t == cmake::AUTHOR_ERROR) { + if (t == MessageType::AUTHOR_WARNING || t == MessageType::AUTHOR_ERROR) { warningsAsErrors = this->GetDevWarningsAsErrors(); - if (warningsAsErrors && t == cmake::AUTHOR_WARNING) { - t = cmake::AUTHOR_ERROR; - } else if (!warningsAsErrors && t == cmake::AUTHOR_ERROR) { - t = cmake::AUTHOR_WARNING; + if (warningsAsErrors && t == MessageType::AUTHOR_WARNING) { + t = MessageType::AUTHOR_ERROR; + } else if (!warningsAsErrors && t == MessageType::AUTHOR_ERROR) { + t = MessageType::AUTHOR_WARNING; } - } else if (t == cmake::DEPRECATION_WARNING || - t == cmake::DEPRECATION_ERROR) { + } else if (t == MessageType::DEPRECATION_WARNING || + t == MessageType::DEPRECATION_ERROR) { warningsAsErrors = this->GetDeprecatedWarningsAsErrors(); - if (warningsAsErrors && t == cmake::DEPRECATION_WARNING) { - t = cmake::DEPRECATION_ERROR; - } else if (!warningsAsErrors && t == cmake::DEPRECATION_ERROR) { - t = cmake::DEPRECATION_WARNING; + if (warningsAsErrors && t == MessageType::DEPRECATION_WARNING) { + t = MessageType::DEPRECATION_ERROR; + } else if (!warningsAsErrors && t == MessageType::DEPRECATION_ERROR) { + t = MessageType::DEPRECATION_WARNING; } } return t; } -bool cmMessenger::IsMessageTypeVisible(cmake::MessageType t) const +bool cmMessenger::IsMessageTypeVisible(MessageType t) const { bool isVisible = true; - if (t == cmake::DEPRECATION_ERROR) { + if (t == MessageType::DEPRECATION_ERROR) { if (!this->GetDeprecatedWarningsAsErrors()) { isVisible = false; } - } else if (t == cmake::DEPRECATION_WARNING) { + } else if (t == MessageType::DEPRECATION_WARNING) { if (this->GetSuppressDeprecatedWarnings()) { isVisible = false; } - } else if (t == cmake::AUTHOR_ERROR) { + } else if (t == MessageType::AUTHOR_ERROR) { if (!this->GetDevWarningsAsErrors()) { isVisible = false; } - } else if (t == cmake::AUTHOR_WARNING) { + } else if (t == MessageType::AUTHOR_WARNING) { if (this->GetSuppressDevWarnings()) { isVisible = false; } @@ -62,22 +61,22 @@ bool cmMessenger::IsMessageTypeVisible(cmake::MessageType t) const return isVisible; } -static bool printMessagePreamble(cmake::MessageType t, std::ostream& msg) +static bool printMessagePreamble(MessageType t, std::ostream& msg) { // Construct the message header. - if (t == cmake::FATAL_ERROR) { + if (t == MessageType::FATAL_ERROR) { msg << "CMake Error"; - } else if (t == cmake::INTERNAL_ERROR) { + } else if (t == MessageType::INTERNAL_ERROR) { msg << "CMake Internal Error (please report a bug)"; - } else if (t == cmake::LOG) { + } else if (t == MessageType::LOG) { msg << "CMake Debug Log"; - } else if (t == cmake::DEPRECATION_ERROR) { + } else if (t == MessageType::DEPRECATION_ERROR) { msg << "CMake Deprecation Error"; - } else if (t == cmake::DEPRECATION_WARNING) { + } else if (t == MessageType::DEPRECATION_WARNING) { msg << "CMake Deprecation Warning"; - } else if (t == cmake::AUTHOR_WARNING) { + } else if (t == MessageType::AUTHOR_WARNING) { msg << "CMake Warning (dev)"; - } else if (t == cmake::AUTHOR_ERROR) { + } else if (t == MessageType::AUTHOR_ERROR) { msg << "CMake Error (dev)"; } else { msg << "CMake Warning"; @@ -93,13 +92,13 @@ void printMessageText(std::ostream& msg, std::string const& text) formatter.PrintFormatted(msg, text.c_str()); } -void displayMessage(cmake::MessageType t, std::ostringstream& msg) +void displayMessage(MessageType t, std::ostringstream& msg) { // Add a note about warning suppression. - if (t == cmake::AUTHOR_WARNING) { + if (t == MessageType::AUTHOR_WARNING) { msg << "This warning is for project developers. Use -Wno-dev to suppress " "it."; - } else if (t == cmake::AUTHOR_ERROR) { + } else if (t == MessageType::AUTHOR_ERROR) { msg << "This error is for project developers. Use -Wno-error=dev to " "suppress " "it."; @@ -110,7 +109,7 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg) #if defined(CMAKE_BUILD_WITH_CMAKE) // Add a C++ stack trace to internal errors. - if (t == cmake::INTERNAL_ERROR) { + if (t == MessageType::INTERNAL_ERROR) { std::string stack = cmsys::SystemInformation::GetProgramStack(0, 0); if (!stack.empty()) { if (cmHasLiteralPrefix(stack, "WARNING:")) { @@ -122,8 +121,8 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg) #endif // Output the message. - if (t == cmake::FATAL_ERROR || t == cmake::INTERNAL_ERROR || - t == cmake::DEPRECATION_ERROR || t == cmake::AUTHOR_ERROR) { + if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR || + t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) { cmSystemTools::SetErrorOccured(); cmSystemTools::Message(msg.str().c_str(), "Error"); } else { @@ -131,18 +130,13 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg) } } -cmMessenger::cmMessenger(cmState* state) - : State(state) -{ -} - -void cmMessenger::IssueMessage(cmake::MessageType t, const std::string& text, +void cmMessenger::IssueMessage(MessageType t, const std::string& text, const cmListFileBacktrace& backtrace) const { bool force = false; if (!force) { // override the message type, if needed, for warnings and errors - cmake::MessageType override = this->ConvertMessageType(t); + MessageType override = this->ConvertMessageType(t); if (override != t) { t = override; force = true; @@ -155,7 +149,7 @@ void cmMessenger::IssueMessage(cmake::MessageType t, const std::string& text, this->DisplayMessage(t, text, backtrace); } -void cmMessenger::DisplayMessage(cmake::MessageType t, const std::string& text, +void cmMessenger::DisplayMessage(MessageType t, const std::string& text, const cmListFileBacktrace& backtrace) const { std::ostringstream msg; @@ -173,31 +167,3 @@ void cmMessenger::DisplayMessage(cmake::MessageType t, const std::string& text, displayMessage(t, msg); } - -bool cmMessenger::GetSuppressDevWarnings() const -{ - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); - return cmSystemTools::IsOn(cacheEntryValue); -} - -bool cmMessenger::GetSuppressDeprecatedWarnings() const -{ - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED"); - return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue); -} - -bool cmMessenger::GetDevWarningsAsErrors() const -{ - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS"); - return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue); -} - -bool cmMessenger::GetDeprecatedWarningsAsErrors() const -{ - const char* cacheEntryValue = - this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED"); - return cmSystemTools::IsOn(cacheEntryValue); -} diff --git a/Source/cmMessenger.h b/Source/cmMessenger.h index 4aafbd4..cf15adf 100644 --- a/Source/cmMessenger.h +++ b/Source/cmMessenger.h @@ -6,34 +6,56 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmListFileCache.h" -#include "cmake.h" +#include "cmMessageType.h" #include <string> -class cmState; - class cmMessenger { public: - cmMessenger(cmState* state); - void IssueMessage( - cmake::MessageType t, std::string const& text, + MessageType t, std::string const& text, cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const; - void DisplayMessage(cmake::MessageType t, std::string const& text, + void DisplayMessage(MessageType t, std::string const& text, cmListFileBacktrace const& backtrace) const; - bool GetSuppressDevWarnings() const; - bool GetSuppressDeprecatedWarnings() const; - bool GetDevWarningsAsErrors() const; - bool GetDeprecatedWarningsAsErrors() const; + void SetSuppressDevWarnings(bool suppress) + { + this->SuppressDevWarnings = suppress; + } + void SetSuppressDeprecatedWarnings(bool suppress) + { + this->SuppressDeprecatedWarnings = suppress; + } + void SetDevWarningsAsErrors(bool error) + { + this->DevWarningsAsErrors = error; + } + void SetDeprecatedWarningsAsErrors(bool error) + { + this->DeprecatedWarningsAsErrors = error; + } + + bool GetSuppressDevWarnings() const { return this->SuppressDevWarnings; } + bool GetSuppressDeprecatedWarnings() const + { + return this->SuppressDeprecatedWarnings; + } + bool GetDevWarningsAsErrors() const { return this->DevWarningsAsErrors; } + bool GetDeprecatedWarningsAsErrors() const + { + return this->DeprecatedWarningsAsErrors; + } private: - bool IsMessageTypeVisible(cmake::MessageType t) const; - cmake::MessageType ConvertMessageType(cmake::MessageType t) const; + bool IsMessageTypeVisible(MessageType t) const; + MessageType ConvertMessageType(MessageType t) const; - cmState* State; + bool SuppressDevWarnings = false; + bool SuppressDeprecatedWarnings = false; + bool DevWarningsAsErrors = false; + bool DeprecatedWarningsAsErrors = false; }; #endif diff --git a/Source/cmNewLineStyle.cxx b/Source/cmNewLineStyle.cxx index 5500eba..12c18ee 100644 --- a/Source/cmNewLineStyle.cxx +++ b/Source/cmNewLineStyle.cxx @@ -5,7 +5,6 @@ #include <stddef.h> cmNewLineStyle::cmNewLineStyle() - : NewLineStyle(Invalid) { } diff --git a/Source/cmNewLineStyle.h b/Source/cmNewLineStyle.h index 397cd2c..f1a7bc6 100644 --- a/Source/cmNewLineStyle.h +++ b/Source/cmNewLineStyle.h @@ -33,7 +33,7 @@ public: const std::string GetCharacters() const; private: - Style NewLineStyle; + Style NewLineStyle = Invalid; }; #endif diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index c953d20..b62da66 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -9,6 +9,7 @@ #include <memory> // IWYU pragma: keep #include <set> #include <sstream> +#include <utility> #include "cmAlgorithms.h" #include "cmCustomCommandGenerator.h" @@ -37,13 +38,7 @@ class cmCustomCommand; cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator( cmGeneratorTarget* target) : cmNinjaTargetGenerator(target) - , TargetNameOut() - , TargetNameSO() - , TargetNameReal() - , TargetNameImport() - , TargetNamePDB() , TargetLinkLanguage("") - , DeviceLinkObject() { this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName()); if (target->GetType() == cmStateEnums::EXECUTABLE) { diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 7ac8d1b..5013be5 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -10,6 +10,7 @@ #include <map> #include <memory> // IWYU pragma: keep #include <sstream> +#include <utility> #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" @@ -18,6 +19,7 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalNinjaGenerator.h" +#include "cmListFileCache.h" // for BT #include "cmLocalGenerator.h" #include "cmLocalNinjaGenerator.h" #include "cmMakefile.h" @@ -54,10 +56,8 @@ cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target) : cmCommonTargetGenerator(target) , MacOSXContentGenerator(nullptr) , OSXBundleGenerator(nullptr) - , MacContentFolders() , LocalGenerator( static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator())) - , Objects() { MacOSXContentGenerator = new MacOSXContentGeneratorType(this); } @@ -431,6 +431,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) vars.TargetCompilePDB = "$TARGET_COMPILE_PDB"; vars.ObjectDir = "$OBJECT_DIR"; vars.ObjectFileDir = "$OBJECT_FILE_DIR"; + if (lang == "Swift") { + vars.SwiftAuxiliarySources = "$SWIFT_AUXILIARY_SOURCES"; + } // For some cases we do an explicit preprocessor invocation. bool const explicitPP = this->NeedExplicitPreprocessing(lang); @@ -901,6 +904,20 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( vars["FLAGS"] = this->ComputeFlagsForObject(source, language); vars["DEFINES"] = this->ComputeDefines(source, language); vars["INCLUDES"] = this->ComputeIncludes(source, language); + // The swift compiler needs all the sources besides the one being compiled in + // order to do the type checking. List all these "auxiliary" sources. + if (language == "Swift") { + std::string aux_sources; + cmGeneratorTarget::KindedSources const& sources = + this->GeneratorTarget->GetKindedSources(this->GetConfigName()); + for (cmGeneratorTarget::SourceAndKind const& src : sources.Sources) { + if (src.Source.Value == source) { + continue; + } + aux_sources += " " + this->GetSourceFilePath(src.Source.Value); + } + vars["SWIFT_AUXILIARY_SOURCES"] = aux_sources; + } if (!this->NeedDepTypeMSVC(language)) { bool replaceExt(false); diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index 006211d..52f63a3 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -6,12 +6,12 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmState.h" #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -81,7 +81,7 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args, "For compatibility with older versions of CMake, option " "is clearing the normal variable '" << args[0] << "'."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } } return true; diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx index 7fd7732..961e2b2 100644 --- a/Source/cmOrderDirectories.cxx +++ b/Source/cmOrderDirectories.cxx @@ -5,6 +5,7 @@ #include "cmAlgorithms.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmake.h" @@ -475,7 +476,7 @@ void cmOrderDirectories::FindImplicitConflicts() << " libraries in implicit directories:\n" << text << "Some of these libraries may not be found correctly."; this->GlobalGenerator->GetCMakeInstance()->IssueMessage( - cmake::WARNING, w.str(), this->Target->GetBacktrace()); + MessageType::WARNING, w.str(), this->Target->GetBacktrace()); } void cmOrderDirectories::OrderDirectories() @@ -544,7 +545,7 @@ void cmOrderDirectories::DiagnoseCycle() } e << "Some of these libraries may not be found correctly."; this->GlobalGenerator->GetCMakeInstance()->IssueMessage( - cmake::WARNING, e.str(), this->Target->GetBacktrace()); + MessageType::WARNING, e.str(), this->Target->GetBacktrace()); } bool cmOrderDirectories::IsSameDirectory(std::string const& l, diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx index 87c1ec0..ab1e699 100644 --- a/Source/cmOutputRequiredFilesCommand.cxx +++ b/Source/cmOutputRequiredFilesCommand.cxx @@ -28,11 +28,7 @@ public: * Construct with dependency generation marked not done; instance * not placed in cmMakefile's list. */ - cmDependInformation() - : DependDone(false) - , SourceFile(nullptr) - { - } + cmDependInformation() {} /** * The set of files on which this one depends. @@ -44,13 +40,13 @@ public: * This flag indicates whether dependency checking has been * performed for this file. */ - bool DependDone; + bool DependDone = false; /** * If this object corresponds to a cmSourceFile instance, this points * to it. */ - const cmSourceFile* SourceFile; + const cmSourceFile* SourceFile = nullptr; /** * Full path to this file. diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx index 2d61cc3..a2bf841 100644 --- a/Source/cmParseArgumentsCommand.cxx +++ b/Source/cmParseArgumentsCommand.cxx @@ -9,8 +9,8 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -46,7 +46,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, if (*argIter == "PARSE_ARGV") { if (args.size() != 6) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "PARSE_ARGV must be called with exactly 6 arguments."); cmSystemTools::SetFatalErrorOccured(); return true; @@ -54,7 +54,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, parseFromArgV = true; argIter++; // move past PARSE_ARGV if (!cmSystemTools::StringToULong(argIter->c_str(), &argvStart)) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "PARSE_ARGV index '" + *argIter + "' is not an unsigned integer"); cmSystemTools::SetFatalErrorOccured(); @@ -86,7 +86,8 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, cmSystemTools::ExpandListArgument(*argIter++, list); for (std::string const& iter : list) { if (!used_keywords.insert(iter).second) { - this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + iter); + this->GetMakefile()->IssueMessage(MessageType::WARNING, + dup_warning + iter); } options[iter]; // default initialize } @@ -96,7 +97,8 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, cmSystemTools::ExpandListArgument(*argIter++, list); for (std::string const& iter : list) { if (!used_keywords.insert(iter).second) { - this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + iter); + this->GetMakefile()->IssueMessage(MessageType::WARNING, + dup_warning + iter); } singleValArgs[iter]; // default initialize } @@ -106,7 +108,8 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, cmSystemTools::ExpandListArgument(*argIter++, list); for (std::string const& iter : list) { if (!used_keywords.insert(iter).second) { - this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + iter); + this->GetMakefile()->IssueMessage(MessageType::WARNING, + dup_warning + iter); } multiValArgs[iter]; // default initialize } @@ -131,7 +134,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, std::string argc = this->Makefile->GetSafeDefinition("ARGC"); unsigned long count; if (!cmSystemTools::StringToULong(argc.c_str(), &count)) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "PARSE_ARGV called with ARGC='" + argc + "' that is not an unsigned integer"); cmSystemTools::SetFatalErrorOccured(); @@ -142,7 +145,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args, argName << "ARGV" << i; const char* arg = this->Makefile->GetDefinition(argName.str()); if (!arg) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "PARSE_ARGV called with " + argName.str() + " not set"); cmSystemTools::SetFatalErrorOccured(); diff --git a/Source/cmPipeConnection.cxx b/Source/cmPipeConnection.cxx index 3dab2f0..999d6f3 100644 --- a/Source/cmPipeConnection.cxx +++ b/Source/cmPipeConnection.cxx @@ -2,7 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmPipeConnection.h" -#include <algorithm> +#include <utility> #include "cmServer.h" diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 5caea7d..0a234c5 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -2,11 +2,11 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmVersion.h" -#include "cmake.h" #include <assert.h> #include <ctype.h> @@ -128,7 +128,7 @@ static void DiagnoseAncientPolicies( << "Please either update your CMakeLists.txt files to conform to " << "the new behavior or use an older version of CMake that still " << "supports the old behavior."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); } static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy, @@ -146,7 +146,7 @@ static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy, std::ostringstream e; e << defaultVar << " has value \"" << defaultValue << "\" but must be \"OLD\", \"NEW\", or \"\" (empty)."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -167,14 +167,14 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, std::ostringstream e; e << "Invalid policy version value \"" << version_min << "\". " << "A numeric major.minor[.patch[.tweak]] must be given."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } // it is an error if the policy version is less than 2.4 if (minMajor < 2 || (minMajor == 2 && minMinor < 4)) { mf->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "Compatibility with CMake < 2.4 is not supported by CMake >= 3.0. " "For compatibility with older versions please use any CMake 2.8.x " "release or lower."); @@ -199,7 +199,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, << "This is not allowed because the greater version may have new " << "policies not known to this CMake. " << "You may need a newer CMake version to build this project."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -218,7 +218,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, std::ostringstream e; e << "Invalid policy max version value \"" << version_max << "\". " << "A numeric major.minor[.patch[.tweak]] must be given."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -232,7 +232,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, e << "Policy VERSION range \"" << version_min << "..." << version_max << "\"" << " specifies a larger minimum than maximum."; - mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 7674877..314f27d 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -254,7 +254,14 @@ class cmMakefile; 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0086, \ "UseSWIG honors SWIG_MODULE_NAME via -module flag.", 3, 14, 0, \ - cmPolicies::WARN) + cmPolicies::WARN) \ + SELECT(POLICY, CMP0087, \ + "Install CODE|SCRIPT allow the use of generator " \ + "expressions.", \ + 3, 14, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0088, \ + "FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.", \ + 3, 14, 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/cmProcessTools.cxx b/Source/cmProcessTools.cxx index 7ab1fa3..facde5d 100644 --- a/Source/cmProcessTools.cxx +++ b/Source/cmProcessTools.cxx @@ -45,10 +45,7 @@ void cmProcessTools::RunProcess(struct cmsysProcess_s* cp, OutputParser* out, } cmProcessTools::LineParser::LineParser(char sep, bool ignoreCR) - : Log(nullptr) - , Prefix(nullptr) - , Separator(sep) - , LineEnd('\0') + : Separator(sep) , IgnoreCR(ignoreCR) { } diff --git a/Source/cmProcessTools.h b/Source/cmProcessTools.h index f1c2a22..da3693d 100644 --- a/Source/cmProcessTools.h +++ b/Source/cmProcessTools.h @@ -54,11 +54,11 @@ public: void SetLog(std::ostream* log, const char* prefix); protected: - std::ostream* Log; - const char* Prefix; + std::ostream* Log = nullptr; + const char* Prefix = nullptr; std::string Line; char Separator; - char LineEnd; + char LineEnd = '\0'; bool IgnoreCR; bool ProcessChunk(const char* data, int length) override; diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 8f565c8..14e92c6 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -9,10 +9,10 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cmake.h" class cmExecutionStatus; @@ -90,7 +90,8 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, if (args[i] == "LANGUAGES") { if (haveLanguages) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, "LANGUAGES may be specified at most once."); + MessageType::FATAL_ERROR, + "LANGUAGES may be specified at most once."); cmSystemTools::SetFatalErrorOccured(); return true; } @@ -105,11 +106,11 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, "keyword: "; msg += cmJoin(languages, ", "); msg += '.'; - this->Makefile->IssueMessage(cmake::WARNING, msg); + this->Makefile->IssueMessage(MessageType::WARNING, msg); } } else if (args[i] == "VERSION") { if (haveVersion) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, "VERSION may be specified at most once."); cmSystemTools::SetFatalErrorOccured(); return true; @@ -121,7 +122,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, doing = DoingVersion; missedValueReporter = [this, &resetReporter]() { this->Makefile->IssueMessage( - cmake::WARNING, + MessageType::WARNING, "VERSION keyword not followed by a value or was followed by a " "value that expanded to nothing."); resetReporter(); @@ -129,7 +130,8 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, } else if (args[i] == "DESCRIPTION") { if (haveDescription) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, "DESCRIPTION may be specified at most once."); + MessageType::FATAL_ERROR, + "DESCRIPTION may be specified at most once."); cmSystemTools::SetFatalErrorOccured(); return true; } @@ -140,7 +142,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, doing = DoingDescription; missedValueReporter = [this, &resetReporter]() { this->Makefile->IssueMessage( - cmake::WARNING, + MessageType::WARNING, "DESCRIPTION keyword not followed by a value or was followed " "by a value that expanded to nothing."); resetReporter(); @@ -148,7 +150,8 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, } else if (args[i] == "HOMEPAGE_URL") { if (haveHomepage) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, "HOMEPAGE_URL may be specified at most once."); + MessageType::FATAL_ERROR, + "HOMEPAGE_URL may be specified at most once."); cmSystemTools::SetFatalErrorOccured(); return true; } @@ -156,7 +159,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, doing = DoingHomepage; missedValueReporter = [this, &resetReporter]() { this->Makefile->IssueMessage( - cmake::WARNING, + MessageType::WARNING, "HOMEPAGE_URL keyword not followed by a value or was followed " "by a value that expanded to nothing."); resetReporter(); @@ -188,7 +191,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, if ((haveVersion || haveDescription || haveHomepage) && !haveLanguages && !languages.empty()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "project with VERSION, DESCRIPTION or HOMEPAGE_URL must " "use LANGUAGES before language names."); cmSystemTools::SetFatalErrorOccured(); @@ -204,7 +207,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, // Set project VERSION variables to given values if (cmp0048 == cmPolicies::OLD || cmp0048 == cmPolicies::WARN) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "VERSION not allowed unless CMP0048 is set to NEW"); cmSystemTools::SetFatalErrorOccured(); return true; @@ -214,7 +217,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, "^([0-9]+(\\.[0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)?)?$"); if (!vx.find(version)) { std::string e = "VERSION \"" + version + "\" format invalid."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e); cmSystemTools::SetFatalErrorOccured(); return true; } @@ -296,7 +299,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, std::ostringstream w; w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0048) << "\nThe following variable(s) would be set to empty:" << vw; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } } diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx index 000529d..653caf7 100644 --- a/Source/cmQtAutoGen.cxx +++ b/Source/cmQtAutoGen.cxx @@ -9,6 +9,7 @@ #include <algorithm> #include <iterator> #include <sstream> +#include <utility> // - Static variables @@ -99,6 +100,41 @@ std::string cmQtAutoGen::GeneratorNameUpper(GeneratorT genType) return cmSystemTools::UpperCase(cmQtAutoGen::GeneratorName(genType)); } +std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc) +{ + std::string res; + std::vector<std::string> lst; + if (moc) { + lst.emplace_back("AUTOMOC"); + } + if (uic) { + lst.emplace_back("AUTOUIC"); + } + if (rcc) { + lst.emplace_back("AUTORCC"); + } + switch (lst.size()) { + case 1: + res += lst.at(0); + break; + case 2: + res += lst.at(0); + res += " and "; + res += lst.at(1); + break; + case 3: + res += lst.at(0); + res += ", "; + res += lst.at(1); + res += " and "; + res += lst.at(2); + break; + default: + break; + } + return res; +} + std::string cmQtAutoGen::Quoted(std::string const& text) { static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a", diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h index 4118dc7..96d1946 100644 --- a/Source/cmQtAutoGen.h +++ b/Source/cmQtAutoGen.h @@ -60,6 +60,9 @@ public: /// @brief Returns the generator name in upper case static std::string GeneratorNameUpper(GeneratorT genType); + /// @brief Returns a string with the requested tool names + static std::string Tools(bool moc, bool uic, bool rcc); + /// @brief Returns the string escaped and enclosed in quotes static std::string Quoted(std::string const& text); diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 5470ec3..431c5bc 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -9,6 +9,7 @@ #include "cmGeneratorTarget.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -75,13 +76,53 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( bool const uic = target->GetPropertyAsBool("AUTOUIC"); bool const rcc = target->GetPropertyAsBool("AUTORCC"); if (moc || uic || rcc) { - // We support Qt4 and Qt5 + std::string const mocExec = + target->GetSafeProperty("AUTOMOC_EXECUTABLE"); + std::string const uicExec = + target->GetSafeProperty("AUTOUIC_EXECUTABLE"); + std::string const rccExec = + target->GetSafeProperty("AUTORCC_EXECUTABLE"); + + // We support Qt4, Qt5 and Qt6 auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target); - if ((qtVersion.Major == 4) || (qtVersion.Major == 5)) { + bool const validQt = (qtVersion.first.Major == 4) || + (qtVersion.first.Major == 5) || (qtVersion.first.Major == 6); + + bool const mocAvailable = (validQt || !mocExec.empty()); + bool const uicAvailable = (validQt || !uicExec.empty()); + bool const rccAvailable = (validQt || !rccExec.empty()); + bool const mocIsValid = (moc && mocAvailable); + bool const uicIsValid = (uic && uicAvailable); + bool const rccIsValid = (rcc && rccAvailable); + // Disabled AUTOMOC/UIC/RCC warning + bool const mocDisabled = (moc && !mocAvailable); + bool const uicDisabled = (uic && !uicAvailable); + bool const rccDisabled = (rcc && !rccAvailable); + if (mocDisabled || uicDisabled || rccDisabled) { + std::string msg = "AUTOGEN: No valid Qt version found for target "; + msg += target->GetName(); + msg += ". "; + msg += cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled); + msg += " disabled. Consider adding:\n"; + { + std::string version = (qtVersion.second == 0) + ? std::string("<QTVERSION>") + : std::to_string(qtVersion.second); + std::string comp = uicDisabled ? "Widgets" : "Core"; + msg += " find_package(Qt"; + msg += version; + msg += " COMPONENTS "; + msg += comp; + msg += ")\n"; + } + msg += "to your CMakeLists.txt file."; + target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg); + } + if (mocIsValid || uicIsValid || rccIsValid) { // Create autogen target initializer Initializers_.emplace_back(cm::make_unique<cmQtAutoGenInitializer>( - this, target, qtVersion, moc, uic, rcc, globalAutoGenTarget, - globalAutoRccTarget)); + this, target, qtVersion.first, mocIsValid, uicIsValid, rccIsValid, + globalAutoGenTarget, globalAutoRccTarget)); } } } diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 6a2a951..9fa8a89 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -9,12 +9,14 @@ #include "cmCustomCommandLines.h" #include "cmDuration.h" #include "cmFilePathChecksum.h" +#include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmLinkItem.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmOutputConverter.h" #include "cmPolicies.h" #include "cmProcessOutput.h" @@ -42,6 +44,9 @@ std::string GetQtExecutableTargetName( const cmQtAutoGen::IntegerVersion& qtVersion, std::string const& executable) { + if (qtVersion.Major == 6) { + return ("Qt6::" + executable); + } if (qtVersion.Major == 5) { return ("Qt5::" + executable); } @@ -395,8 +400,16 @@ bool cmQtAutoGenInitializer::InitCustomTargets() } // Init uic specific settings - if (this->Uic.Enabled && !InitUic()) { - return false; + if (this->Uic.Enabled) { + if (InitUic()) { + auto* uicTarget = makefile->FindTargetToUse( + GetQtExecutableTargetName(this->QtVersion, "uic")); + if (uicTarget != nullptr) { + this->AutogenTarget.DependTargets.insert(uicTarget); + } + } else { + return false; + } } // Autogen target name @@ -437,6 +450,12 @@ bool cmQtAutoGenInitializer::InitCustomTargets() this->AutogenTarget.DependOrigin = this->Target->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS"); + auto* mocTarget = makefile->FindTargetToUse( + GetQtExecutableTargetName(this->QtVersion, "moc")); + if (mocTarget != nullptr) { + this->AutogenTarget.DependTargets.insert(mocTarget); + } + std::string const deps = this->Target->GetSafeProperty("AUTOGEN_TARGET_DEPENDS"); if (!deps.empty()) { @@ -504,7 +523,7 @@ bool cmQtAutoGenInitializer::InitMoc() { // We need to disable this until we have all implicit includes available. // See issue #18669. - // bool const appendImplicit = (this->QtVersion.Major == 5); + // bool const appendImplicit = (this->QtVersion.Major >= 5); auto GetIncludeDirs = [this, localGen](std::string const& cfg) -> std::vector<std::string> { @@ -824,7 +843,7 @@ bool cmQtAutoGenInitializer::InitScanFiles() msg += ":\n set_property(SOURCE file.h PROPERTY "; msg += property; msg += " ON)\n"; - makefile->IssueMessage(cmake::AUTHOR_WARNING, msg); + makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg); } } } @@ -839,7 +858,7 @@ bool cmQtAutoGenInitializer::InitScanFiles() // Process qrc files if (!this->Rcc.Qrcs.empty()) { - const bool QtV5 = (this->QtVersion.Major == 5); + const bool modernQt = (this->QtVersion.Major >= 5); // Target rcc options std::vector<std::string> optionsTarget; cmSystemTools::ExpandListArgument( @@ -911,10 +930,10 @@ bool cmQtAutoGenInitializer::InitScanFiles() std::vector<std::string> nameOpts; nameOpts.emplace_back("-name"); nameOpts.emplace_back(std::move(name)); - RccMergeOptions(opts, nameOpts, QtV5); + RccMergeOptions(opts, nameOpts, modernQt); } // Merge file option - RccMergeOptions(opts, qrc.Options, QtV5); + RccMergeOptions(opts, qrc.Options, modernQt); qrc.Options = std::move(opts); } // RCC resources @@ -1092,6 +1111,7 @@ bool cmQtAutoGenInitializer::InitRccTargets() { cmMakefile* makefile = this->Target->Target->GetMakefile(); cmLocalGenerator* localGen = this->Target->GetLocalGenerator(); + auto rccTargetName = GetQtExecutableTargetName(this->QtVersion, "rcc"); for (Qrc const& qrc : this->Rcc.Qrcs) { // Register info file as generated by CMake @@ -1102,6 +1122,11 @@ bool cmQtAutoGenInitializer::InitRccTargets() std::vector<std::string> ccOutput; ccOutput.push_back(qrc.RccFile); + std::vector<std::string> ccDepends; + // Add the .qrc and info file to the custom command dependencies + ccDepends.push_back(qrc.QrcFile); + ccDepends.push_back(qrc.InfoFile); + cmCustomCommandLines commandLines; if (this->MultiConfig) { // Build for all configurations @@ -1137,15 +1162,12 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccName += "_"; ccName += qrc.PathChecksum; } - std::vector<std::string> ccDepends; - // Add the .qrc and info file to the custom target dependencies - ccDepends.push_back(qrc.QrcFile); - ccDepends.push_back(qrc.InfoFile); cmTarget* autoRccTarget = makefile->AddUtilityCommand( ccName, cmMakefile::TargetOrigin::Generator, true, this->Dir.Work.c_str(), ccOutput, ccDepends, commandLines, false, ccComment.c_str()); + // Create autogen generator target localGen->AddGeneratorTarget( new cmGeneratorTarget(autoRccTarget, localGen)); @@ -1154,6 +1176,9 @@ bool cmQtAutoGenInitializer::InitRccTargets() if (!this->TargetsFolder.empty()) { autoRccTarget->SetProperty("FOLDER", this->TargetsFolder.c_str()); } + if (!rccTargetName.empty()) { + autoRccTarget->AddUtility(rccTargetName, makefile); + } } // Add autogen target to the origin target dependencies this->Target->Target->AddUtility(ccName, makefile); @@ -1166,16 +1191,15 @@ bool cmQtAutoGenInitializer::InitRccTargets() // Create custom rcc command { std::vector<std::string> ccByproducts; - std::vector<std::string> ccDepends; - // Add the .qrc and info file to the custom command dependencies - ccDepends.push_back(qrc.QrcFile); - ccDepends.push_back(qrc.InfoFile); // Add the resource files to the dependencies for (std::string const& fileName : qrc.Resources) { // Add resource file to the custom command dependencies ccDepends.push_back(fileName); } + if (!rccTargetName.empty()) { + ccDepends.push_back(rccTargetName); + } makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends, /*main_dependency*/ std::string(), commandLines, ccComment.c_str(), @@ -1208,11 +1232,7 @@ bool cmQtAutoGenInitializer::SetupCustomTargets() } // Write AUTORCC info files - if (this->Rcc.Enabled && !this->SetupWriteRccInfo()) { - return false; - } - - return true; + return !this->Rcc.Enabled || this->SetupWriteRccInfo(); } bool cmQtAutoGenInitializer::SetupWriteAutogenInfo() @@ -1374,7 +1394,7 @@ static std::vector<cmQtAutoGenInitializer::IntegerVersion> GetKnownQtVersions( std::vector<cmQtAutoGenInitializer::IntegerVersion> result; for (const std::string& prefix : - std::vector<std::string>({ "Qt5Core", "QT" })) { + std::vector<std::string>({ "Qt6Core", "Qt5Core", "QT" })) { auto tmp = cmQtAutoGenInitializer::IntegerVersion( StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MAJOR")), StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MINOR"))); @@ -1386,53 +1406,67 @@ static std::vector<cmQtAutoGenInitializer::IntegerVersion> GetKnownQtVersions( return result; } -cmQtAutoGenInitializer::IntegerVersion cmQtAutoGenInitializer::GetQtVersion( - cmGeneratorTarget const* target) +std::pair<cmQtAutoGenInitializer::IntegerVersion, unsigned int> +cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target) { - auto knownQtVersions = GetKnownQtVersions(target); - if (knownQtVersions.empty()) { - return cmQtAutoGenInitializer::IntegerVersion(); // No Qt - } + std::pair<IntegerVersion, unsigned int> res( + IntegerVersion(), + CharPtrToInt(target->GetLinkInterfaceDependentStringProperty( + "QT_MAJOR_VERSION", ""))); - // Pick a version from the known versions: - auto targetVersion = CharPtrToInt( - target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", "")); - - if (targetVersion == 0) { - // No specific version was requested by the target: - // Use highest known Qt version. - return knownQtVersions.at(0); - } - - for (auto it : knownQtVersions) { - if (it.Major == targetVersion) { - return it; + auto knownQtVersions = GetKnownQtVersions(target); + if (!knownQtVersions.empty()) { + if (res.second == 0) { + // No specific version was requested by the target: + // Use highest known Qt version. + res.first = knownQtVersions.at(0); + } else { + // Pick a version from the known versions: + for (auto it : knownQtVersions) { + if (it.Major == res.second) { + res.first = it; + break; + } + } } } - - // Requested version was not found - return cmQtAutoGenInitializer::IntegerVersion(); + return res; } std::pair<bool, std::string> GetQtExecutable( const cmQtAutoGen::IntegerVersion& qtVersion, cmGeneratorTarget* target, const std::string& executable, bool ignoreMissingTarget, std::string* output) { + const std::string upperExecutable = cmSystemTools::UpperCase(executable); + std::string result = + target->Target->GetSafeProperty("AUTO" + upperExecutable + "_EXECUTABLE"); + if (!result.empty()) { + cmListFileBacktrace lfbt = target->Target->GetMakefile()->GetBacktrace(); + cmGeneratorExpression ge(lfbt); + std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(result); + result = cge->Evaluate(target->GetLocalGenerator(), ""); + + return std::make_pair(true, result); + } + std::string err; - std::string result; // Find executable { const std::string targetName = GetQtExecutableTargetName(qtVersion, executable); if (targetName.empty()) { - err = "The AUTOMOC, AUTOUIC and AUTORCC feature "; - err += "supports only Qt 4 and Qt 5"; + err = "The AUTO" + upperExecutable + " feature "; + err += "supports only Qt 4, Qt 5 and Qt 6."; } else { cmLocalGenerator* localGen = target->GetLocalGenerator(); cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse(targetName); if (tgt != nullptr) { - result = tgt->ImportedGetLocation(""); + if (tgt->IsImported()) { + result = tgt->ImportedGetLocation(""); + } else { + result = tgt->GetLocation(""); + } } else { if (ignoreMissingTarget) { return std::make_pair(true, ""); @@ -1510,7 +1544,7 @@ bool cmQtAutoGenInitializer::GetRccExecutable() return false; } - if (this->QtVersion.Major == 5) { + if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) { if (stdOut.find("--list") != std::string::npos) { this->Rcc.ListOptions.push_back("--list"); } else { diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index d817848..47f157c 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -11,6 +11,7 @@ #include <ostream> #include <set> #include <string> +#include <utility> #include <vector> class cmGeneratorTarget; @@ -25,11 +26,7 @@ public: class Qrc { public: - Qrc() - : Generated(false) - , Unique(false) - { - } + Qrc() {} public: std::string LockFile; @@ -40,8 +37,8 @@ public: std::string SettingsFile; std::map<std::string, std::string> ConfigSettingsFile; std::string RccFile; - bool Generated; - bool Unique; + bool Generated = false; + bool Unique = false; std::vector<std::string> Options; std::vector<std::string> Resources; }; @@ -80,7 +77,9 @@ public: }; public: - static IntegerVersion GetQtVersion(cmGeneratorTarget const* target); + /// @return The detected Qt version and the required Qt major version + static std::pair<IntegerVersion, unsigned int> GetQtVersion( + cmGeneratorTarget const* target); cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer, cmGeneratorTarget* target, diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx index 734b2d7..f2f4cad 100644 --- a/Source/cmQtAutoGenerator.cxx +++ b/Source/cmQtAutoGenerator.cxx @@ -14,6 +14,7 @@ #include "cmake.h" #include <algorithm> +#include <utility> // -- Class methods diff --git a/Source/cmQtAutoGeneratorMocUic.cxx b/Source/cmQtAutoGeneratorMocUic.cxx index 446ef9a..9658e97 100644 --- a/Source/cmQtAutoGeneratorMocUic.cxx +++ b/Source/cmQtAutoGeneratorMocUic.cxx @@ -1,19 +1,21 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQtAutoGeneratorMocUic.h" -#include "cmQtAutoGen.h" #include <algorithm> #include <array> +#include <cstddef> #include <functional> #include <list> #include <memory> +#include <set> #include <sstream> #include <utility> #include "cmAlgorithms.h" #include "cmCryptoHash.h" #include "cmMakefile.h" +#include "cmQtAutoGen.h" #include "cmSystemTools.h" #include "cmake.h" @@ -1130,11 +1132,6 @@ void cmQtAutoGeneratorMocUic::WorkerT::UVProcessFinished() cmQtAutoGeneratorMocUic::cmQtAutoGeneratorMocUic() : Base_(&FileSys()) , Moc_(&FileSys()) - , Stage_(StageT::SETTINGS_READ) - , JobsRemain_(0) - , JobError_(false) - , JobThreadsAbort_(false) - , MocAutoFileUpdated_(false) { // Precompile regular expressions Moc_.RegExpInclude.compile( diff --git a/Source/cmQtAutoGeneratorMocUic.h b/Source/cmQtAutoGeneratorMocUic.h index 2226954..9ec1def 100644 --- a/Source/cmQtAutoGeneratorMocUic.h +++ b/Source/cmQtAutoGeneratorMocUic.h @@ -11,7 +11,6 @@ #include "cm_uv.h" #include "cmsys/RegularExpression.hxx" -#include <algorithm> #include <condition_variable> #include <cstddef> #include <deque> @@ -21,6 +20,7 @@ #include <set> #include <string> #include <thread> +#include <utility> #include <vector> class cmMakefile; @@ -404,7 +404,7 @@ private: MocSettingsT Moc_; UicSettingsT Uic_; // -- Progress - StageT Stage_; + StageT Stage_ = StageT::SETTINGS_READ; // -- Job queues std::mutex JobsMutex_; struct @@ -416,15 +416,15 @@ private: JobQueueT Uic; } JobQueues_; JobQueueT JobQueue_; - std::size_t volatile JobsRemain_; - bool volatile JobError_; - bool volatile JobThreadsAbort_; + std::size_t volatile JobsRemain_ = 0; + bool volatile JobError_ = false; + bool volatile JobThreadsAbort_ = false; std::condition_variable JobsConditionRead_; // -- Moc meta std::set<std::string> MocIncludedStrings_; std::set<std::string> MocIncludedFiles_; std::set<std::string> MocAutoFiles_; - bool volatile MocAutoFileUpdated_; + bool volatile MocAutoFileUpdated_ = false; // -- Settings file std::string SettingsFile_; std::string SettingsStringMoc_; diff --git a/Source/cmQtAutoGeneratorRcc.cxx b/Source/cmQtAutoGeneratorRcc.cxx index 65c6741..29dc7a0 100644 --- a/Source/cmQtAutoGeneratorRcc.cxx +++ b/Source/cmQtAutoGeneratorRcc.cxx @@ -15,12 +15,6 @@ // -- Class methods cmQtAutoGeneratorRcc::cmQtAutoGeneratorRcc() - : MultiConfig_(false) - , SettingsChanged_(false) - , Stage_(StageT::SETTINGS_READ) - , Error_(false) - , Generate_(false) - , BuildFileChanged_(false) { // Initialize libuv asynchronous iteration request UVRequest().init(*UVLoop(), &cmQtAutoGeneratorRcc::UVPollStage, this); diff --git a/Source/cmQtAutoGeneratorRcc.h b/Source/cmQtAutoGeneratorRcc.h index 74cec36..1148071 100644 --- a/Source/cmQtAutoGeneratorRcc.h +++ b/Source/cmQtAutoGeneratorRcc.h @@ -70,7 +70,7 @@ private: private: // -- Config settings - bool MultiConfig_; + bool MultiConfig_ = false; // -- Directories std::string AutogenBuildDir_; std::string IncludeDir_; @@ -95,12 +95,12 @@ private: // -- Settings file std::string SettingsFile_; std::string SettingsString_; - bool SettingsChanged_; + bool SettingsChanged_ = false; // -- libuv loop - StageT Stage_; - bool Error_; - bool Generate_; - bool BuildFileChanged_; + StageT Stage_ = StageT::SETTINGS_READ; + bool Error_ = false; + bool Generate_ = false; + bool BuildFileChanged_ = false; }; #endif diff --git a/Source/cmRulePlaceholderExpander.cxx b/Source/cmRulePlaceholderExpander.cxx index 0dfb797..4b74ff0 100644 --- a/Source/cmRulePlaceholderExpander.cxx +++ b/Source/cmRulePlaceholderExpander.cxx @@ -162,6 +162,11 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable( } } } + if (replaceValues.SwiftAuxiliarySources) { + if (variable == "SWIFT_AUXILIARY_SOURCES") { + return replaceValues.SwiftAuxiliarySources; + } + } if (variable == "TARGET_SONAME" || variable == "SONAME_FLAG" || variable == "TARGET_INSTALLNAME_DIR") { // All these variables depend on TargetSOName diff --git a/Source/cmRulePlaceholderExpander.h b/Source/cmRulePlaceholderExpander.h index a7d8cee..a936747 100644 --- a/Source/cmRulePlaceholderExpander.h +++ b/Source/cmRulePlaceholderExpander.h @@ -58,6 +58,7 @@ public: const char* Includes; const char* DependencyFile; const char* FilterPrefix; + const char* SwiftAuxiliarySources; }; // Expand rule variables in CMake of the type found in language rules diff --git a/Source/cmScriptGenerator.h b/Source/cmScriptGenerator.h index c8fed19..0bb388e 100644 --- a/Source/cmScriptGenerator.h +++ b/Source/cmScriptGenerator.h @@ -12,10 +12,7 @@ class cmScriptGeneratorIndent { public: - cmScriptGeneratorIndent() - : Level(0) - { - } + cmScriptGeneratorIndent() {} cmScriptGeneratorIndent(int level) : Level(level) { @@ -32,7 +29,7 @@ public: } private: - int Level; + int Level = 0; }; inline std::ostream& operator<<(std::ostream& os, cmScriptGeneratorIndent indent) diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index fe0bdc9..f7d3879 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -417,7 +417,7 @@ static void __start_thread(void* arg) auto server = static_cast<cmServerBase*>(arg); std::string error; bool success = server->Serve(&error); - if (!success || error.empty() == false) { + if (!success || !error.empty()) { std::cerr << "Error during serve: " << error << std::endl; } } diff --git a/Source/cmServerConnection.cxx b/Source/cmServerConnection.cxx index 1fc8cf8..5caa019 100644 --- a/Source/cmServerConnection.cxx +++ b/Source/cmServerConnection.cxx @@ -7,13 +7,13 @@ #include "cmServerDictionary.h" #include "cm_uv.h" -#include <algorithm> #ifdef _WIN32 # include "io.h" #else # include <unistd.h> #endif #include <cassert> +#include <utility> cmStdIoConnection::cmStdIoConnection( cmConnectionBufferStrategy* bufferStrategy) diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 5d1f3f0..efc6bb5 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -7,6 +7,7 @@ #include "cmCustomCommand.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmProperty.h" #include "cmState.h" #include "cmSystemTools.h" @@ -179,7 +180,8 @@ bool cmSourceFile::FindFullPath(std::string* error) if (error) { *error = e.str(); } else { - this->Location.GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Location.GetMakefile()->IssueMessage(MessageType::FATAL_ERROR, + e.str()); } this->FindFullPathFailed = true; return false; diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index 15433f9..3dab638 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -5,15 +5,13 @@ #include "cmAlgorithms.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmake.h" #include <assert.h> cmSourceFileLocation::cmSourceFileLocation() - : Makefile(nullptr) - , AmbiguousDirectory(true) - , AmbiguousExtension(true) { } @@ -197,7 +195,7 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc) // This can occur when referencing a source file from a different // directory. This is not yet allowed. this->Makefile->IssueMessage( - cmake::INTERNAL_ERROR, + MessageType::INTERNAL_ERROR, "Matches error: Each side has a directory relative to a different " "location. This can occur when referencing a source file from a " "different directory. This is not yet allowed."); diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h index 886a184..82747ba 100644 --- a/Source/cmSourceFileLocation.h +++ b/Source/cmSourceFileLocation.h @@ -83,9 +83,9 @@ public: cmMakefile const* GetMakefile() const { return this->Makefile; } private: - cmMakefile const* const Makefile; - bool AmbiguousDirectory; - bool AmbiguousExtension; + cmMakefile const* const Makefile = nullptr; + bool AmbiguousDirectory = true; + bool AmbiguousExtension = true; std::string Directory; std::string Name; diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index c3df313..08f4d1a 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -254,16 +254,12 @@ bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args, bool cmSourceGroupCommand::checkArgumentsPreconditions( const ParsedArguments& parsedArguments, std::string& errorMsg) const { - if (!checkSingleParameterArgumentPreconditions(kPrefixOptionName, - parsedArguments, errorMsg) || - !checkSingleParameterArgumentPreconditions(kTreeOptionName, - parsedArguments, errorMsg) || - !checkSingleParameterArgumentPreconditions(kRegexOptionName, - parsedArguments, errorMsg)) { - return false; - } - - return true; + return checkSingleParameterArgumentPreconditions( + kPrefixOptionName, parsedArguments, errorMsg) && + checkSingleParameterArgumentPreconditions(kTreeOptionName, parsedArguments, + errorMsg) && + checkSingleParameterArgumentPreconditions(kRegexOptionName, + parsedArguments, errorMsg); } bool cmSourceGroupCommand::processTree(ParsedArguments& parsedArguments, @@ -286,12 +282,8 @@ bool cmSourceGroupCommand::processTree(ParsedArguments& parsedArguments, std::set<std::string> sourceGroupPaths = getSourceGroupFilesPaths(root, filesVector); - if (!addFilesToItsSourceGroups(root, sourceGroupPaths, prefix, - *(this->Makefile), errorMsg)) { - return false; - } - - return true; + return addFilesToItsSourceGroups(root, sourceGroupPaths, prefix, + *(this->Makefile), errorMsg); } bool cmSourceGroupCommand::checkSingleParameterArgumentPreconditions( diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 4bbd2e0..f664000 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -22,14 +22,6 @@ #include "cmake.h" cmState::cmState() - : IsInTryCompile(false) - , IsGeneratorMultiConfig(false) - , WindowsShell(false) - , WindowsVSIDE(false) - , WatcomWMake(false) - , MinGWMake(false) - , NMake(false) - , MSYSShell(false) { this->CacheManager = new cmCacheManager; this->GlobVerificationManager = new cmGlobVerificationManager; diff --git a/Source/cmState.h b/Source/cmState.h index 916985d..abe93ed 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -202,14 +202,14 @@ private: std::string SourceDirectory; std::string BinaryDirectory; - bool IsInTryCompile; - bool IsGeneratorMultiConfig; - bool WindowsShell; - bool WindowsVSIDE; - bool WatcomWMake; - bool MinGWMake; - bool NMake; - bool MSYSShell; + bool IsInTryCompile = false; + bool IsGeneratorMultiConfig = false; + bool WindowsShell = false; + bool WindowsVSIDE = false; + bool WatcomWMake = false; + bool MinGWMake = false; + bool NMake = false; + bool MSYSShell = false; }; #endif diff --git a/Source/cmStatePrivate.h b/Source/cmStatePrivate.h index e76f2af..ec0ed6c 100644 --- a/Source/cmStatePrivate.h +++ b/Source/cmStatePrivate.h @@ -50,8 +50,7 @@ struct cmStateDetail::PolicyStackEntry : public cmPolicies::PolicyMap { typedef cmPolicies::PolicyMap derived; PolicyStackEntry(bool w = false) - : derived() - , Weak(w) + : Weak(w) { } PolicyStackEntry(derived const& d, bool w) diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index a649f5e..a4305e6 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -28,7 +28,6 @@ cmStateSnapshot::cmStateSnapshot(cmState* state) : State(state) - , Position() { } diff --git a/Source/cmString.hxx b/Source/cmString.hxx index 1623a43..49bad78 100644 --- a/Source/cmString.hxx +++ b/Source/cmString.hxx @@ -15,6 +15,7 @@ #include <ostream> #include <string> #include <type_traits> +#include <utility> namespace cm { @@ -625,8 +626,7 @@ private: // Internal constructor for view of statically allocated string. String(string_view v, Private) - : string_() - , view_(v) + : view_(v) { } diff --git a/Source/cmStringReplaceHelper.h b/Source/cmStringReplaceHelper.h index 938325a..3e76d86 100644 --- a/Source/cmStringReplaceHelper.h +++ b/Source/cmStringReplaceHelper.h @@ -46,7 +46,6 @@ private: } RegexReplacement(int n) : Number(n) - , Value() { } RegexReplacement() {} diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 688f73b..a94cf6a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -17,6 +17,7 @@ #include "cmGlobalGenerator.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmMessenger.h" #include "cmOutputConverter.h" #include "cmProperty.h" @@ -99,7 +100,7 @@ const char* cmTargetPropertyComputer::GetSources<cmTarget>( bool addContent = false; bool noMessage = true; std::ostringstream e; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (context.GetBottom().GetPolicy(cmPolicies::CMP0051)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n"; @@ -570,7 +571,7 @@ std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s) if (src != s) { std::ostringstream e; bool noMessage = false; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n"; @@ -581,7 +582,7 @@ std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s) case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (!noMessage) { e << "Legacy variable expansion in source file \"" << s @@ -589,7 +590,7 @@ std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s) << "\". This behavior will be removed in a " "future version of CMake."; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return ""; } } @@ -933,40 +934,40 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) if (prop == propMANUALLY_ADDED_DEPENDENCIES) { std::ostringstream e; e << "MANUALLY_ADDED_DEPENDENCIES property is read-only\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == propNAME) { std::ostringstream e; e << "NAME property is read-only\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == propTYPE) { std::ostringstream e; e << "TYPE property is read-only\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == propEXPORT_NAME && this->IsImported()) { std::ostringstream e; e << "EXPORT_NAME property can't be set on imported targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == propSOURCES && this->IsImported()) { std::ostringstream e; e << "SOURCES property can't be set on imported targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == propIMPORTED_GLOBAL && !this->IsImported()) { std::ostringstream e; e << "IMPORTED_GLOBAL property can't be set on non-imported targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } @@ -1039,7 +1040,7 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) std::ostringstream e; e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } /* no need to change anything if value does not change */ @@ -1056,7 +1057,7 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) e << "CUDA_PTX_COMPILATION property can only be applied to OBJECT " "targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } else { this->Properties.SetProperty(prop, value); @@ -1074,21 +1075,21 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value, if (prop == "NAME") { std::ostringstream e; e << "NAME property is read-only\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == "EXPORT_NAME" && this->IsImported()) { std::ostringstream e; e << "EXPORT_NAME property can't be set on imported targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == "SOURCES" && this->IsImported()) { std::ostringstream e; e << "SOURCES property can't be set on imported targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == "IMPORTED_GLOBAL") { @@ -1096,7 +1097,7 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value, e << "IMPORTED_GLOBAL property can't be appended, only set on imported " "targets (\"" << this->Name << "\")\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } if (prop == "INCLUDE_DIRECTORIES") { @@ -1146,7 +1147,7 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value, this->Internal->SourceEntries.push_back(value); this->Internal->SourceBacktraces.push_back(lfbt); } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, prop + " property may not be APPENDed."); } else { this->Properties.AppendProperty(prop, value, asString); @@ -1283,7 +1284,7 @@ static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop, << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG " << "properties accordingly."; } - context->IssueMessage(cmake::FATAL_ERROR, e.str()); + context->IssueMessage(MessageType::FATAL_ERROR, e.str()); } static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value, @@ -1305,7 +1306,7 @@ static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value, "property may contain configuration-sensitive generator-expressions " "which may be used to specify per-configuration rules."; - context->IssueMessage(cmake::FATAL_ERROR, e.str()); + context->IssueMessage(MessageType::FATAL_ERROR, e.str()); } static void cmTargetCheckIMPORTED_GLOBAL(const cmTarget* target, @@ -1319,7 +1320,7 @@ static void cmTargetCheckIMPORTED_GLOBAL(const cmTarget* target, e << "Attempt to promote imported target \"" << target->GetName() << "\" to global scope (by setting IMPORTED_GLOBAL) " "which is not built in this directory."; - context->IssueMessage(cmake::FATAL_ERROR, e.str()); + context->IssueMessage(MessageType::FATAL_ERROR, e.str()); } } @@ -1683,21 +1684,21 @@ bool cmTarget::CheckImportedLibName(std::string const& prop, if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY || !this->IsImported()) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, prop + " property may be set only on imported INTERFACE library targets."); return false; } if (!value.empty()) { if (value[0] == '-') { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, prop + " property value\n " + value + "\nmay not start with '-'."); return false; } std::string::size_type bad = value.find_first_of(":/\\;"); if (bad != std::string::npos) { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, prop + " property value\n " + value + "\nmay not contain '" + value.substr(bad, 1) + "'."); diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index 4e716dc..c4dc838 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -6,8 +6,8 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -24,7 +24,7 @@ void cmTargetCompileDefinitionsCommand::HandleMissingTarget( e << "Cannot specify compile definitions for target \"" << name << "\" " "which is not built by this project."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } std::string cmTargetCompileDefinitionsCommand::Join( diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx index f58e404..c9e394b 100644 --- a/Source/cmTargetCompileFeaturesCommand.cxx +++ b/Source/cmTargetCompileFeaturesCommand.cxx @@ -6,7 +6,7 @@ #include "cmAlgorithms.h" #include "cmMakefile.h" -#include "cmake.h" +#include "cmMessageType.h" class cmExecutionStatus; class cmTarget; @@ -24,7 +24,7 @@ void cmTargetCompileFeaturesCommand::HandleMissingTarget( e << "Cannot specify compile features for target \"" << name << "\" " "which is not built by this project."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } std::string cmTargetCompileFeaturesCommand::Join( diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx index 4df3630..8b4763a 100644 --- a/Source/cmTargetCompileOptionsCommand.cxx +++ b/Source/cmTargetCompileOptionsCommand.cxx @@ -7,8 +7,8 @@ #include "cmAlgorithms.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -24,7 +24,7 @@ void cmTargetCompileOptionsCommand::HandleMissingTarget( std::ostringstream e; e << "Cannot specify compile options for target \"" << name << "\" which is not built by this project."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } std::string cmTargetCompileOptionsCommand::Join( diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index af142aa..d6918c0 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -8,9 +8,9 @@ #include "cmGeneratorExpression.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -27,7 +27,7 @@ void cmTargetIncludeDirectoriesCommand::HandleMissingTarget( std::ostringstream e; e << "Cannot specify include directories for target \"" << name << "\" which is not built by this project."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } std::string cmTargetIncludeDirectoriesCommand::Join( diff --git a/Source/cmTargetLinkDirectoriesCommand.cxx b/Source/cmTargetLinkDirectoriesCommand.cxx index bca3e45..269f751 100644 --- a/Source/cmTargetLinkDirectoriesCommand.cxx +++ b/Source/cmTargetLinkDirectoriesCommand.cxx @@ -8,9 +8,9 @@ #include "cmGeneratorExpression.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -26,7 +26,7 @@ void cmTargetLinkDirectoriesCommand::HandleMissingTarget( std::ostringstream e; e << "Cannot specify link directories for target \"" << name << "\" which is not built by this project."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } std::string cmTargetLinkDirectoriesCommand::Join( diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index eebf7a0..5c7b95c 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -8,6 +8,7 @@ #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmState.h" #include "cmStateTypes.h" @@ -51,7 +52,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( } } if (!this->Target) { - cmake::MessageType t = cmake::FATAL_ERROR; // fail by default + MessageType t = MessageType::FATAL_ERROR; // fail by default std::ostringstream e; e << "Cannot specify link libraries for target \"" << args[0] << "\" " << "which is not built by this project."; @@ -60,7 +61,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( if (args.size() < 2) { switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0016)) { case cmPolicies::WARN: - t = cmake::AUTHOR_WARNING; + t = MessageType::AUTHOR_WARNING; // Print the warning. e << "\n" << "CMake does not support this but it used to work accidentally " @@ -69,7 +70,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( << cmPolicies::GetPolicyWarning(cmPolicies::CMP0016); break; case cmPolicies::OLD: // OLD behavior does not warn. - t = cmake::MESSAGE; + t = MessageType::MESSAGE; break; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: @@ -81,11 +82,11 @@ bool cmTargetLinkLibrariesCommand::InitialPass( } // Now actually print the message. switch (t) { - case cmake::AUTHOR_WARNING: - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + case MessageType::AUTHOR_WARNING: + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); break; - case cmake::FATAL_ERROR: - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + case MessageType::FATAL_ERROR: + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); break; default: @@ -98,7 +99,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( if (this->Target->GetType() == cmStateEnums::UTILITY) { std::ostringstream e; const char* modal = nullptr; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0039)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0039) << "\n"; @@ -109,13 +110,13 @@ bool cmTargetLinkLibrariesCommand::InitialPass( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: modal = "must"; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (modal) { e << "Utility target \"" << this->Target->GetName() << "\" " << modal << " not be used as the target of a target_link_libraries call."; this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } @@ -141,7 +142,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( this->CurrentProcessingState = ProcessingPlainLinkInterface; if (i != 1) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The LINK_INTERFACE_LIBRARIES option must appear as the second " "argument, just after the target name."); return true; @@ -152,7 +153,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( this->CurrentProcessingState != ProcessingKeywordPublicInterface && this->CurrentProcessingState != ProcessingKeywordLinkInterface) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The INTERFACE, PUBLIC or PRIVATE option must appear as the second " "argument, just after the target name."); return true; @@ -163,7 +164,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( this->CurrentProcessingState != ProcessingPlainPrivateInterface && this->CurrentProcessingState != ProcessingPlainPublicInterface) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The LINK_PUBLIC or LINK_PRIVATE option must appear as the second " "argument, just after the target name."); return true; @@ -175,7 +176,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( this->CurrentProcessingState != ProcessingKeywordPublicInterface && this->CurrentProcessingState != ProcessingKeywordLinkInterface) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The INTERFACE, PUBLIC or PRIVATE option must appear as the second " "argument, just after the target name."); return true; @@ -186,7 +187,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( this->CurrentProcessingState != ProcessingPlainPublicInterface && this->CurrentProcessingState != ProcessingPlainPrivateInterface) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The LINK_PUBLIC or LINK_PRIVATE option must appear as the second " "argument, just after the target name."); return true; @@ -198,7 +199,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( this->CurrentProcessingState != ProcessingKeywordPublicInterface && this->CurrentProcessingState != ProcessingKeywordLinkInterface) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The INTERFACE, PUBLIC or PRIVATE option must appear as the second " "argument, just after the target name."); return true; @@ -258,7 +259,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( std::ostringstream e; e << "The \"" << cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[llt] << "\" argument must be followed by a library."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); } @@ -290,7 +291,7 @@ void cmTargetLinkLibrariesCommand::LinkLibraryTypeSpecifierWarning(int left, << cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[right] << "\" instead of a library name. " << "The first specifier will be ignored."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, @@ -299,7 +300,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY && this->CurrentProcessingState != ProcessingKeywordLinkInterface) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "INTERFACE library can only be used with the INTERFACE keyword of " "target_link_libraries"); return false; @@ -307,7 +308,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, if (this->Target->IsImported() && this->CurrentProcessingState != ProcessingKeywordLinkInterface) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "IMPORTED library can only be used with the INTERFACE keyword of " "target_link_libraries"); return false; @@ -325,7 +326,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, sig, this->Makefile->GetExecutionContext())) { std::ostringstream e; const char* modal = nullptr; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0023)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0023) << "\n"; @@ -336,7 +337,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: modal = "must"; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (modal) { @@ -355,7 +356,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, ? cmTarget::PlainTLLSignature : cmTarget::KeywordTLLSignature); this->Makefile->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { return false; } } @@ -408,7 +409,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, << this->Target->GetName() << "\" which is not built in this directory.\n" << "This is allowed only when policy CMP0079 is set to NEW."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } @@ -426,7 +427,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, << " may not be linked into another target. One may link only to " "INTERFACE, OBJECT, STATIC or SHARED libraries, or to executables " "with the ENABLE_EXPORTS property set."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } this->Target->AddLinkLibrary(*this->Makefile, lib, libRef, llt); @@ -442,7 +443,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, "which the target was created rather than in this calling " "directory."; /* clang-format on */ - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } // Handle (additional) case where the command was called with PRIVATE / diff --git a/Source/cmTargetLinkOptionsCommand.cxx b/Source/cmTargetLinkOptionsCommand.cxx index d6ed5ae..5366486 100644 --- a/Source/cmTargetLinkOptionsCommand.cxx +++ b/Source/cmTargetLinkOptionsCommand.cxx @@ -7,8 +7,8 @@ #include "cmAlgorithms.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -23,7 +23,7 @@ void cmTargetLinkOptionsCommand::HandleMissingTarget(const std::string& name) std::ostringstream e; e << "Cannot specify link options for target \"" << name << "\" which is not built by this project."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } std::string cmTargetLinkOptionsCommand::Join( diff --git a/Source/cmTargetPropertyComputer.cxx b/Source/cmTargetPropertyComputer.cxx index 06ce0b1..d2c3496 100644 --- a/Source/cmTargetPropertyComputer.cxx +++ b/Source/cmTargetPropertyComputer.cxx @@ -7,10 +7,10 @@ #include <sstream> #include <unordered_set> +#include "cmMessageType.h" #include "cmMessenger.h" #include "cmPolicies.h" #include "cmStateSnapshot.h" -#include "cmake.h" bool cmTargetPropertyComputer::HandleLocationPropertyPolicy( std::string const& tgtName, cmMessenger* messenger, @@ -18,7 +18,7 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy( { std::ostringstream e; const char* modal = nullptr; - cmake::MessageType messageType = cmake::AUTHOR_WARNING; + MessageType messageType = MessageType::AUTHOR_WARNING; switch (context.GetBottom().GetPolicy(cmPolicies::CMP0026)) { case cmPolicies::WARN: e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n"; @@ -29,7 +29,7 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy( case cmPolicies::REQUIRED_IF_USED: case cmPolicies::NEW: modal = "may"; - messageType = cmake::FATAL_ERROR; + messageType = MessageType::FATAL_ERROR; } if (modal) { @@ -41,7 +41,7 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy( messenger->IssueMessage(messageType, e.str(), context); } - return messageType != cmake::FATAL_ERROR; + return messageType != MessageType::FATAL_ERROR; } bool cmTargetPropertyComputer::WhiteListedInterfaceProperty( @@ -65,6 +65,7 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty( builtIns.insert("EXPORT_NAME"); builtIns.insert("IMPORTED"); builtIns.insert("IMPORTED_GLOBAL"); + builtIns.insert("MANUALLY_ADDED_DEPENDENCIES"); builtIns.insert("NAME"); builtIns.insert("TYPE"); } @@ -100,7 +101,7 @@ bool cmTargetPropertyComputer::PassesWhitelist( e << "INTERFACE_LIBRARY targets may only have whitelisted properties. " "The property \"" << prop << "\" is not allowed."; - messenger->IssueMessage(cmake::FATAL_ERROR, e.str(), context); + messenger->IssueMessage(MessageType::FATAL_ERROR, e.str(), context); return false; } return true; diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 7429053..11e288f 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -7,10 +7,10 @@ #include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmPolicies.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cmake.h" class cmExecutionStatus; @@ -34,7 +34,7 @@ void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name) e << "Cannot specify sources for target \"" << name << "\" " "which is not built by this project."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); } std::string cmTargetSourcesCommand::Join( @@ -99,7 +99,7 @@ std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent( case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_IF_USED: this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0076)); break; case cmPolicies::NEW: { @@ -117,7 +117,7 @@ std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent( e << "A private source from a directory other than that of target \"" << tgt->GetName() << "\" has a relative path."; } - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str()); + this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); } return useAbsoluteContent ? absoluteContent : content; diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 796d2df..1e2ddc7 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -7,6 +7,7 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" +#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmOutputConverter.h" #include "cmProperty.h" @@ -121,16 +122,15 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, // Output properties for the test. cmPropertyMap& pm = this->Test->GetProperties(); - if (!pm.empty()) { - os << indent << "set_tests_properties(" << this->Test->GetName() - << " PROPERTIES "; - for (auto const& i : pm) { - os << " " << i.first << " " - << cmOutputConverter::EscapeForCMake( - ge.Parse(i.second.GetValue())->Evaluate(this->LG, config)); - } - os << ")" << std::endl; + os << indent << "set_tests_properties(" << this->Test->GetName() + << " PROPERTIES "; + for (auto const& i : pm) { + os << " " << i.first << " " + << cmOutputConverter::EscapeForCMake( + ge.Parse(i.second.GetValue())->Evaluate(this->LG, config)); } + this->GenerateInternalProperties(os); + os << ")" << std::endl; } void cmTestGenerator::GenerateScriptNoConfig(std::ostream& os, Indent indent) @@ -179,13 +179,37 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent) // Output properties for the test. cmPropertyMap& pm = this->Test->GetProperties(); - if (!pm.empty()) { - fout << indent << "set_tests_properties(" << this->Test->GetName() - << " PROPERTIES "; - for (auto const& i : pm) { - fout << " " << i.first << " " - << cmOutputConverter::EscapeForCMake(i.second.GetValue()); + fout << indent << "set_tests_properties(" << this->Test->GetName() + << " PROPERTIES "; + for (auto const& i : pm) { + fout << " " << i.first << " " + << cmOutputConverter::EscapeForCMake(i.second.GetValue()); + } + this->GenerateInternalProperties(fout); + fout << ")" << std::endl; +} + +void cmTestGenerator::GenerateInternalProperties(std::ostream& os) +{ + cmListFileBacktrace bt = this->Test->GetBacktrace(); + if (bt.Empty()) { + return; + } + + os << " " + << "_BACKTRACE_TRIPLES" + << " \""; + + bool prependTripleSeparator = false; + while (!bt.Empty()) { + const auto& entry = bt.Top(); + if (prependTripleSeparator) { + os << ";"; } - fout << ")" << std::endl; + os << entry.FilePath << ";" << entry.Line << ";" << entry.Name; + bt = bt.Pop(); + prependTripleSeparator = true; } + + os << "\""; } diff --git a/Source/cmTestGenerator.h b/Source/cmTestGenerator.h index 73d05a3..f26d2ff 100644 --- a/Source/cmTestGenerator.h +++ b/Source/cmTestGenerator.h @@ -35,6 +35,9 @@ public: cmTest* GetTest() const; +private: + void GenerateInternalProperties(std::ostream& os); + protected: void GenerateScriptConfigs(std::ostream& os, Indent indent) override; void GenerateScriptActions(std::ostream& os, Indent indent) override; diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index 3ff84ce..05b3f05 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -3,6 +3,7 @@ #include "cmTryCompileCommand.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmake.h" class cmExecutionStatus; @@ -18,7 +19,7 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& argv, if (this->Makefile->GetCMakeInstance()->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The TRY_COMPILE() command is not supported in --find-package mode."); return false; } diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index fafbd24..e224a27 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -7,6 +7,7 @@ #include "cmDuration.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" @@ -25,7 +26,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, if (this->Makefile->GetCMakeInstance()->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) { this->Makefile->IssueMessage( - cmake::FATAL_ERROR, + MessageType::FATAL_ERROR, "The TRY_RUN() command is not supported in --find-package mode."); return false; } diff --git a/Source/cmUVHandlePtr.h b/Source/cmUVHandlePtr.h index 2937e0d..73ee334 100644 --- a/Source/cmUVHandlePtr.h +++ b/Source/cmUVHandlePtr.h @@ -3,7 +3,6 @@ #pragma once #include "cmConfigure.h" // IWYU pragma: keep -#include <algorithm> #include <cstddef> #include <cstdint> #include <memory> @@ -11,12 +10,22 @@ #include "cm_uv.h" -#define CM_PERFECT_FWD_CTOR(Class, FwdTo) \ - template <typename... Args> \ - Class(Args&&... args) \ - : FwdTo(std::forward<Args>(args)...) \ - { \ - } +#if defined(__SUNPRO_CC) + +# include <utility> + +# define CM_INHERIT_CTOR(Class, Base, Tpl) \ + template <typename... Args> \ + Class(Args&&... args) \ + : Base Tpl(std::forward<Args>(args)...) \ + { \ + } + +#else + +# define CM_INHERIT_CTOR(Class, Base, Tpl) using Base Tpl ::Base; + +#endif namespace cm { @@ -116,7 +125,7 @@ class uv_handle_ptr_ : public uv_handle_ptr_base_<T> friend class uv_handle_ptr_; public: - CM_PERFECT_FWD_CTOR(uv_handle_ptr_, uv_handle_ptr_base_<T>); + CM_INHERIT_CTOR(uv_handle_ptr_, uv_handle_ptr_base_, <T>); /*** * Allow less verbose calling of uv_<T> functions @@ -133,13 +142,13 @@ template <> class uv_handle_ptr_<uv_handle_t> : public uv_handle_ptr_base_<uv_handle_t> { public: - CM_PERFECT_FWD_CTOR(uv_handle_ptr_, uv_handle_ptr_base_<uv_handle_t>); + CM_INHERIT_CTOR(uv_handle_ptr_, uv_handle_ptr_base_, <uv_handle_t>); }; class uv_async_ptr : public uv_handle_ptr_<uv_async_t> { public: - CM_PERFECT_FWD_CTOR(uv_async_ptr, uv_handle_ptr_<uv_async_t>); + CM_INHERIT_CTOR(uv_async_ptr, uv_handle_ptr_, <uv_async_t>); int init(uv_loop_t& loop, uv_async_cb async_cb, void* data = nullptr); @@ -148,7 +157,7 @@ public: struct uv_signal_ptr : public uv_handle_ptr_<uv_signal_t> { - CM_PERFECT_FWD_CTOR(uv_signal_ptr, uv_handle_ptr_<uv_signal_t>); + CM_INHERIT_CTOR(uv_signal_ptr, uv_handle_ptr_, <uv_signal_t>); int init(uv_loop_t& loop, void* data = nullptr); @@ -159,7 +168,7 @@ struct uv_signal_ptr : public uv_handle_ptr_<uv_signal_t> struct uv_pipe_ptr : public uv_handle_ptr_<uv_pipe_t> { - CM_PERFECT_FWD_CTOR(uv_pipe_ptr, uv_handle_ptr_<uv_pipe_t>); + CM_INHERIT_CTOR(uv_pipe_ptr, uv_handle_ptr_, <uv_pipe_t>); operator uv_stream_t*() const; @@ -168,7 +177,7 @@ struct uv_pipe_ptr : public uv_handle_ptr_<uv_pipe_t> struct uv_process_ptr : public uv_handle_ptr_<uv_process_t> { - CM_PERFECT_FWD_CTOR(uv_process_ptr, uv_handle_ptr_<uv_process_t>); + CM_INHERIT_CTOR(uv_process_ptr, uv_handle_ptr_, <uv_process_t>); int spawn(uv_loop_t& loop, uv_process_options_t const& options, void* data = nullptr); @@ -176,7 +185,7 @@ struct uv_process_ptr : public uv_handle_ptr_<uv_process_t> struct uv_timer_ptr : public uv_handle_ptr_<uv_timer_t> { - CM_PERFECT_FWD_CTOR(uv_timer_ptr, uv_handle_ptr_<uv_timer_t>); + CM_INHERIT_CTOR(uv_timer_ptr, uv_handle_ptr_, <uv_timer_t>); int init(uv_loop_t& loop, void* data = nullptr); @@ -185,7 +194,7 @@ struct uv_timer_ptr : public uv_handle_ptr_<uv_timer_t> struct uv_tty_ptr : public uv_handle_ptr_<uv_tty_t> { - CM_PERFECT_FWD_CTOR(uv_tty_ptr, uv_handle_ptr_<uv_tty_t>); + CM_INHERIT_CTOR(uv_tty_ptr, uv_handle_ptr_, <uv_tty_t>); operator uv_stream_t*() const; diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx index 7a54e12..9187c29 100644 --- a/Source/cmVSSetupHelper.cxx +++ b/Source/cmVSSetupHelper.cxx @@ -57,8 +57,9 @@ std::string VSInstanceInfo::GetInstallLocation() const return loc; } -cmVSSetupAPIHelper::cmVSSetupAPIHelper() - : setupConfig(NULL) +cmVSSetupAPIHelper::cmVSSetupAPIHelper(unsigned int version) + : Version(version) + , setupConfig(NULL) , setupConfig2(NULL) , setupHelper(NULL) , initializationFailure(false) @@ -88,7 +89,7 @@ bool cmVSSetupAPIHelper::SetVSInstance(std::string const& vsInstallLocation) return this->EnumerateAndChooseVSInstance(); } -bool cmVSSetupAPIHelper::IsVS2017Installed() +bool cmVSSetupAPIHelper::IsVSInstalled() { return this->EnumerateAndChooseVSInstance(); } @@ -312,11 +313,11 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() return false; std::string envVSCommonToolsDir; + std::string envVSCommonToolsDirEnvName = + "VS" + std::to_string(this->Version) + "0COMNTOOLS"; - // FIXME: When we support VS versions beyond 2017, the version - // to choose will be passed in by the caller. We need to map that - // to a per-version name of this environment variable. - if (cmSystemTools::GetEnv("VS150COMNTOOLS", envVSCommonToolsDir)) { + if (cmSystemTools::GetEnv(envVSCommonToolsDirEnvName.c_str(), + envVSCommonToolsDir)) { cmSystemTools::ConvertToUnixSlashes(envVSCommonToolsDir); } @@ -328,6 +329,8 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() return false; } + std::wstring const wantVersion = std::to_wstring(this->Version) + L'.'; + SmartCOMPtr<ISetupInstance> instance; while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) { SmartCOMPtr<ISetupInstance2> instance2 = NULL; @@ -343,6 +346,12 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() instance = instance2 = NULL; if (isInstalled) { + // We are looking for a specific major version. + if (instanceInfo.Version.size() < wantVersion.size() || + instanceInfo.Version.substr(0, wantVersion.size()) != wantVersion) { + continue; + } + if (!this->SpecifiedVSInstallLocation.empty()) { // We are looking for a specific instance. std::string currentVSLocation = instanceInfo.GetInstallLocation(); diff --git a/Source/cmVSSetupHelper.h b/Source/cmVSSetupHelper.h index b9cca45..4748a7a 100644 --- a/Source/cmVSSetupHelper.h +++ b/Source/cmVSSetupHelper.h @@ -120,12 +120,12 @@ struct VSInstanceInfo class cmVSSetupAPIHelper { public: - cmVSSetupAPIHelper(); + cmVSSetupAPIHelper(unsigned int version); ~cmVSSetupAPIHelper(); bool SetVSInstance(std::string const& vsInstallLocation); - bool IsVS2017Installed(); + bool IsVSInstalled(); bool GetVSInstanceInfo(std::string& vsInstallLocation); bool GetVCToolsetVersion(std::string& vsToolsetVersion); bool IsWin10SDKInstalled(); @@ -140,6 +140,8 @@ private: int ChooseVSInstance(const std::vector<VSInstanceInfo>& vecVSInstances); bool EnumerateAndChooseVSInstance(); + unsigned int Version; + // COM ptrs to query about VS instances SmartCOMPtr<ISetupConfiguration> setupConfig; SmartCOMPtr<ISetupConfiguration2> setupConfig2; diff --git a/Source/cmVariableWatch.h b/Source/cmVariableWatch.h index 27d1b12..2f444ed 100644 --- a/Source/cmVariableWatch.h +++ b/Source/cmVariableWatch.h @@ -63,15 +63,10 @@ public: protected: struct Pair { - WatchMethod Method; - void* ClientData; - DeleteData DeleteDataCall; - Pair() - : Method(nullptr) - , ClientData(nullptr) - , DeleteDataCall(nullptr) - { - } + WatchMethod Method = nullptr; + void* ClientData = nullptr; + DeleteData DeleteDataCall = nullptr; + Pair() {} ~Pair() { if (this->DeleteDataCall && this->ClientData) { diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx index e080df1..03e0059 100644 --- a/Source/cmVariableWatchCommand.cxx +++ b/Source/cmVariableWatchCommand.cxx @@ -7,6 +7,7 @@ #include "cmExecutionStatus.h" #include "cmListFileCache.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" #include "cmVariableWatch.h" #include "cmake.h" @@ -70,7 +71,7 @@ static void cmVariableWatchCommandVariableAccessed(const std::string& variable, msg << "Variable \"" << variable << "\" was accessed using " << accessString << " with value \"" << (newValue ? newValue : "") << "\"."; - makefile->IssueMessage(cmake::LOG, msg.str()); + makefile->IssueMessage(MessageType::LOG, msg.str()); } data->InCallback = false; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 6d54c12..dd90269 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -6,6 +6,7 @@ #include "cmComputeLinkInformation.h" #include "cmCustomCommandGenerator.h" #include "cmGeneratedFileStream.h" +#include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalVisualStudio10Generator.h" #include "cmLocalVisualStudio10Generator.h" @@ -297,6 +298,11 @@ std::ostream& cmVisualStudio10TargetGenerator::Elem::WriteString( "$(UserRootDir)\\Microsoft.CSharp.$(Platform).user.props" #define VS10_CSharp_TARGETS "$(MSBuildToolsPath)\\Microsoft.CSharp.targets" +#define VS10_CSharp_NETCF_TARGETS \ + "$(MSBuildExtensionsPath)\\Microsoft\\$(TargetFrameworkIdentifier)\\" \ + "$(TargetFrameworkTargetsVersion)\\Microsoft.$(TargetFrameworkIdentifier)" \ + ".CSharp.targets" + void cmVisualStudio10TargetGenerator::Generate() { // do not generate external ms projects @@ -315,8 +321,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->GetName() + "\" is of type STATIC_LIBRARY. This is discouraged (and may be " "disabled in future). Make it a SHARED library instead."; - this->Makefile->IssueMessage(cmake::MessageType::DEPRECATION_WARNING, - message); + this->Makefile->IssueMessage(MessageType::DEPRECATION_WARNING, message); } this->ProjectType = csproj; this->Managed = true; @@ -480,9 +485,31 @@ void cmVisualStudio10TargetGenerator::Generate() targetFrameworkVersion = this->GeneratorTarget->GetProperty( "DOTNET_TARGET_FRAMEWORK_VERSION"); } + if (!targetFrameworkVersion && this->ProjectType == csproj && + this->GlobalGenerator->TargetsWindowsCE() && + this->GlobalGenerator->GetVersion() == + cmGlobalVisualStudioGenerator::VS12) { + // VS12 .NETCF default to .NET framework 3.9 + targetFrameworkVersion = "v3.9"; + } if (targetFrameworkVersion) { e1.Element("TargetFrameworkVersion", targetFrameworkVersion); } + if (this->ProjectType == csproj && + this->GlobalGenerator->TargetsWindowsCE()) { + const char* targetFrameworkId = this->GeneratorTarget->GetProperty( + "VS_TARGET_FRAMEWORK_IDENTIFIER"); + if (!targetFrameworkId) { + targetFrameworkId = "WindowsEmbeddedCompact"; + } + e1.Element("TargetFrameworkIdentifier", targetFrameworkId); + const char* targetFrameworkVer = this->GeneratorTarget->GetProperty( + "VS_TARGET_FRAMEWORKS_TARGET_VERSION"); + if (!targetFrameworkVer) { + targetFrameworkVer = "v8.0"; + } + e1.Element("TargetFrameworkTargetsVersion", targetFrameworkVer); + } } // Disable the project upgrade prompt that is displayed the first time a @@ -623,6 +650,7 @@ void cmVisualStudio10TargetGenerator::Generate() Elem(e0, "PropertyGroup").Attribute("Label", "UserMacros"); this->WriteWinRTPackageCertificateKeyFile(e0); this->WritePathAndIncrementalLinkOptions(e0); + this->WriteCEDebugProjectConfigurationValues(e0); this->WriteItemDefinitionGroups(e0); this->WriteCustomCommands(e0); this->WriteAllSources(e0); @@ -637,7 +665,11 @@ void cmVisualStudio10TargetGenerator::Generate() Elem(e0, "Import").Attribute("Project", VS10_CXX_TARGETS); break; case csproj: - Elem(e0, "Import").Attribute("Project", VS10_CSharp_TARGETS); + if (this->GlobalGenerator->TargetsWindowsCE()) { + Elem(e0, "Import").Attribute("Project", VS10_CSharp_NETCF_TARGETS); + } else { + Elem(e0, "Import").Attribute("Project", VS10_CSharp_TARGETS); + } break; } @@ -1071,6 +1103,32 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) } } +void cmVisualStudio10TargetGenerator::WriteCEDebugProjectConfigurationValues( + Elem& e0) +{ + if (!this->GlobalGenerator->TargetsWindowsCE()) { + return; + } + const char* additionalFiles = + this->GeneratorTarget->GetProperty("DEPLOYMENT_ADDITIONAL_FILES"); + const char* remoteDirectory = + this->GeneratorTarget->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY"); + if (!(additionalFiles || remoteDirectory)) { + return; + } + for (std::string const& c : this->Configurations) { + Elem e1(e0, "PropertyGroup"); + e1.Attribute("Condition", this->CalcCondition(c)); + + if (remoteDirectory) { + e1.Element("RemoteDirectory", remoteDirectory); + } + if (additionalFiles) { + e1.Element("CEAdditionalFiles", additionalFiles); + } + } +} + void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues( Elem& e1, std::string const& config) { @@ -1392,6 +1450,14 @@ void cmVisualStudio10TargetGenerator::WriteGroups() groupsUsed.insert(sourceGroup); } + if (cmSourceFile const* srcCMakeLists = + this->LocalGenerator->CreateVCProjBuildRule()) { + std::string const& source = srcCMakeLists->GetFullPath(); + cmSourceGroup* sourceGroup = + this->Makefile->FindSourceGroup(source, sourceGroups); + groupsUsed.insert(sourceGroup); + } + this->AddMissingSourceGroups(groupsUsed, sourceGroups); // Write out group file @@ -2524,7 +2590,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( "\" the /clr compiler flag was added manually. " + "Set usage of C++/CLI by setting COMMON_LANGUAGE_RUNTIME " "target property."; - this->Makefile->IssueMessage(cmake::MessageType::WARNING, message); + this->Makefile->IssueMessage(MessageType::WARNING, message); } } if (auto* clr = diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index b17b5f8..7d24e88 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -57,6 +57,7 @@ private: void WriteProjectConfigurations(Elem& e0); void WriteProjectConfigurationValues(Elem& e0); void WriteMSToolConfigurationValues(Elem& e1, std::string const& config); + void WriteCEDebugProjectConfigurationValues(Elem& e0); void WriteMSToolConfigurationValuesManaged(Elem& e1, std::string const& config); void WriteHeaderSource(Elem& e1, cmSourceFile const* sf); diff --git a/Source/cmVisualStudio10ToolsetOptions.cxx b/Source/cmVisualStudio10ToolsetOptions.cxx index f71b8b7..39063ed 100644 --- a/Source/cmVisualStudio10ToolsetOptions.cxx +++ b/Source/cmVisualStudio10ToolsetOptions.cxx @@ -7,8 +7,7 @@ #include "cmVisualStudioGeneratorOptions.h" std::string cmVisualStudio10ToolsetOptions::GetClFlagTableName( - std::string const& name, std::string const& toolset, - std::string const& defaultToolset) const + std::string const& name, std::string const& toolset) const { std::string const useToolset = this->GetToolsetName(name, toolset); @@ -23,13 +22,12 @@ std::string cmVisualStudio10ToolsetOptions::GetClFlagTableName( } else if (useToolset == "v100") { return "v10"; } else { - return this->GetToolsetName(name, defaultToolset); + return ""; } } std::string cmVisualStudio10ToolsetOptions::GetCSharpFlagTableName( - std::string const& name, std::string const& toolset, - std::string const& defaultToolset) const + std::string const& name, std::string const& toolset) const { std::string const useToolset = this->GetToolsetName(name, toolset); @@ -44,13 +42,12 @@ std::string cmVisualStudio10ToolsetOptions::GetCSharpFlagTableName( } else if (useToolset == "v100") { return "v10"; } else { - return this->GetToolsetName(name, defaultToolset); + return ""; } } std::string cmVisualStudio10ToolsetOptions::GetRcFlagTableName( - std::string const& name, std::string const& toolset, - std::string const& defaultToolset) const + std::string const& name, std::string const& toolset) const { std::string const useToolset = this->GetToolsetName(name, toolset); @@ -63,13 +60,12 @@ std::string cmVisualStudio10ToolsetOptions::GetRcFlagTableName( } else if (useToolset == "v100") { return "v10"; } else { - return this->GetToolsetName(name, defaultToolset); + return ""; } } std::string cmVisualStudio10ToolsetOptions::GetLibFlagTableName( - std::string const& name, std::string const& toolset, - std::string const& defaultToolset) const + std::string const& name, std::string const& toolset) const { std::string const useToolset = this->GetToolsetName(name, toolset); @@ -82,13 +78,12 @@ std::string cmVisualStudio10ToolsetOptions::GetLibFlagTableName( } else if (useToolset == "v100") { return "v10"; } else { - return this->GetToolsetName(name, defaultToolset); + return ""; } } std::string cmVisualStudio10ToolsetOptions::GetLinkFlagTableName( - std::string const& name, std::string const& toolset, - std::string const& defaultToolset) const + std::string const& name, std::string const& toolset) const { std::string const useToolset = this->GetToolsetName(name, toolset); @@ -103,13 +98,12 @@ std::string cmVisualStudio10ToolsetOptions::GetLinkFlagTableName( } else if (useToolset == "v100") { return "v10"; } else { - return this->GetToolsetName(name, defaultToolset); + return ""; } } std::string cmVisualStudio10ToolsetOptions::GetMasmFlagTableName( - std::string const& name, std::string const& toolset, - std::string const& defaultToolset) const + std::string const& name, std::string const& toolset) const { std::string const useToolset = this->GetToolsetName(name, toolset); @@ -122,7 +116,7 @@ std::string cmVisualStudio10ToolsetOptions::GetMasmFlagTableName( } else if (useToolset == "v100") { return "v10"; } else { - return this->GetToolsetName(name, defaultToolset); + return ""; } } diff --git a/Source/cmVisualStudio10ToolsetOptions.h b/Source/cmVisualStudio10ToolsetOptions.h index 43946f0..875a35b 100644 --- a/Source/cmVisualStudio10ToolsetOptions.h +++ b/Source/cmVisualStudio10ToolsetOptions.h @@ -16,25 +16,17 @@ class cmVisualStudio10ToolsetOptions { public: std::string GetClFlagTableName(std::string const& name, - std::string const& toolset, - std::string const& defaultToolset) const; + std::string const& toolset) const; std::string GetCSharpFlagTableName(std::string const& name, - std::string const& toolset, - std::string const& defaultToolset) const; + std::string const& toolset) const; std::string GetRcFlagTableName(std::string const& name, - std::string const& toolset, - std::string const& defaultToolset) const; + std::string const& toolset) const; std::string GetLibFlagTableName(std::string const& name, - std::string const& toolset, - std::string const& defaultToolset) const; + std::string const& toolset) const; std::string GetLinkFlagTableName(std::string const& name, - std::string const& toolset, - std::string const& defaultToolset) const; + std::string const& toolset) const; std::string GetMasmFlagTableName(std::string const& name, - std::string const& toolset, - std::string const& defaultToolset) const; - -private: + std::string const& toolset) const; std::string GetToolsetName(std::string const& name, std::string const& toolset) const; }; diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 5d67dcf..5c3e533 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -70,6 +70,7 @@ void cmVisualStudioGeneratorOptions::FixExceptionHandlingDefault() case cmGlobalVisualStudioGenerator::VS12: case cmGlobalVisualStudioGenerator::VS14: case cmGlobalVisualStudioGenerator::VS15: + case cmGlobalVisualStudioGenerator::VS16: // by default VS puts <ExceptionHandling></ExceptionHandling> empty // for a project, to make our projects look the same put a new line // and space over for the closing </ExceptionHandling> as the default @@ -269,7 +270,7 @@ void cmVisualStudioGeneratorOptions::FixManifestUACFlags() if (keyValue[1].front() == '\'' && keyValue[1].back() == '\'') { keyValue[1] = - keyValue[1].substr(1, std::max<int>(0, keyValue[1].size() - 2)); + keyValue[1].substr(1, std::max(0, cm::isize(keyValue[1]) - 2)); } if (keyValue[0] == "level") { diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index 9d43d19..a01fa6f 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -6,8 +6,8 @@ #include "cmExecutionStatus.h" #include "cmExpandedCommandArgument.h" #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmSystemTools.h" -#include "cmake.h" #include <memory> // IWYU pragma: keep @@ -45,7 +45,7 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, std::vector<cmExpandedCommandArgument> expandedArguments; mf.ExpandArguments(this->Args, expandedArguments); - cmake::MessageType messageType; + MessageType messageType; cmListFileContext execContext = this->GetStartingContext(); @@ -72,7 +72,7 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, err += errorString; err += ")."; mf.IssueMessage(messageType, err); - if (messageType == cmake::FATAL_ERROR) { + if (messageType == MessageType::FATAL_ERROR) { cmSystemTools::SetFatalErrorOccured(); return true; } diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx index c504ef4..49dbf1a 100644 --- a/Source/cmWriteFileCommand.cxx +++ b/Source/cmWriteFileCommand.cxx @@ -50,7 +50,7 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args, // Set permissions to writable if (cmSystemTools::GetPermissions(fileName.c_str(), mode)) { #if defined(_MSC_VER) || defined(__MINGW32__) - writable = mode & S_IWRITE; + writable = (mode & S_IWRITE) != 0; mode_t newMode = mode | S_IWRITE; #else writable = mode & S_IWUSR; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index e81d14b..c65bd2e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -55,8 +55,8 @@ # include "cmGlobalVisualStudio11Generator.h" # include "cmGlobalVisualStudio12Generator.h" # include "cmGlobalVisualStudio14Generator.h" -# include "cmGlobalVisualStudio15Generator.h" # include "cmGlobalVisualStudio9Generator.h" +# include "cmGlobalVisualStudioVersionedGenerator.h" # include "cmVSSetupHelper.h" # define CMAKE_HAVE_VS_GENERATORS @@ -141,7 +141,7 @@ cmake::cmake(Role role) this->State = new cmState; this->CurrentSnapshot = this->State->CreateBaseSnapshot(); - this->Messenger = new cmMessenger(this->State); + this->Messenger = new cmMessenger; #ifdef __APPLE__ struct rlimit rlp; @@ -610,16 +610,13 @@ bool cmake::FindPackage(const std::vector<std::string>& args) } // Parse the args -void cmake::SetArgs(const std::vector<std::string>& args, - bool directoriesSetBefore) +void cmake::SetArgs(const std::vector<std::string>& args) { - bool directoriesSet = directoriesSetBefore; bool haveToolset = false; bool havePlatform = false; for (unsigned int i = 1; i < args.size(); ++i) { std::string const& arg = args[i]; if (arg.find("-H", 0) == 0 || arg.find("-S", 0) == 0) { - directoriesSet = true; std::string path = arg.substr(2); if (path.empty()) { ++i; @@ -640,7 +637,6 @@ void cmake::SetArgs(const std::vector<std::string>& args, } else if (arg.find("-O", 0) == 0) { // There is no local generate anymore. Ignore -O option. } else if (arg.find("-B", 0) == 0) { - directoriesSet = true; std::string path = arg.substr(2); if (path.empty()) { ++i; @@ -802,16 +798,27 @@ void cmake::SetArgs(const std::vector<std::string>& args, this->SetGlobalGenerator(gen); } } - // no option assume it is the path to the source + // no option assume it is the path to the source or an existing build else { - directoriesSet = true; this->SetDirectoriesFromFile(arg.c_str()); } } - if (!directoriesSet) { - this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory()); + + const bool haveSourceDir = !this->GetHomeDirectory().empty(); + const bool haveBinaryDir = !this->GetHomeOutputDirectory().empty(); + + if (this->CurrentWorkingMode == cmake::NORMAL_MODE && !haveSourceDir && + !haveBinaryDir) { + cmSystemTools::Error("No source or binary directory provided"); + return; + } + + if (!haveSourceDir) { this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory()); } + if (!haveBinaryDir) { + this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory()); + } } void cmake::SetDirectoriesFromFile(const char* arg) @@ -1300,6 +1307,23 @@ int cmake::Configure() } } + // Cache variables may have already been set by a previous invocation, + // so we cannot rely on command line options alone. Always ensure our + // messenger is in sync with the cache. + const char* value = this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED"); + this->Messenger->SetSuppressDeprecatedWarnings(value && + cmSystemTools::IsOff(value)); + + value = this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED"); + this->Messenger->SetDeprecatedWarningsAsErrors(cmSystemTools::IsOn(value)); + + value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"); + this->Messenger->SetSuppressDevWarnings(cmSystemTools::IsOn(value)); + + value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS"); + this->Messenger->SetDevWarningsAsErrors(value && + cmSystemTools::IsOff(value)); + int ret = this->ActualConfigure(); const char* delCacheVars = this->State->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_"); @@ -1511,7 +1535,6 @@ void cmake::CreateDefaultGlobalGenerator() const char* GeneratorName; }; static VSVersionedGenerator const vsGenerators[] = { - { "15.0", "Visual Studio 15 2017" }, // { "14.0", "Visual Studio 14 2015" }, // { "12.0", "Visual Studio 12 2013" }, // { "11.0", "Visual Studio 11 2012" }, // @@ -1522,8 +1545,9 @@ void cmake::CreateDefaultGlobalGenerator() "\\Setup\\VC;ProductDir", // ";InstallDir" // }; - cmVSSetupAPIHelper vsSetupAPIHelper; - if (vsSetupAPIHelper.IsVS2017Installed()) { + if (cmVSSetupAPIHelper(16).IsVSInstalled()) { + found = "Visual Studio 16 2019"; + } else if (cmVSSetupAPIHelper(15).IsVSInstalled()) { found = "Visual Studio 15 2017"; } else { for (VSVersionedGenerator const* g = cm::cbegin(vsGenerators); @@ -1701,6 +1725,18 @@ void cmake::AddCacheEntry(const std::string& key, const char* value, this->State->AddCacheEntry(key, value, helpString, cmStateEnums::CacheEntryType(type)); this->UnwatchUnusedCli(key); + + if (key == "CMAKE_WARN_DEPRECATED") { + this->Messenger->SetSuppressDeprecatedWarnings( + value && cmSystemTools::IsOff(value)); + } else if (key == "CMAKE_ERROR_DEPRECATED") { + this->Messenger->SetDeprecatedWarningsAsErrors(cmSystemTools::IsOn(value)); + } else if (key == "CMAKE_SUPPRESS_DEVELOPER_WARNINGS") { + this->Messenger->SetSuppressDevWarnings(cmSystemTools::IsOn(value)); + } else if (key == "CMAKE_SUPPRESS_DEVELOPER_ERRORS") { + this->Messenger->SetDevWarningsAsErrors(value && + cmSystemTools::IsOff(value)); + } } bool cmake::DoWriteGlobVerifyTarget() const @@ -1765,7 +1801,10 @@ void cmake::AddDefaultGenerators() { #if defined(_WIN32) && !defined(__CYGWIN__) # if !defined(CMAKE_BOOT_MINGW) - this->Generators.push_back(cmGlobalVisualStudio15Generator::NewFactory()); + this->Generators.push_back( + cmGlobalVisualStudioVersionedGenerator::NewFactory16()); + this->Generators.push_back( + cmGlobalVisualStudioVersionedGenerator::NewFactory15()); this->Generators.push_back(cmGlobalVisualStudio14Generator::NewFactory()); this->Generators.push_back(cmGlobalVisualStudio12Generator::NewFactory()); this->Generators.push_back(cmGlobalVisualStudio11Generator::NewFactory()); @@ -2426,7 +2465,7 @@ static bool cmakeCheckStampList(const char* stampList, bool verbose) return true; } -void cmake::IssueMessage(cmake::MessageType t, std::string const& text, +void cmake::IssueMessage(MessageType t, std::string const& text, cmListFileBacktrace const& backtrace) const { this->Messenger->IssueMessage(t, text, backtrace); @@ -2653,7 +2692,7 @@ void cmake::RunCheckForUnusedVariables() } } if (haveUnused) { - this->IssueMessage(cmake::WARNING, msg.str()); + this->IssueMessage(MessageType::WARNING, msg.str()); } #endif } diff --git a/Source/cmake.h b/Source/cmake.h index d00acc7..9891857 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -14,6 +14,7 @@ #include "cmInstalledFile.h" #include "cmListFileCache.h" +#include "cmMessageType.h" #include "cmStateSnapshot.h" #include "cmStateTypes.h" @@ -68,19 +69,6 @@ public: RoleProject // all commands }; - enum MessageType - { - AUTHOR_WARNING, - AUTHOR_ERROR, - FATAL_ERROR, - INTERNAL_ERROR, - MESSAGE, - WARNING, - LOG, - DEPRECATION_ERROR, - DEPRECATION_WARNING - }; - enum DiagLevel { DIAG_IGNORE, @@ -277,8 +265,7 @@ public: int GetSystemInformation(std::vector<std::string>&); ///! Parse command line arguments - void SetArgs(const std::vector<std::string>&, - bool directoriesSetBefore = false); + void SetArgs(const std::vector<std::string>& args); ///! Is this cmake running as a result of a TRY_COMPILE command bool GetIsInTryCompile() const; @@ -434,7 +421,7 @@ public: /** Display a message to the user. */ void IssueMessage( - cmake::MessageType t, std::string const& text, + MessageType t, std::string const& text, cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const; ///! run the --build option @@ -550,13 +537,13 @@ private: * Convert a message type between a warning and an error, based on the state * of the error output CMake variables, in the cache. */ - cmake::MessageType ConvertMessageType(cmake::MessageType t) const; + MessageType ConvertMessageType(MessageType t) const; /* * Check if messages of this type should be output, based on the state of the * warning and error output CMake variables, in the cache. */ - bool IsMessageTypeVisible(cmake::MessageType t) const; + bool IsMessageTypeVisible(MessageType t) const; }; #define CMAKE_STANDARD_OPTIONS_TABLE \ diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 75dabde..e52f2b3 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -285,12 +285,12 @@ int do_cmake(int ac, char const* const* av) } else if (cmHasLiteralPrefix(av[i], "-P")) { if (i == ac - 1) { cmSystemTools::Error("No script specified for argument -P"); - } else { - workingMode = cmake::SCRIPT_MODE; - args.push_back(av[i]); - i++; - args.push_back(av[i]); + return 1; } + workingMode = cmake::SCRIPT_MODE; + args.push_back(av[i]); + i++; + args.push_back(av[i]); } else if (cmHasLiteralPrefix(av[i], "--find-package")) { workingMode = cmake::FIND_PACKAGE_MODE; args.push_back(av[i]); diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 930ced9..b645ef1 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -44,6 +44,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <utility> class cmConnection; @@ -270,9 +271,12 @@ static int HandleCppLint(const std::string& runCmd, << "\n"; return 1; } - std::cerr << "Warning: cpplint diagnostics:\n"; - // Output the output from cpplint to stderr - std::cerr << stdOut; + if (!stdOut.empty()) { + std::cerr << "Warning: cpplint diagnostics:\n"; + // Output the output from cpplint to stderr + std::cerr << stdOut; + } + // always return 0 so the build can continue as cpplint returns non-zero // for any warning return 0; @@ -1017,7 +1021,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) std::string config; if (args.size() > 3) { config = args[3]; - }; + } return autoGen.Run(infoFile, config) ? 0 : 1; } #endif @@ -1481,7 +1485,7 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string>& args) break; default: break; - }; + } } // Free the process instance. diff --git a/Source/cmparseMSBuildXML.py b/Source/cmparseMSBuildXML.py deleted file mode 100755 index 1b38d15..0000000 --- a/Source/cmparseMSBuildXML.py +++ /dev/null @@ -1,341 +0,0 @@ -# This python script parses the spec files from MSBuild to create -# mappings from compiler options to IDE XML specifications. For -# more information see here: - -# http://blogs.msdn.com/vcblog/archive/2008/12/16/msbuild-task.aspx -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/1033/cl.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/1033/lib.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/1033/link.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V110/1033/cl.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V110/1033/lib.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V110/1033/link.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/v120/1033/cl.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/v120/1033/lib.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/v120/1033/link.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V140/1033/cl.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V140/1033/lib.xml" -# "${PROGRAMFILES}/MSBuild/Microsoft.Cpp/v4.0/V140/1033/link.xml" -# "${PROGRAMFILES}/Microsoft Visual Studio/VS15Preview/Common7/IDE/VC/VCTargets/1033/cl.xml" -# "${PROGRAMFILES}/Microsoft Visual Studio/VS15Preview/Common7/IDE/VC/VCTargets/1033/lib.xml" -# "${PROGRAMFILES}/Microsoft Visual Studio/VS15Preview/Common7/IDE/VC/VCTargets/1033/link.xml" -# -# BoolProperty <Name>true|false</Name> -# simple example: -# <BoolProperty ReverseSwitch="Oy-" Name="OmitFramePointers" -# Category="Optimization" Switch="Oy"> -# <BoolProperty.DisplayName> <BoolProperty.Description> -# <CLCompile> -# <OmitFramePointers>true</OmitFramePointers> -# </ClCompile> -# -# argument means it might be this: /MP3 -# example with argument: -# <BoolProperty Name="MultiProcessorCompilation" Category="General" Switch="MP"> -# <BoolProperty.DisplayName> -# <sys:String>Multi-processor Compilation</sys:String> -# </BoolProperty.DisplayName> -# <BoolProperty.Description> -# <sys:String>Multi-processor Compilation</sys:String> -# </BoolProperty.Description> -# <Argument Property="ProcessorNumber" IsRequired="false" /> -# </BoolProperty> -# <CLCompile> -# <MultiProcessorCompilation>true</MultiProcessorCompilation> -# <ProcessorNumber>4</ProcessorNumber> -# </ClCompile> -# IntProperty -# not used AFIT -# <IntProperty Name="ProcessorNumber" Category="General" Visible="false"> - - -# per config options example -# <EnableFiberSafeOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</EnableFiberSafeOptimizations> -# -# EnumProperty -# <EnumProperty Name="Optimization" Category="Optimization"> -# <EnumProperty.DisplayName> -# <sys:String>Optimization</sys:String> -# </EnumProperty.DisplayName> -# <EnumProperty.Description> -# <sys:String>Select option for code optimization; choose Custom to use specific optimization options. (/Od, /O1, /O2, /Ox)</sys:String> -# </EnumProperty.Description> -# <EnumValue Name="MaxSpeed" Switch="O2"> -# <EnumValue.DisplayName> -# <sys:String>Maximize Speed</sys:String> -# </EnumValue.DisplayName> -# <EnumValue.Description> -# <sys:String>Equivalent to /Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy</sys:String> -# </EnumValue.Description> -# </EnumValue> -# <EnumValue Name="MinSpace" Switch="O1"> -# <EnumValue.DisplayName> -# <sys:String>Minimize Size</sys:String> -# </EnumValue.DisplayName> -# <EnumValue.Description> -# <sys:String>Equivalent to /Og /Os /Oy /Ob2 /Gs /GF /Gy</sys:String> -# </EnumValue.Description> -# </EnumValue> -# example for O2 would be this: -# <Optimization>MaxSpeed</Optimization> -# example for O1 would be this: -# <Optimization>MinSpace</Optimization> -# -# StringListProperty -# <StringListProperty Name="PreprocessorDefinitions" Category="Preprocessor" Switch="D "> -# <StringListProperty.DisplayName> -# <sys:String>Preprocessor Definitions</sys:String> -# </StringListProperty.DisplayName> -# <StringListProperty.Description> -# <sys:String>Defines a preprocessing symbols for your source file.</sys:String> -# </StringListProperty.Description> -# </StringListProperty> - -# <StringListProperty Subtype="folder" Name="AdditionalIncludeDirectories" Category="General" Switch="I"> -# <StringListProperty.DisplayName> -# <sys:String>Additional Include Directories</sys:String> -# </StringListProperty.DisplayName> -# <StringListProperty.Description> -# <sys:String>Specifies one or more directories to add to the include path; separate with semi-colons if more than one. (/I[path])</sys:String> -# </StringListProperty.Description> -# </StringListProperty> -# StringProperty - -# Example add bill include: - -# <AdditionalIncludeDirectories>..\..\..\..\..\..\bill;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - - -import sys -from xml.dom.minidom import parse, parseString - -def getText(node): - nodelist = node.childNodes - rc = "" - for child in nodelist: - if child.nodeType == child.TEXT_NODE: - rc = rc + child.data - return rc - -def print_tree(document, spaces=""): - for i in range(len(document.childNodes)): - if document.childNodes[i].nodeType == document.childNodes[i].ELEMENT_NODE: - print spaces+str(document.childNodes[i].nodeName ) - print_tree(document.childNodes[i],spaces+"----") - pass - -########################################################################################### -#Data structure that stores a property of MSBuild -class Property: - #type = type of MSBuild property (ex. if the property is EnumProperty type should be "Enum") - #attributeNames = a list of any attributes that this property could have (ex. if this was a EnumProperty it should be ["Name","Category"]) - #document = the dom file that's root node is the Property node (ex. if you were parsing a BoolProperty the root node should be something like <BoolProperty Name="RegisterOutput" Category="General" IncludeInCommandLine="false"> - def __init__(self,type,attributeNames,document=None): - self.suffix_type = "Property" - self.prefix_type = type - self.attributeNames = attributeNames - self.attributes = {} - self.DisplayName = "" - self.Description = "" - self.argumentProperty = "" - self.argumentIsRequired = "" - self.values = [] - if document is not None: - self.populate(document) - pass - - #document = the dom file that's root node is the Property node (ex. if you were parsing a BoolProperty the root node should be something like <BoolProperty Name="RegisterOutput" Category="General" IncludeInCommandLine="false"> - #spaces = do not use - def populate(self,document, spaces = ""): - if document.nodeName == self.prefix_type+self.suffix_type: - for i in self.attributeNames: - self.attributes[i] = document.getAttribute(i) - for i in range(len(document.childNodes)): - child = document.childNodes[i] - if child.nodeType == child.ELEMENT_NODE: - if child.nodeName == self.prefix_type+self.suffix_type+".DisplayName": - self.DisplayName = getText(child.childNodes[1]) - if child.nodeName == self.prefix_type+self.suffix_type+".Description": - self.Description = getText(child.childNodes[1]) - if child.nodeName == "Argument": - self.argumentProperty = child.getAttribute("Property") - self.argumentIsRequired = child.getAttribute("IsRequired") - if child.nodeName == self.prefix_type+"Value": - va = Property(self.prefix_type,["Name","DisplayName","Switch"]) - va.suffix_type = "Value" - va.populate(child) - self.values.append(va) - self.populate(child,spaces+"----") - pass - - #toString function - def __str__(self): - toReturn = self.prefix_type+self.suffix_type+":" - for i in self.attributeNames: - toReturn += "\n "+i+": "+self.attributes[i] - if self.argumentProperty != "": - toReturn += "\n Argument:\n Property: "+self.argumentProperty+"\n IsRequired: "+self.argumentIsRequired - for i in self.values: - toReturn+="\n "+str(i).replace("\n","\n ") - return toReturn -########################################################################################### - -########################################################################################### -#Class that populates itself from an MSBuild file and outputs it in CMake -#format - -class MSBuildToCMake: - #document = the entire MSBuild xml file - def __init__(self,document=None): - self.enumProperties = [] - self.stringProperties = [] - self.stringListProperties = [] - self.boolProperties = [] - self.intProperties = [] - if document!=None : - self.populate(document) - pass - - #document = the entire MSBuild xml file - #spaces = don't use - #To add a new property (if they exist) copy and paste this code and fill in appropriate places - # - #if child.nodeName == "<Name>Property": - # self.<Name>Properties.append(Property("<Name>",[<List of attributes>],child)) - # - #Replace <Name> with the name of the new property (ex. if property is StringProperty replace <Name> with String) - #Replace <List of attributes> with a list of attributes in your property's root node - #in the __init__ function add the line self.<Name>Properties = [] - # - #That is all that is required to add new properties - # - def populate(self,document, spaces=""): - for i in range(len(document.childNodes)): - child = document.childNodes[i] - if child.nodeType == child.ELEMENT_NODE: - if child.nodeName == "EnumProperty": - self.enumProperties.append(Property("Enum",["Name","Category"],child)) - if child.nodeName == "StringProperty": - self.stringProperties.append(Property("String",["Name","Subtype","Separator","Category","Visible","IncludeInCommandLine","Switch","DisplayName","ReadOnly"],child)) - if child.nodeName == "StringListProperty": - self.stringListProperties.append(Property("StringList",["Name","Category","Switch","DisplayName","Subtype"],child)) - if child.nodeName == "BoolProperty": - self.boolProperties.append(Property("Bool",["ReverseSwitch","Name","Category","Switch","DisplayName","SwitchPrefix","IncludeInCommandLine"],child)) - if child.nodeName == "IntProperty": - self.intProperties.append(Property("Int",["Name","Category","Visible"],child)) - self.populate(child,spaces+"----") - pass - - #outputs information that CMake needs to know about MSBuild xml files - def toCMake(self): - toReturn = "static cmVS7FlagTable cmVS10CxxTable[] =\n{\n" - toReturn += "\n //Enum Properties\n" - lastProp = {} - for i in self.enumProperties: - if i.attributes["Name"] == "CompileAsManaged": - #write these out after the rest of the enumProperties - lastProp = i - continue - for j in i.values: - #hardcore Brad King's manual fixes for cmVS10CLFlagTable.h - if i.attributes["Name"] == "PrecompiledHeader" and j.attributes["Switch"] != "": - toReturn+=" {\""+i.attributes["Name"]+"\", \""+j.attributes["Switch"]+"\",\n \""+j.attributes["DisplayName"]+"\", \""+j.attributes["Name"]+"\",\n cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},\n" - else: - #default (normal, non-hardcoded) case - toReturn+=" {\""+i.attributes["Name"]+"\", \""+j.attributes["Switch"]+"\",\n \""+j.attributes["DisplayName"]+"\", \""+j.attributes["Name"]+"\", 0},\n" - toReturn += "\n" - - if lastProp != {}: - for j in lastProp.values: - toReturn+=" {\""+lastProp.attributes["Name"]+"\", \""+j.attributes["Switch"]+"\",\n \""+j.attributes["DisplayName"]+"\", \""+j.attributes["Name"]+"\", 0},\n" - toReturn += "\n" - - toReturn += "\n //Bool Properties\n" - for i in self.boolProperties: - if i.argumentProperty == "": - if i.attributes["ReverseSwitch"] != "": - toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["ReverseSwitch"]+"\", \"\", \"false\", 0},\n" - if i.attributes["Switch"] != "": - toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+"\", \"\", \"true\", 0},\n" - - toReturn += "\n //Bool Properties With Argument\n" - for i in self.boolProperties: - if i.argumentProperty != "": - if i.attributes["ReverseSwitch"] != "": - toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["ReverseSwitch"]+"\", \"\", \"false\",\n cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},\n" - toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["ReverseSwitch"]+"\", \""+i.attributes["DisplayName"]+"\", \"\",\n cmVS7FlagTable::UserValueRequired},\n" - if i.attributes["Switch"] != "": - toReturn += " {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+"\", \"\", \"true\",\n cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},\n" - toReturn += " {\""+i.argumentProperty+"\", \""+i.attributes["Switch"]+"\", \""+i.attributes["DisplayName"]+"\", \"\",\n cmVS7FlagTable::UserValueRequired},\n" - - toReturn += "\n //String List Properties\n" - for i in self.stringListProperties: - if i.attributes["Switch"] == "": - toReturn += " // Skip [" + i.attributes["Name"] + "] - no command line Switch.\n"; - else: - toReturn +=" {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+"\",\n \""+i.attributes["DisplayName"]+"\",\n \"\", cmVS7FlagTable::UserValue | cmVS7FlagTable::SemicolonAppendable},\n" - - toReturn += "\n //String Properties\n" - for i in self.stringProperties: - if i.attributes["Switch"] == "": - if i.attributes["Name"] == "PrecompiledHeaderFile": - #more hardcoding - toReturn += " {\"PrecompiledHeaderFile\", \"Yc\",\n" - toReturn += " \"Precompiled Header Name\",\n" - toReturn += " \"\", cmVS7FlagTable::UserValueRequired},\n" - toReturn += " {\"PrecompiledHeaderFile\", \"Yu\",\n" - toReturn += " \"Precompiled Header Name\",\n" - toReturn += " \"\", cmVS7FlagTable::UserValueRequired},\n" - else: - toReturn += " // Skip [" + i.attributes["Name"] + "] - no command line Switch.\n"; - else: - toReturn +=" {\""+i.attributes["Name"]+"\", \""+i.attributes["Switch"]+i.attributes["Separator"]+"\",\n \""+i.attributes["DisplayName"]+"\",\n \"\", cmVS7FlagTable::UserValue},\n" - - toReturn += " {0,0,0,0,0}\n};" - return toReturn - pass - - #toString function - def __str__(self): - toReturn = "" - allList = [self.enumProperties,self.stringProperties,self.stringListProperties,self.boolProperties,self.intProperties] - for p in allList: - for i in p: - toReturn += "==================================================\n"+str(i).replace("\n","\n ")+"\n==================================================\n" - - return toReturn -########################################################################################### - -########################################################################################### -# main function -def main(argv): - xml_file = None - help = """ - Please specify an input xml file with -x - - Exiting... - Have a nice day :)""" - for i in range(0,len(argv)): - if argv[i] == "-x": - xml_file = argv[i+1] - if argv[i] == "-h": - print help - sys.exit(0) - pass - if xml_file == None: - print help - sys.exit(1) - - f = open(xml_file,"r") - xml_str = f.read() - xml_dom = parseString(xml_str) - - convertor = MSBuildToCMake(xml_dom) - print convertor.toCMake() - - xml_dom.unlink() -########################################################################################### -# main entry point -if __name__ == "__main__": - main(sys.argv) - -sys.exit(0) diff --git a/Source/ctest.cxx b/Source/ctest.cxx index ca412ae..8ba126f 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -46,7 +46,10 @@ static const char* cmDocumentationOptions[][2] = { "given number of jobs." }, { "-Q,--quiet", "Make ctest quiet." }, { "-O <file>, --output-log <file>", "Output to log file" }, - { "-N,--show-only", "Disable actual execution of tests." }, + { "-N,--show-only[=format]", + "Disable actual execution of tests. The optional 'format' defines the " + "format of the test information and can be 'human' for the current text " + "format or 'json-v1' for json format. Defaults to 'human'." }, { "-L <regex>, --label-regex <regex>", "Run tests with labels matching " "regular expression." }, diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 094c2ee..f65690b 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -1162,7 +1162,7 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, case KWSYSPE_PIPE_STDERR: wd->PipeId = kwsysProcess_Pipe_STDERR; break; - }; + } return 1; } } else if (n < 0 && errno == EAGAIN) { diff --git a/Source/kwsys/testCommandLineArguments.cxx b/Source/kwsys/testCommandLineArguments.cxx index ef87436..15f9c02 100644 --- a/Source/kwsys/testCommandLineArguments.cxx +++ b/Source/kwsys/testCommandLineArguments.cxx @@ -165,25 +165,26 @@ int testCommandLineArguments(int argc, char* argv[]) } size_t cc; #define CompareTwoLists(list1, list_valid, lsize) \ - if (list1.size() != lsize) { \ - std::cerr << "Problem setting " #list1 ". Size is: " << list1.size() \ - << " should be: " << lsize << std::endl; \ - res = 1; \ - } else { \ - std::cout << #list1 " argument set:"; \ - for (cc = 0; cc < lsize; ++cc) { \ - std::cout << " " << list1[cc]; \ - if (!CompareTwoItemsOnList(list1[cc], list_valid[cc])) { \ - std::cerr << "Problem setting " #list1 ". Value of " << cc \ - << " is: [" << list1[cc] << "] <> [" << list_valid[cc] \ - << "]" << std::endl; \ - res = 1; \ - break; \ + do { \ + if (list1.size() != lsize) { \ + std::cerr << "Problem setting " #list1 ". Size is: " << list1.size() \ + << " should be: " << lsize << std::endl; \ + res = 1; \ + } else { \ + std::cout << #list1 " argument set:"; \ + for (cc = 0; cc < lsize; ++cc) { \ + std::cout << " " << list1[cc]; \ + if (!CompareTwoItemsOnList(list1[cc], list_valid[cc])) { \ + std::cerr << "Problem setting " #list1 ". Value of " << cc \ + << " is: [" << list1[cc] << "] <> [" << list_valid[cc] \ + << "]" << std::endl; \ + res = 1; \ + break; \ + } \ } \ + std::cout << std::endl; \ } \ - std::cout << std::endl; \ - } - + } while (0) CompareTwoLists(numbers_argument, valid_numbers, 10); CompareTwoLists(doubles_argument, valid_doubles, 3); CompareTwoLists(bools_argument, valid_bools, 3); |