This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, master has been updated via 467e6ac728cefa484f9e9369a7da4d05b04ec403 (commit) via c23c4ed9cf912e265e1070507905b3dbc495a210 (commit) via 9f23c91919945f8158ef5bc2512aefaa418de0da (commit) via c9af23d2a1f00d76d550892fcc94f03c2cfd1cf9 (commit) via aff019f7a453e8bbb67f004d3164151305d0d23e (commit) via 780d9e070bec694c12a10162d64196073c6d2ba2 (commit) via 94f536b9354b13cbd9b04ec9157f6acbbfd46598 (commit) via 4ff0bb054b65ac332fed3272afac8142599b6464 (commit) via 65d3ea2c7f737c01b426d73f57167f5ad60c095c (commit) via e91bfe440c1419b445ef6746552dd03ba302e6cf (commit) via f2ba968ef2a1c46e117dcd8eec34a55775f3d5f4 (commit) via 9b5cc4253135c7811936b05525e013e04a390d02 (commit) via e268840c0a5db59f97c0fbc77aaae621520b83a3 (commit) via 451fd329a88f26bacce7e9939ef767876b385050 (commit) from ea2b488fecc7536197c766e22732edf3928bfc27 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=467e6ac728cefa484f9e9369a7da4d05b04ec403 commit 467e6ac728cefa484f9e9369a7da4d05b04ec403 Merge: c23c4ed e91bfe4 Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Jul 26 11:29:19 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Jul 26 07:32:18 2019 -0400 Merge topic 'definitions_string_view' e91bfe440c cmMakefile: Let AddDefinition accept a value as cm::string_view f2ba968ef2 cmMakefile: Simplify and rename AddDefinitionBool 9b5cc42531 cmDefinitions: Remove const char* based Set method e268840c0a cmDefinitions: Add Unset and cm::string_view based Set methods 451fd329a8 cmDefinitions: Cleanups Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3577 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c23c4ed9cf912e265e1070507905b3dbc495a210 commit c23c4ed9cf912e265e1070507905b3dbc495a210 Merge: 9f23c91 4ff0bb0 Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Jul 26 11:29:31 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Jul 26 07:30:45 2019 -0400 Merge topic 'IsON_IsOFF_string_view' 4ff0bb054b cmSystemTools: Make IsInternallyOn, IsON and IsOff cm::string_view based 65d3ea2c7f cmAlgorithms: Make cmHasLiteral{Prefix,Suffix} cm::string_view based Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3598 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9f23c91919945f8158ef5bc2512aefaa418de0da commit 9f23c91919945f8158ef5bc2512aefaa418de0da Merge: c9af23d aff019f Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Jul 26 11:28:30 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Jul 26 07:29:21 2019 -0400 Merge topic 'update-kwsys' aff019f7a4 Merge branch 'upstream-KWSys' into update-kwsys 780d9e070b KWSys 2019-07-25 (a24a6acb) Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3602 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c9af23d2a1f00d76d550892fcc94f03c2cfd1cf9 commit c9af23d2a1f00d76d550892fcc94f03c2cfd1cf9 Merge: ea2b488 94f536b Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Jul 26 11:28:00 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Jul 26 07:28:09 2019 -0400 Merge topic 'variable-typo' 94f536b935 cmCTestHandlerCommand: fix typo of local variable Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3600 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=aff019f7a453e8bbb67f004d3164151305d0d23e commit aff019f7a453e8bbb67f004d3164151305d0d23e Merge: a1c6d7e 780d9e0 Author: Brad King <brad.k...@kitware.com> AuthorDate: Thu Jul 25 07:54:34 2019 -0400 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Jul 25 07:54:34 2019 -0400 Merge branch 'upstream-KWSys' into update-kwsys * upstream-KWSys: KWSys 2019-07-25 (a24a6acb) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=780d9e070bec694c12a10162d64196073c6d2ba2 commit 780d9e070bec694c12a10162d64196073c6d2ba2 Author: KWSys Upstream <kwro...@kitware.com> AuthorDate: Thu Jul 25 07:53:43 2019 -0400 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Jul 25 07:54:33 2019 -0400 KWSys 2019-07-25 (a24a6acb) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit a24a6acbbb4a51cf6fefbeb10d1f63ed1b670c69 (master). Upstream Shortlog ----------------- Brad King (3): 15896025 SystemTools: Use C++11 in SystemToolsAppendComponents c6f8e24a SystemTools: Fix CollapseFullPath with relative base path 5ca03af6 SystemTools: Revert "Reduce scope of 'buf' variable in CollapseFullPath" David Bodnar (5): 116a4919 RegularExpression: Reduce scope of 'len' variable 31f5cdeb RegularExpression: Initialize private members on construction 6e36d909 SystemTools: Reduce scope of 'buf' variable in CollapseFullPath a93bc28c SystemTools: Drop unnecessary .c_str() 6c3dfd25 CommandLineArguments: initialize internal class members directly diff --git a/CommandLineArguments.cxx b/CommandLineArguments.cxx index a97f7a8..dc9f01d 100644 --- a/CommandLineArguments.cxx +++ b/CommandLineArguments.cxx @@ -67,10 +67,10 @@ class CommandLineArgumentsInternal { public: CommandLineArgumentsInternal() + : UnknownArgumentCallback{ KWSYS_NULLPTR } + , ClientData{ KWSYS_NULLPTR } + , LastArgument{ 0 } { - this->UnknownArgumentCallback = KWSYS_NULLPTR; - this->ClientData = KWSYS_NULLPTR; - this->LastArgument = 0; } typedef CommandLineArgumentsVectorOfStrings VectorOfStrings; diff --git a/RegularExpression.cxx b/RegularExpression.cxx index 5f84b19..3e10765 100644 --- a/RegularExpression.cxx +++ b/RegularExpression.cxx @@ -337,7 +337,6 @@ bool RegularExpression::compile(const char* exp) { const char* scan; const char* longest; - size_t len; int flags; if (exp == KWSYS_NULLPTR) { @@ -412,7 +411,7 @@ bool RegularExpression::compile(const char* exp) // if (flags & SPSTART) { longest = KWSYS_NULLPTR; - len = 0; + size_t len = 0; for (; scan != KWSYS_NULLPTR; scan = regnext(scan)) if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) { longest = OPERAND(scan); diff --git a/RegularExpression.hxx.in b/RegularExpression.hxx.in index b7b93f9..ed86418 100644 --- a/RegularExpression.hxx.in +++ b/RegularExpression.hxx.in @@ -407,8 +407,12 @@ private: * Create an empty regular expression. */ inline RegularExpression::RegularExpression() + : regstart{} + , reganch{} + , regmust{} + , program{ 0 } + , progsize{} { - this->program = 0; } /** @@ -416,8 +420,12 @@ inline RegularExpression::RegularExpression() * compiles s. */ inline RegularExpression::RegularExpression(const char* s) + : regstart{} + , reganch{} + , regmust{} + , program{ 0 } + , progsize{} { - this->program = 0; if (s) { this->compile(s); } @@ -428,8 +436,12 @@ inline RegularExpression::RegularExpression(const char* s) * compiles s. */ inline RegularExpression::RegularExpression(const std::string& s) + : regstart{} + , reganch{} + , regmust{} + , program{ 0 } + , progsize{} { - this->program = 0; this->compile(s); } diff --git a/SystemTools.cxx b/SystemTools.cxx index 2135913..36f24c7 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -3394,15 +3394,16 @@ static void SystemToolsAppendComponents( static const std::string cur = "."; for (std::vector<std::string>::const_iterator i = first; i != last; ++i) { if (*i == up) { - if (out_components.size() > 1) { + // Remove the previous component if possible. Ignore ../ components + // that try to go above the root. Keep ../ components if they are + // at the beginning of a relative path (base path is relative). + if (out_components.size() > 1 && out_components.back() != up) { out_components.resize(out_components.size() - 1); + } else if (!out_components.empty() && out_components[0].empty()) { + out_components.emplace_back(std::move(*i)); } } else if (!i->empty() && *i != cur) { -#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L) - out_components.push_back(std::move(*i)); -#else - out_components.push_back(*i); -#endif + out_components.emplace_back(std::move(*i)); } } } @@ -4738,7 +4739,7 @@ void SystemTools::ClassInitialize() // Test progressively shorter logical-to-physical mappings. std::string cwd_str = cwd; std::string pwd_path; - Realpath(pwd_str.c_str(), pwd_path); + Realpath(pwd_str, pwd_path); while (cwd_str == pwd_path && cwd_str != pwd_str) { // The current pair of paths is a working logical mapping. cwd_changed = cwd_str; @@ -4748,7 +4749,7 @@ void SystemTools::ClassInitialize() // mapping still works. pwd_str = SystemTools::GetFilenamePath(pwd_str); cwd_str = SystemTools::GetFilenamePath(cwd_str); - Realpath(pwd_str.c_str(), pwd_path); + Realpath(pwd_str, pwd_path); } // Add the translation to keep the logical path name. diff --git a/testSystemTools.cxx b/testSystemTools.cxx index 9a40b53..ffa6a29 100644 --- a/testSystemTools.cxx +++ b/testSystemTools.cxx @@ -684,9 +684,10 @@ static bool CheckRelativePaths() } static bool CheckCollapsePath(const std::string& path, - const std::string& expected) + const std::string& expected, + const char* base = nullptr) { - std::string result = kwsys::SystemTools::CollapseFullPath(path); + std::string result = kwsys::SystemTools::CollapseFullPath(path, base); if (!kwsys::SystemTools::ComparePath(expected, result)) { std::cerr << "CollapseFullPath(" << path << ") yielded " << result << " instead of " << expected << std::endl; @@ -710,6 +711,9 @@ static bool CheckCollapsePath() res &= CheckCollapsePath("C:/", "C:/"); res &= CheckCollapsePath("C:/../", "C:/"); res &= CheckCollapsePath("C:/../../", "C:/"); + res &= CheckCollapsePath("../b", "../../b", "../"); + res &= CheckCollapsePath("../a/../b", "../b", "../rel"); + res &= CheckCollapsePath("a/../b", "../rel/b", "../rel"); return res; } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=94f536b9354b13cbd9b04ec9157f6acbbfd46598 commit 94f536b9354b13cbd9b04ec9157f6acbbfd46598 Author: Ben Boeckel <ben.boec...@kitware.com> AuthorDate: Wed Jul 24 15:29:32 2019 -0400 Commit: Ben Boeckel <ben.boec...@kitware.com> CommitDate: Wed Jul 24 15:29:32 2019 -0400 cmCTestHandlerCommand: fix typo of local variable diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index 2b73d40..381b41e 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -112,17 +112,17 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, foundBadArgument = true; } } - bool capureCMakeError = (this->Values[ct_CAPTURE_CMAKE_ERROR] && - *this->Values[ct_CAPTURE_CMAKE_ERROR]); + bool captureCMakeError = (this->Values[ct_CAPTURE_CMAKE_ERROR] && + *this->Values[ct_CAPTURE_CMAKE_ERROR]); // now that arguments are parsed check to see if there is a // CAPTURE_CMAKE_ERROR specified let the errorState object know. - if (capureCMakeError) { + if (captureCMakeError) { errorState.CaptureCMakeError(); } // if we found a bad argument then exit before running command if (foundBadArgument) { // store the cmake error - if (capureCMakeError) { + if (captureCMakeError) { this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR], "-1"); std::string const err = this->GetName() + " " + status.GetError(); @@ -191,7 +191,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot instantiate test handler " << this->GetName() << std::endl); - if (capureCMakeError) { + if (captureCMakeError) { this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR], "-1"); std::string const& err = status.GetError(); @@ -215,7 +215,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, this->SetError("failed to change directory to " + this->CTest->GetCTestConfiguration("BuildDirectory") + " : " + std::strerror(workdir.GetLastResult())); - if (capureCMakeError) { + if (captureCMakeError) { this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR], "-1"); cmCTestLog(this->CTest, ERROR_MESSAGE, @@ -235,7 +235,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, } this->ProcessAdditionalValues(handler); // log the error message if there was an error - if (capureCMakeError) { + if (captureCMakeError) { const char* returnString = "0"; if (cmSystemTools::GetErrorOccuredFlag()) { returnString = "-1"; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4ff0bb054b65ac332fed3272afac8142599b6464 commit 4ff0bb054b65ac332fed3272afac8142599b6464 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Tue Jul 23 12:04:41 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Wed Jul 24 19:31:14 2019 +0200 cmSystemTools: Make IsInternallyOn, IsON and IsOff cm::string_view based diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 723f280..e824757 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -282,115 +282,85 @@ void cmSystemTools::ReportLastSystemError(const char* msg) cmSystemTools::Error(m); } -bool cmSystemTools::IsInternallyOn(const char* val) -{ - if (!val) { - return false; - } - std::string v = val; - if (v.size() > 4) { - return false; - } - - for (char& c : v) { - c = static_cast<char>(toupper(c)); +bool cmSystemTools::IsInternallyOn(cm::string_view val) +{ + return (val.size() == 4) && // + (val[0] == 'I' || val[0] == 'i') && // + (val[1] == '_') && // + (val[2] == 'O' || val[2] == 'o') && // + (val[3] == 'N' || val[3] == 'n'); +} + +bool cmSystemTools::IsOn(cm::string_view val) +{ + switch (val.size()) { + case 1: + return val[0] == '1' || val[0] == 'Y' || val[0] == 'y'; + case 2: + return // + (val[0] == 'O' || val[0] == 'o') && // + (val[1] == 'N' || val[1] == 'n'); + case 3: + return // + (val[0] == 'Y' || val[0] == 'y') && // + (val[1] == 'E' || val[1] == 'e') && // + (val[2] == 'S' || val[2] == 's'); + case 4: + return // + (val[0] == 'T' || val[0] == 't') && // + (val[1] == 'R' || val[1] == 'r') && // + (val[2] == 'U' || val[2] == 'u') && // + (val[3] == 'E' || val[3] == 'e'); + default: + break; } - return v == "I_ON"; -} -bool cmSystemTools::IsOn(const char* val) -{ - if (!val) { - return false; - } - /* clang-format off */ - // "1" - if (val[0] == '1' && val[1] == '\0') { - return true; - } - // "ON" - if ((val[0] == 'O' || val[0] == 'o') && - (val[1] == 'N' || val[1] == 'n') && val[2] == '\0') { - return true; - } - // "Y", "YES" - if ((val[0] == 'Y' || val[0] == 'y') && (val[1] == '\0' || ( - (val[1] == 'E' || val[1] == 'e') && - (val[2] == 'S' || val[2] == 's') && val[3] == '\0'))) { - return true; - } - // "TRUE" - if ((val[0] == 'T' || val[0] == 't') && - (val[1] == 'R' || val[1] == 'r') && - (val[2] == 'U' || val[2] == 'u') && - (val[3] == 'E' || val[3] == 'e') && val[4] == '\0') { - return true; - } - /* clang-format on */ return false; } -bool cmSystemTools::IsOn(const std::string& val) +bool cmSystemTools::IsNOTFOUND(cm::string_view val) { - return cmSystemTools::IsOn(val.c_str()); + return (val == "NOTFOUND") || cmHasLiteralSuffix(val, "-NOTFOUND"); } -bool cmSystemTools::IsNOTFOUND(const char* val) +bool cmSystemTools::IsOff(cm::string_view val) { - if (strcmp(val, "NOTFOUND") == 0) { - return true; + switch (val.size()) { + case 0: + return true; + case 1: + return val[0] == '0' || val[0] == 'N' || val[0] == 'n'; + case 2: + return // + (val[0] == 'N' || val[0] == 'n') && // + (val[1] == 'O' || val[1] == 'o'); + case 3: + return // + (val[0] == 'O' || val[0] == 'o') && // + (val[1] == 'F' || val[1] == 'f') && // + (val[2] == 'F' || val[2] == 'f'); + case 5: + return // + (val[0] == 'F' || val[0] == 'f') && // + (val[1] == 'A' || val[1] == 'a') && // + (val[2] == 'L' || val[2] == 'l') && // + (val[3] == 'S' || val[3] == 's') && // + (val[4] == 'E' || val[4] == 'e'); + case 6: + return // + (val[0] == 'I' || val[0] == 'i') && // + (val[1] == 'G' || val[1] == 'g') && // + (val[2] == 'N' || val[2] == 'n') && // + (val[3] == 'O' || val[3] == 'o') && // + (val[4] == 'R' || val[4] == 'r') && // + (val[5] == 'E' || val[5] == 'e'); + default: + break; } - return cmHasLiteralSuffix(val, "-NOTFOUND"); -} -bool cmSystemTools::IsOff(const char* val) -{ - // "" - if (!val || val[0] == '\0') { - return true; - } - /* clang-format off */ - // "0" - if (val[0] == '0' && val[1] == '\0') { - return true; - } - // "OFF" - if ((val[0] == 'O' || val[0] == 'o') && - (val[1] == 'F' || val[1] == 'f') && - (val[2] == 'F' || val[2] == 'f') && val[3] == '\0') { - return true; - } - // "N", "NO" - if ((val[0] == 'N' || val[0] == 'n') && (val[1] == '\0' || ( - (val[1] == 'O' || val[1] == 'o') && val[2] == '\0'))) { - return true; - } - // "FALSE" - if ((val[0] == 'F' || val[0] == 'f') && - (val[1] == 'A' || val[1] == 'a') && - (val[2] == 'L' || val[2] == 'l') && - (val[3] == 'S' || val[3] == 's') && - (val[4] == 'E' || val[4] == 'e') && val[5] == '\0') { - return true; - } - // "IGNORE" - if ((val[0] == 'I' || val[0] == 'i') && - (val[1] == 'G' || val[1] == 'g') && - (val[2] == 'N' || val[2] == 'n') && - (val[3] == 'O' || val[3] == 'o') && - (val[4] == 'R' || val[4] == 'r') && - (val[5] == 'E' || val[5] == 'e') && val[6] == '\0') { - return true; - } - /* clang-format on */ return cmSystemTools::IsNOTFOUND(val); } -bool cmSystemTools::IsOff(const std::string& val) -{ - return cmSystemTools::IsOff(val.c_str()); -} - void cmSystemTools::ParseWindowsCommandLine(const char* command, std::vector<std::string>& args) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index a9c03bd..5ce6a48 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -8,6 +8,7 @@ #include "cmCryptoHash.h" #include "cmDuration.h" #include "cmProcessOutput.h" +#include "cm_string_view.hxx" #include "cmsys/Process.h" #include "cmsys/SystemTools.hxx" // IWYU pragma: export #include <functional> @@ -149,26 +150,45 @@ public: * forced this value. This is not the same as On, but this * may be considered as "internally switched on". */ - static bool IsInternallyOn(const char* val); + static bool IsInternallyOn(cm::string_view val); + static inline bool IsInternallyOn(const char* val) + { + if (!val) { + return false; + } + return IsInternallyOn(cm::string_view(val)); + } + /** - * does a string indicate a true or on value ? This is not the same - * as ifdef. + * Does a string indicate a true or on value? This is not the same as ifdef. */ - static bool IsOn(const char* val); - static bool IsOn(const std::string& val); + static bool IsOn(cm::string_view val); + inline static bool IsOn(const char* val) + { + if (!val) { + return false; + } + return IsOn(cm::string_view(val)); + } /** - * does a string indicate a false or off value ? Note that this is + * Does a string indicate a false or off value ? Note that this is * not the same as !IsOn(...) because there are a number of * ambiguous values such as "/usr/local/bin" a path will result in * IsON and IsOff both returning false. Note that the special path * NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true. */ - static bool IsOff(const char* val); - static bool IsOff(const std::string& val); + static bool IsOff(cm::string_view val); + inline static bool IsOff(const char* val) + { + if (!val) { + return true; + } + return IsOff(cm::string_view(val)); + } //! Return true if value is NOTFOUND or ends in -NOTFOUND. - static bool IsNOTFOUND(const char* value); + static bool IsNOTFOUND(cm::string_view val); //! Return true if the path is a framework static bool IsPathToFramework(const std::string& value); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=65d3ea2c7f737c01b426d73f57167f5ad60c095c commit 65d3ea2c7f737c01b426d73f57167f5ad60c095c Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Wed Jul 24 11:40:39 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Wed Jul 24 19:31:14 2019 +0200 cmAlgorithms: Make cmHasLiteral{Prefix,Suffix} cm::string_view based diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index b4b480b..cf71052 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -19,44 +19,6 @@ #include <utility> #include <vector> -inline bool cmHasLiteralPrefixImpl(const std::string& str1, const char* str2, - size_t N) -{ - return strncmp(str1.c_str(), str2, N) == 0; -} - -inline bool cmHasLiteralPrefixImpl(const char* str1, const char* str2, - size_t N) -{ - return strncmp(str1, str2, N) == 0; -} - -inline bool cmHasLiteralSuffixImpl(const std::string& str1, const char* str2, - size_t N) -{ - size_t len = str1.size(); - return len >= N && strcmp(str1.c_str() + len - N, str2) == 0; -} - -inline bool cmHasLiteralSuffixImpl(const char* str1, const char* str2, - size_t N) -{ - size_t len = strlen(str1); - return len >= N && strcmp(str1 + len - N, str2) == 0; -} - -template <typename T, size_t N> -bool cmHasLiteralPrefix(const T& str1, const char (&str2)[N]) -{ - return cmHasLiteralPrefixImpl(str1, str2, N - 1); -} - -template <typename T, size_t N> -bool cmHasLiteralSuffix(const T& str1, const char (&str2)[N]) -{ - return cmHasLiteralSuffixImpl(str1, str2, N - 1); -} - struct cmStrCmp { cmStrCmp(const char* test) @@ -327,6 +289,13 @@ inline bool cmHasPrefix(cm::string_view str, cm::string_view prefix) return str.compare(0, prefix.size(), prefix) == 0; } +/** Returns true if string @a str starts with string @a prefix. **/ +template <size_t N> +inline bool cmHasLiteralPrefix(cm::string_view str, const char (&prefix)[N]) +{ + return cmHasPrefix(str, cm::string_view(prefix, N - 1)); +} + /** Returns true if string @a str ends with the character @a suffix. **/ inline bool cmHasSuffix(cm::string_view str, char suffix) { @@ -340,6 +309,13 @@ inline bool cmHasSuffix(cm::string_view str, cm::string_view suffix) str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } +/** Returns true if string @a str ends with string @a suffix. **/ +template <size_t N> +inline bool cmHasLiteralSuffix(cm::string_view str, const char (&suffix)[N]) +{ + return cmHasSuffix(str, cm::string_view(suffix, N - 1)); +} + /** Removes an existing suffix character of from the string @a str. **/ inline void cmStripSuffixIfExists(std::string& str, char suffix) { diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index acacba2..d887627 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -146,8 +146,7 @@ bool cmSourceFileLocation::MatchesAmbiguousExtension( // adding an extension. if (!(this->Name.size() > loc.Name.size() && this->Name[loc.Name.size()] == '.' && - cmHasLiteralPrefixImpl(this->Name.c_str(), loc.Name.c_str(), - loc.Name.size()))) { + cmHasPrefix(this->Name, loc.Name))) { return false; } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e91bfe440c1419b445ef6746552dd03ba302e6cf commit e91bfe440c1419b445ef6746552dd03ba302e6cf Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Wed Jul 17 16:20:58 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Wed Jul 24 11:11:25 2019 +0200 cmMakefile: Let AddDefinition accept a value as cm::string_view This changes `cmMakefile::AddDefinition` to take a `cm::string_view` as value argument instead of a `const char *`. Benefits are: - `std::string` can be passed to `cmMakefile::AddDefinition` directly without the `c_str()` plus string length recomputation fallback. - Lengths of literals passed to `cmMakefile::AddDefinition` can be computed at compile time. In various sources uses of `cmMakefile::AddDefinition` are adapted to avoid `std::string::c_str` calls and the `std::string` is passed directly. Uses of `cmMakefile::AddDefinition`, where a `nullptr` `const char*` might be passed to `cmMakefile::AddDefinition` are extended with `nullptr` checks. diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 350ebed..512ac7a 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -759,7 +759,7 @@ int cmCPackGenerator::InstallCMakeProject( if (this->GetOption("CPACK_INSTALL_PREFIX")) { dir += this->GetOption("CPACK_INSTALL_PREFIX"); } - mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir); cmCPackLogger( cmCPackLog::LOG_DEBUG, @@ -799,7 +799,7 @@ int cmCPackGenerator::InstallCMakeProject( return 0; } } else { - mf.AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory); if (!cmsys::SystemTools::MakeDirectory(tempInstallDirectory, default_dir_mode)) { @@ -818,11 +818,11 @@ int cmCPackGenerator::InstallCMakeProject( } if (!buildConfig.empty()) { - mf.AddDefinition("BUILD_TYPE", buildConfig.c_str()); + mf.AddDefinition("BUILD_TYPE", buildConfig); } std::string installComponentLowerCase = cmSystemTools::LowerCase(component); if (installComponentLowerCase != "all") { - mf.AddDefinition("CMAKE_INSTALL_COMPONENT", component.c_str()); + mf.AddDefinition("CMAKE_INSTALL_COMPONENT", component); } // strip on TRUE, ON, 1, one or several file names, but not on @@ -863,9 +863,8 @@ int cmCPackGenerator::InstallCMakeProject( // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES // to CPack (may be used by generators like CPack RPM or DEB) // in order to transparently handle ABSOLUTE PATH - if (mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { - mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", - mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); + if (const char* def = mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { + mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", def); } // Now rebuild the list of files after installation diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index c6018cf..89c3b1c 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -270,7 +270,7 @@ int main(int argc, char const* const* argv) } if (!cpackBuildConfig.empty()) { - globalMF.AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str()); + globalMF.AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig); } if (cmSystemTools::FileExists(cpackConfigFile)) { @@ -292,24 +292,21 @@ int main(int argc, char const* const* argv) } if (!generator.empty()) { - globalMF.AddDefinition("CPACK_GENERATOR", generator.c_str()); + globalMF.AddDefinition("CPACK_GENERATOR", generator); } if (!cpackProjectName.empty()) { - globalMF.AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName); } if (!cpackProjectVersion.empty()) { - globalMF.AddDefinition("CPACK_PACKAGE_VERSION", - cpackProjectVersion.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_VERSION", cpackProjectVersion); } if (!cpackProjectVendor.empty()) { - globalMF.AddDefinition("CPACK_PACKAGE_VENDOR", - cpackProjectVendor.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_VENDOR", cpackProjectVendor); } // if this is not empty it has been set on the command line // go for it. Command line override values set in config file. if (!cpackProjectDirectory.empty()) { - globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", - cpackProjectDirectory.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", cpackProjectDirectory); } // The value has not been set on the command line else { @@ -318,11 +315,11 @@ int main(int argc, char const* const* argv) // use default value iff no value has been provided by the config file if (!globalMF.IsSet("CPACK_PACKAGE_DIRECTORY")) { globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", - cpackProjectDirectory.c_str()); + cpackProjectDirectory); } } for (auto const& cd : definitions.Map) { - globalMF.AddDefinition(cd.first, cd.second.c_str()); + globalMF.AddDefinition(cd.first, cd.second); } const char* cpackModulesPath = globalMF.GetDefinition("CPACK_MODULE_PATH"); @@ -426,7 +423,7 @@ int main(int argc, char const* const* argv) std::ostringstream ostr; ostr << projVersionMajor << "." << projVersionMinor << "." << projVersionPatch; - mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str().c_str()); + mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str()); } int res = cpackGenerator->DoPackage(); diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 2eacaf1..e71eafe 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -156,15 +156,14 @@ bool cmCTestBuildCommand::InitialPass(std::vector<std::string> const& args, if (this->Values[ctb_NUMBER_ERRORS] && *this->Values[ctb_NUMBER_ERRORS]) { std::ostringstream str; str << this->Handler->GetTotalErrors(); - this->Makefile->AddDefinition(this->Values[ctb_NUMBER_ERRORS], - str.str().c_str()); + this->Makefile->AddDefinition(this->Values[ctb_NUMBER_ERRORS], str.str()); } if (this->Values[ctb_NUMBER_WARNINGS] && *this->Values[ctb_NUMBER_WARNINGS]) { std::ostringstream str; str << this->Handler->GetTotalWarnings(); this->Makefile->AddDefinition(this->Values[ctb_NUMBER_WARNINGS], - str.str().c_str()); + str.str()); } return ret; } diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index 2b73d40..00188e4 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -230,8 +230,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, if (this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE]) { std::ostringstream str; str << res; - this->Makefile->AddDefinition(this->Values[ct_RETURN_VALUE], - str.str().c_str()); + this->Makefile->AddDefinition(this->Values[ct_RETURN_VALUE], str.str()); } this->ProcessAdditionalValues(handler); // log the error message if there was an error diff --git a/Source/CTest/cmCTestMemCheckCommand.cxx b/Source/CTest/cmCTestMemCheckCommand.cxx index 7dad1ce..d7d42bf 100644 --- a/Source/CTest/cmCTestMemCheckCommand.cxx +++ b/Source/CTest/cmCTestMemCheckCommand.cxx @@ -3,7 +3,6 @@ #include "cmCTestMemCheckCommand.h" #include <sstream> -#include <string> #include <vector> #include "cmCTest.h" @@ -47,7 +46,6 @@ void cmCTestMemCheckCommand::ProcessAdditionalValues( if (this->Values[ctm_DEFECT_COUNT] && *this->Values[ctm_DEFECT_COUNT]) { std::ostringstream str; str << static_cast<cmCTestMemCheckHandler*>(handler)->GetDefectCount(); - this->Makefile->AddDefinition(this->Values[ctm_DEFECT_COUNT], - str.str().c_str()); + this->Makefile->AddDefinition(this->Values[ctm_DEFECT_COUNT], str.str()); } } diff --git a/Source/CTest/cmCTestRunScriptCommand.cxx b/Source/CTest/cmCTestRunScriptCommand.cxx index a7e47d3..c03cffd 100644 --- a/Source/CTest/cmCTestRunScriptCommand.cxx +++ b/Source/CTest/cmCTestRunScriptCommand.cxx @@ -43,7 +43,7 @@ bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args, args[i].c_str(), !np, &ret); std::ostringstream str; str << ret; - this->Makefile->AddDefinition(returnVariable, str.str().c_str()); + this->Makefile->AddDefinition(returnVariable, str.str()); } } return true; diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index fc319b3..7a5b8d1 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -168,7 +168,7 @@ void cmCTestScriptHandler::UpdateElapsedTime() auto itime = cmDurationTo<unsigned int>(std::chrono::steady_clock::now() - this->ScriptStartTime); auto timeString = std::to_string(itime); - this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString.c_str()); + this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString); } } @@ -352,21 +352,21 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) this->CreateCMake(); // set a variable with the path to the current script - this->Makefile->AddDefinition( - "CTEST_SCRIPT_DIRECTORY", cmSystemTools::GetFilenamePath(script).c_str()); - this->Makefile->AddDefinition( - "CTEST_SCRIPT_NAME", cmSystemTools::GetFilenameName(script).c_str()); + this->Makefile->AddDefinition("CTEST_SCRIPT_DIRECTORY", + cmSystemTools::GetFilenamePath(script)); + this->Makefile->AddDefinition("CTEST_SCRIPT_NAME", + cmSystemTools::GetFilenameName(script)); this->Makefile->AddDefinition("CTEST_EXECUTABLE_NAME", - cmSystemTools::GetCTestCommand().c_str()); + cmSystemTools::GetCTestCommand()); this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME", - cmSystemTools::GetCMakeCommand().c_str()); + cmSystemTools::GetCMakeCommand()); this->Makefile->AddDefinitionBool("CTEST_RUN_CURRENT_SCRIPT", true); this->SetRunCurrentScript(true); this->UpdateElapsedTime(); // add the script arg if defined if (!script_arg.empty()) { - this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg.c_str()); + this->Makefile->AddDefinition("CTEST_SCRIPT_ARG", script_arg); } #if defined(__CYGWIN__) @@ -398,7 +398,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) const std::map<std::string, std::string>& defs = this->CTest->GetDefinitions(); for (auto const& d : defs) { - this->Makefile->AddDefinition(d.first, d.second.c_str()); + this->Makefile->AddDefinition(d.first, d.second); } // finally read in the script diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx index bf43d88..58c0a1b 100644 --- a/Source/CTest/cmCTestSubmitCommand.cxx +++ b/Source/CTest/cmCTestSubmitCommand.cxx @@ -143,7 +143,7 @@ bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args, if (this->Values[cts_BUILD_ID] && *this->Values[cts_BUILD_ID]) { this->Makefile->AddDefinition(this->Values[cts_BUILD_ID], - this->CTest->GetBuildID().c_str()); + this->CTest->GetBuildID()); } return ret; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index cfbdad0..5134407 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1714,8 +1714,7 @@ void cmCTestTestHandler::GetListOfTests() cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); cmMakefile mf(&gg, cm.GetCurrentSnapshot()); - mf.AddDefinition("CTEST_CONFIGURATION_TYPE", - this->CTest->GetConfigType().c_str()); + mf.AddDefinition("CTEST_CONFIGURATION_TYPE", this->CTest->GetConfigType()); // Add handler for ADD_TEST auto newCom1 = cm::make_unique<cmCTestAddTestCommand>(); diff --git a/Source/cmAuxSourceDirectoryCommand.cxx b/Source/cmAuxSourceDirectoryCommand.cxx index 106e7a7..c1a6e7f 100644 --- a/Source/cmAuxSourceDirectoryCommand.cxx +++ b/Source/cmAuxSourceDirectoryCommand.cxx @@ -74,6 +74,6 @@ bool cmAuxSourceDirectoryCommand::InitialPass( sourceListValue += ";"; } sourceListValue += cmJoin(files, ";"); - this->Makefile->AddDefinition(args[1], sourceListValue.c_str()); + this->Makefile->AddDefinition(args[1], sourceListValue); return true; } diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx index 428a0b2..e9e1d49 100644 --- a/Source/cmBuildCommand.cxx +++ b/Source/cmBuildCommand.cxx @@ -92,7 +92,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args) this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand( target, configuration, "", this->Makefile->IgnoreErrorsCMP0061()); - this->Makefile->AddDefinition(variable, makecommand.c_str()); + this->Makefile->AddDefinition(variable, makecommand); return true; } diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx index 54f08bb..b4cd2a5 100644 --- a/Source/cmCMakeHostSystemInformationCommand.cxx +++ b/Source/cmCMakeHostSystemInformationCommand.cxx @@ -55,7 +55,7 @@ bool cmCMakeHostSystemInformationCommand::InitialPass( result_list += value; } - this->Makefile->AddDefinition(variable, result_list.c_str()); + this->Makefile->AddDefinition(variable, result_list); return true; } diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx index 4b4bca2..f2eae38 100644 --- a/Source/cmCMakeMinimumRequired.cxx +++ b/Source/cmCMakeMinimumRequired.cxx @@ -61,8 +61,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args, } // Save the required version string. - this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION", - version_min.c_str()); + this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION", version_min); // Get the current version number. unsigned int current_major = cmVersion::GetMajorVersion(); diff --git a/Source/cmCMakePolicyCommand.cxx b/Source/cmCMakePolicyCommand.cxx index 8da5ef7..ce046fc 100644 --- a/Source/cmCMakePolicyCommand.cxx +++ b/Source/cmCMakePolicyCommand.cxx @@ -209,8 +209,7 @@ bool cmCMakePolicyCommand::HandleGetWarningMode( } // Lookup the policy warning. - this->Makefile->AddDefinition(var, - cmPolicies::GetPolicyWarning(pid).c_str()); + this->Makefile->AddDefinition(var, cmPolicies::GetPolicyWarning(pid)); return true; } diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 8c2d987..80ca898 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -65,8 +65,10 @@ unsigned int CCONV cmGetMinorVersion(void*) void CCONV cmAddDefinition(void* arg, const char* name, const char* value) { - cmMakefile* mf = static_cast<cmMakefile*>(arg); - mf->AddDefinition(name, value); + if (value) { + cmMakefile* mf = static_cast<cmMakefile*>(arg); + mf->AddDefinition(name, value); + } } /* Add a definition to this makefile and the global cmake cache. */ diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index f12ef0b..d780af6 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -932,7 +932,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, cmStateEnums::INTERNAL); if (!outputVariable.empty()) { - this->Makefile->AddDefinition(outputVariable, output.c_str()); + this->Makefile->AddDefinition(outputVariable, output); } if (this->SrcFileSignature) { @@ -961,8 +961,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, } if (!copyFileError.empty()) { - this->Makefile->AddDefinition(copyFileError, - copyFileErrorMessage.c_str()); + this->Makefile->AddDefinition(copyFileError, copyFileErrorMessage); } } return res; diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx index b78493f..427db72 100644 --- a/Source/cmCreateTestSourceList.cxx +++ b/Source/cmCreateTestSourceList.cxx @@ -125,16 +125,15 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, } if (!extraInclude.empty()) { this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES", - extraInclude.c_str()); + extraInclude); } if (!function.empty()) { - this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", - function.c_str()); + this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function); } this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", - forwardDeclareCode.c_str()); + forwardDeclareCode); this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", - functionMapCode.c_str()); + functionMapCode); bool res = true; if (!this->Makefile->ConfigureFile(configFile, driver, false, true, false)) { res = false; @@ -154,6 +153,6 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args, sourceListValue += *i; } - this->Makefile->AddDefinition(sourceList, sourceListValue.c_str()); + this->Makefile->AddDefinition(sourceList, sourceListValue); return res; } diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index 4b559e7..bc1d173 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -103,7 +103,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args, } std::string coutput = std::string(output, first, last - first + 1); - this->Makefile->AddDefinition(output_variable, coutput.c_str()); + this->Makefile->AddDefinition(output_variable, coutput); } if (!return_variable.empty()) { diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 689fc20..8d91f43 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -332,7 +332,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args, } } this->Makefile->AddDefinition(arguments.ResultsVariable, - cmJoin(res, ";").c_str()); + cmJoin(res, ";")); } break; case cmsysProcess_State_Exception: this->Makefile->AddDefinition(arguments.ResultsVariable, diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 70800b4..b7a2b27 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -117,8 +117,9 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args, } sourceListValue += generatedSourcesClasses[classNum]->GetFullPath(); } + std::string const varName = target + "_FLTK_UI_SRCS"; - this->Makefile->AddDefinition(varName, sourceListValue.c_str()); + this->Makefile->AddDefinition(varName, sourceListValue); this->Makefile->AddFinalAction( [target](cmMakefile& makefile) { FinalAction(makefile, target); }); diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 9871f49..1c40753 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -365,7 +365,7 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args) } } } - this->Makefile->AddDefinition(variable, output.c_str()); + this->Makefile->AddDefinition(variable, output); return true; } @@ -383,7 +383,7 @@ bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args) if (hash) { std::string out = hash->HashFile(args[1]); if (!out.empty()) { - this->Makefile->AddDefinition(args[2], out.c_str()); + this->Makefile->AddDefinition(args[2], out); return true; } std::ostringstream e; @@ -751,7 +751,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) } // Save the output in a makefile variable. - this->Makefile->AddDefinition(outVar, output.c_str()); + this->Makefile->AddDefinition(outVar, output); return true; } @@ -938,7 +938,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, std::sort(files.begin(), files.end()); files.erase(std::unique(files.begin(), files.end()), files.end()); - this->Makefile->AddDefinition(variable, cmJoin(files, ";").c_str()); + this->Makefile->AddDefinition(variable, cmJoin(files, ";")); return true; } @@ -1298,14 +1298,14 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args) if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) { std::string rpath(se_rpath->Value); std::replace(rpath.begin(), rpath.end(), ':', ';'); - this->Makefile->AddDefinition(arguments.RPath, rpath.c_str()); + this->Makefile->AddDefinition(arguments.RPath, rpath); } } if (!arguments.RunPath.empty()) { if (cmELF::StringEntry const* se_runpath = elf.GetRunPath()) { std::string runpath(se_runpath->Value); std::replace(runpath.begin(), runpath.end(), ':', ';'); - this->Makefile->AddDefinition(arguments.RunPath, runpath.c_str()); + this->Makefile->AddDefinition(arguments.RunPath, runpath); } } @@ -1316,7 +1316,7 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args) this->SetError(error); return false; } - this->Makefile->AddDefinition(arguments.Error, error.c_str()); + this->Makefile->AddDefinition(arguments.Error, error); return true; #endif } @@ -1354,7 +1354,7 @@ bool cmFileCommand::HandleRelativePathCommand( } std::string res = cmSystemTools::RelativePath(directoryName, fileName); - this->Makefile->AddDefinition(outVar, res.c_str()); + this->Makefile->AddDefinition(outVar, res); return true; } @@ -1460,7 +1460,7 @@ bool cmFileCommand::HandleCMakePathCommand( std::string value = cmJoin( cmMakeRange(path).transform(nativePath ? ToNativePath : ToCMakePath), ";"); - this->Makefile->AddDefinition(args[2], value.c_str()); + this->Makefile->AddDefinition(args[2], value); return true; } @@ -1800,7 +1800,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) if (!statusVar.empty()) { std::ostringstream result; result << 0 << ";\"" << msg; - this->Makefile->AddDefinition(statusVar, result.str().c_str()); + this->Makefile->AddDefinition(statusVar, result.str()); } return true; } @@ -1949,7 +1949,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) std::ostringstream result; result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res) << "\""; - this->Makefile->AddDefinition(statusVar, result.str().c_str()); + this->Makefile->AddDefinition(statusVar, result.str()); } ::curl_global_cleanup(); @@ -1981,7 +1981,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args) std::string status = "1;HASH mismatch: " "expected: " + expectedHash + " actual: " + actualHash; - this->Makefile->AddDefinition(statusVar, status.c_str()); + this->Makefile->AddDefinition(statusVar, status); } this->SetError(oss.str()); @@ -2236,7 +2236,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) std::ostringstream result; result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res) << "\""; - this->Makefile->AddDefinition(statusVar, result.str().c_str()); + this->Makefile->AddDefinition(statusVar, result.str()); } ::curl_global_cleanup(); @@ -2261,7 +2261,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args) log += "\n"; } - this->Makefile->AddDefinition(logVar, log.c_str()); + this->Makefile->AddDefinition(logVar, log); } return true; @@ -2479,7 +2479,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args) } if (!resultVariable.empty()) { - this->Makefile->AddDefinition(resultVariable, result.c_str()); + this->Makefile->AddDefinition(resultVariable, result); } return true; @@ -2528,7 +2528,7 @@ bool cmFileCommand::HandleTimestampCommand( cmTimestamp timestamp; std::string result = timestamp.FileModificationTime(filename.c_str(), formatString, utcFlag); - this->Makefile->AddDefinition(outputVariable, result.c_str()); + this->Makefile->AddDefinition(outputVariable, result); return true; } @@ -2556,8 +2556,7 @@ bool cmFileCommand::HandleSizeCommand(std::vector<std::string> const& args) } this->Makefile->AddDefinition( - outputVariable, - std::to_string(cmSystemTools::FileLength(filename)).c_str()); + outputVariable, std::to_string(cmSystemTools::FileLength(filename))); return true; } @@ -2584,7 +2583,7 @@ bool cmFileCommand::HandleReadSymlinkCommand( return false; } - this->Makefile->AddDefinition(outputVariable, result.c_str()); + this->Makefile->AddDefinition(outputVariable, result); return true; } @@ -2630,7 +2629,7 @@ bool cmFileCommand::HandleCreateLinkCommand( if (fileName == newFileName) { result = "CREATE_LINK cannot use same file and newfile"; if (!arguments.Result.empty()) { - this->Makefile->AddDefinition(arguments.Result, result.c_str()); + this->Makefile->AddDefinition(arguments.Result, result); return true; } this->SetError(result); @@ -2641,7 +2640,7 @@ bool cmFileCommand::HandleCreateLinkCommand( if (!arguments.Symbolic && !cmSystemTools::FileExists(fileName)) { result = "Cannot hard link \'" + fileName + "\' as it does not exist."; if (!arguments.Result.empty()) { - this->Makefile->AddDefinition(arguments.Result, result.c_str()); + this->Makefile->AddDefinition(arguments.Result, result); return true; } this->SetError(result); @@ -2658,7 +2657,7 @@ bool cmFileCommand::HandleCreateLinkCommand( << cmSystemTools::GetLastSystemError() << "\n"; if (!arguments.Result.empty()) { - this->Makefile->AddDefinition(arguments.Result, e.str().c_str()); + this->Makefile->AddDefinition(arguments.Result, e.str()); return true; } this->SetError(e.str()); @@ -2693,7 +2692,7 @@ bool cmFileCommand::HandleCreateLinkCommand( } if (!arguments.Result.empty()) { - this->Makefile->AddDefinition(arguments.Result, result.c_str()); + this->Makefile->AddDefinition(arguments.Result, result); } return true; @@ -2821,7 +2820,7 @@ bool cmFileCommand::HandleGetRuntimeDependenciesCommand( std::string varName = parsedArgs.ConflictingDependenciesPrefix + "_" + val.first; std::string pathsStr = cmJoin(paths, ";"); - this->Makefile->AddDefinition(varName, pathsStr.c_str()); + this->Makefile->AddDefinition(varName, pathsStr); } else { std::ostringstream e; e << "Multiple conflicting paths found for " << val.first << ":"; @@ -2851,18 +2850,16 @@ bool cmFileCommand::HandleGetRuntimeDependenciesCommand( if (!parsedArgs.ResolvedDependenciesVar.empty()) { std::string val = cmJoin(deps, ";"); - this->Makefile->AddDefinition(parsedArgs.ResolvedDependenciesVar, - val.c_str()); + this->Makefile->AddDefinition(parsedArgs.ResolvedDependenciesVar, val); } if (!parsedArgs.UnresolvedDependenciesVar.empty()) { std::string val = cmJoin(unresolvedDeps, ";"); - this->Makefile->AddDefinition(parsedArgs.UnresolvedDependenciesVar, - val.c_str()); + this->Makefile->AddDefinition(parsedArgs.UnresolvedDependenciesVar, val); } if (!parsedArgs.ConflictingDependenciesPrefix.empty()) { std::string val = cmJoin(conflictingDeps, ";"); this->Makefile->AddDefinition( - parsedArgs.ConflictingDependenciesPrefix + "_FILENAMES", val.c_str()); + parsedArgs.ConflictingDependenciesPrefix + "_FILENAMES", val); } return true; } diff --git a/Source/cmFileInstaller.cxx b/Source/cmFileInstaller.cxx index d4f76fd..9378439 100644 --- a/Source/cmFileInstaller.cxx +++ b/Source/cmFileInstaller.cxx @@ -38,7 +38,7 @@ cmFileInstaller::~cmFileInstaller() { // Save the updated install manifest. this->Makefile->AddDefinition("CMAKE_INSTALL_MANIFEST_FILES", - this->Manifest.c_str()); + this->Manifest); } void cmFileInstaller::ManifestAppend(std::string const& file) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index c6d599e..5d656c1 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -675,7 +675,9 @@ void cmFindPackageCommand::AddFindDefinition(const std::string& var, } else { this->OriginalDefs[var].exists = false; } - this->Makefile->AddDefinition(var, val); + if (val) { + this->Makefile->AddDefinition(var, val); + } } void cmFindPackageCommand::RestoreFindDefinitions() @@ -683,7 +685,7 @@ void cmFindPackageCommand::RestoreFindDefinitions() for (auto const& i : this->OriginalDefs) { OriginalDef const& od = i.second; if (od.exists) { - this->Makefile->AddDefinition(i.first, od.value.c_str()); + this->Makefile->AddDefinition(i.first, od.value); } else { this->Makefile->RemoveDefinition(i.first); } @@ -957,7 +959,7 @@ bool cmFindPackageCommand::HandlePackageMode( std::string fileVar = this->Name; fileVar += "_CONFIG"; if (found) { - this->Makefile->AddDefinition(fileVar, this->FileFound.c_str()); + this->Makefile->AddDefinition(fileVar, this->FileFound); } else { this->Makefile->RemoveDefinition(fileVar); } @@ -979,11 +981,9 @@ bool cmFindPackageCommand::HandlePackageMode( sep = ";"; } - this->Makefile->AddDefinition(consideredConfigsVar, - consideredConfigFiles.c_str()); + this->Makefile->AddDefinition(consideredConfigsVar, consideredConfigFiles); - this->Makefile->AddDefinition(consideredVersionsVar, - consideredVersions.c_str()); + this->Makefile->AddDefinition(consideredVersionsVar, consideredVersions); return result; } @@ -1612,8 +1612,8 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file, this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT"); // Set the input variables. - this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name.c_str()); - this->Makefile->AddDefinition("PACKAGE_FIND_VERSION", this->Version.c_str()); + this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name); + this->Makefile->AddDefinition("PACKAGE_FIND_VERSION", this->Version); char buf[64]; sprintf(buf, "%u", this->VersionMajor); this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf); @@ -1690,7 +1690,7 @@ void cmFindPackageCommand::StoreVersionFound() if (this->VersionFound.empty()) { this->Makefile->RemoveDefinition(ver); } else { - this->Makefile->AddDefinition(ver, this->VersionFound.c_str()); + this->Makefile->AddDefinition(ver, this->VersionFound); } // Store the version components. diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx index e3918b5..06dce2c 100644 --- a/Source/cmForEachCommand.cxx +++ b/Source/cmForEachCommand.cxx @@ -53,7 +53,7 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, for (std::string const& arg : cmMakeRange(this->Args).advance(1)) { // set the variable to the loop value - mf.AddDefinition(this->Args[0], arg.c_str()); + mf.AddDefinition(this->Args[0], arg); // Invoke all the functions that were collected in the block. cmExecutionStatus status(mf); for (cmListFileFunction const& func : this->Functions) { @@ -62,12 +62,12 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, if (status.GetReturnInvoked()) { inStatus.SetReturnInvoked(); // restore the variable to its prior value - mf.AddDefinition(this->Args[0], oldDef.c_str()); + mf.AddDefinition(this->Args[0], oldDef); return true; } if (status.GetBreakInvoked()) { // restore the variable to its prior value - mf.AddDefinition(this->Args[0], oldDef.c_str()); + mf.AddDefinition(this->Args[0], oldDef); return true; } if (status.GetContinueInvoked()) { @@ -80,7 +80,7 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, } // restore the variable to its prior value - mf.AddDefinition(this->Args[0], oldDef.c_str()); + mf.AddDefinition(this->Args[0], oldDef); return true; } // close out a nested foreach diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 8b664ad..6afd31a 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -55,20 +55,20 @@ bool cmFunctionHelperCommand::operator()( // set the value of argc std::ostringstream strStream; strStream << expandedArgs.size(); - makefile.AddDefinition("ARGC", strStream.str().c_str()); + makefile.AddDefinition("ARGC", strStream.str()); makefile.MarkVariableAsUsed("ARGC"); // set the values for ARGV0 ARGV1 ... for (unsigned int t = 0; t < expandedArgs.size(); ++t) { std::ostringstream tmpStream; tmpStream << "ARGV" << t; - makefile.AddDefinition(tmpStream.str(), expandedArgs[t].c_str()); + makefile.AddDefinition(tmpStream.str(), expandedArgs[t]); makefile.MarkVariableAsUsed(tmpStream.str()); } // define the formal arguments for (unsigned int j = 1; j < this->Args.size(); ++j) { - makefile.AddDefinition(this->Args[j], expandedArgs[j - 1].c_str()); + makefile.AddDefinition(this->Args[j], expandedArgs[j - 1]); } // define ARGV and ARGN @@ -76,9 +76,9 @@ bool cmFunctionHelperCommand::operator()( std::vector<std::string>::const_iterator eit = expandedArgs.begin() + (this->Args.size() - 1); std::string argnDef = cmJoin(cmMakeRange(eit, expandedArgs.end()), ";"); - makefile.AddDefinition("ARGV", argvDef.c_str()); + makefile.AddDefinition("ARGV", argvDef); makefile.MarkVariableAsUsed("ARGV"); - makefile.AddDefinition("ARGN", argnDef.c_str()); + makefile.AddDefinition("ARGN", argnDef); makefile.MarkVariableAsUsed("ARGN"); // Invoke all the functions that were collected in the block. diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx index fc82fee..8538944 100644 --- a/Source/cmGetCMakePropertyCommand.cxx +++ b/Source/cmGetCMakePropertyCommand.cxx @@ -46,7 +46,7 @@ bool cmGetCMakePropertyCommand::InitialPass( } } - this->Makefile->AddDefinition(variable, output.c_str()); + this->Makefile->AddDefinition(variable, output); return true; } diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx index a92eb71..98ccb0a 100644 --- a/Source/cmGetDirectoryPropertyCommand.cxx +++ b/Source/cmGetDirectoryPropertyCommand.cxx @@ -66,7 +66,7 @@ bool cmGetDirectoryPropertyCommand::InitialPass( return false; } std::string const& output = dir->GetSafeDefinition(*i); - this->Makefile->AddDefinition(variable, output.c_str()); + this->Makefile->AddDefinition(variable, output); return true; } @@ -97,9 +97,5 @@ bool cmGetDirectoryPropertyCommand::InitialPass( void cmGetDirectoryPropertyCommand::StoreResult(std::string const& variable, const char* prop) { - if (prop) { - this->Makefile->AddDefinition(variable, prop); - return; - } - this->Makefile->AddDefinition(variable, ""); + this->Makefile->AddDefinition(variable, prop ? prop : ""); } diff --git a/Source/cmGetFilenameComponentCommand.cxx b/Source/cmGetFilenameComponentCommand.cxx index 163b4c8..fc82535 100644 --- a/Source/cmGetFilenameComponentCommand.cxx +++ b/Source/cmGetFilenameComponentCommand.cxx @@ -128,9 +128,9 @@ bool cmGetFilenameComponentCommand::InitialPass( args[2] == "PATH" ? cmStateEnums::FILEPATH : cmStateEnums::STRING); } else { if (!programArgs.empty() && !storeArgs.empty()) { - this->Makefile->AddDefinition(storeArgs, programArgs.c_str()); + this->Makefile->AddDefinition(storeArgs, programArgs); } - this->Makefile->AddDefinition(args.front(), result.c_str()); + this->Makefile->AddDefinition(args.front(), result); } return true; diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 039f439..de462ed 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -121,7 +121,7 @@ bool cmGetPropertyCommand::InitialPass(std::vector<std::string> const& args, } else { output = "NOTFOUND"; } - this->Makefile->AddDefinition(this->Variable, output.c_str()); + this->Makefile->AddDefinition(this->Variable, output); } else if (this->InfoType == OutFullDoc) { // Lookup full documentation. std::string output; @@ -132,7 +132,7 @@ bool cmGetPropertyCommand::InitialPass(std::vector<std::string> const& args, } else { output = "NOTFOUND"; } - this->Makefile->AddDefinition(this->Variable, output.c_str()); + this->Makefile->AddDefinition(this->Variable, output); } else if (this->InfoType == OutDefined) { // Lookup if the property is defined if (this->Makefile->GetState()->GetPropertyDefinition(this->PropertyName, diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx index 75879a5..a16076d 100644 --- a/Source/cmGetSourceFilePropertyCommand.cxx +++ b/Source/cmGetSourceFilePropertyCommand.cxx @@ -25,7 +25,7 @@ bool cmGetSourceFilePropertyCommand::InitialPass( } if (sf) { if (args[2] == "LANGUAGE") { - this->Makefile->AddDefinition(var, sf->GetLanguage().c_str()); + this->Makefile->AddDefinition(var, sf->GetLanguage()); return true; } const char* prop = nullptr; diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index fc0e9c6..07aaf02 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -75,9 +75,9 @@ bool cmGetTargetPropertyCommand::InitialPass( } } if (prop_exists) { - this->Makefile->AddDefinition(var, prop.c_str()); + this->Makefile->AddDefinition(var, prop); return true; } - this->Makefile->AddDefinition(var, (var + "-NOTFOUND").c_str()); + this->Makefile->AddDefinition(var, var + "-NOTFOUND"); return true; } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index baa8559..7b8ffc5 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -525,7 +525,7 @@ void cmGlobalGenerator::EnableLanguage( rootBin += cmVersion::GetCMakeVersion(); // set the dir for parent files so they can be used by modules - mf->AddDefinition("CMAKE_PLATFORM_INFO_DIR", rootBin.c_str()); + mf->AddDefinition("CMAKE_PLATFORM_INFO_DIR", rootBin); if (!this->CMakeInstance->GetIsInTryCompile()) { // Keep a mark in the cache to indicate that we've initialized the @@ -585,8 +585,7 @@ void cmGlobalGenerator::EnableLanguage( windowsVersionString << osviex.dwMajorVersion << "." << osviex.dwMinorVersion << "." << osviex.dwBuildNumber; - mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", - windowsVersionString.str().c_str()); + mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString.str()); #endif // Read the DetermineSystem file std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake"); diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index b69dea0..7cfbea6 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -111,7 +111,7 @@ bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts, mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", gbuild.c_str(), "build program to use", cmStateEnums::INTERNAL, true); - mf->AddDefinition("CMAKE_SYSTEM_VERSION", tsp.c_str()); + mf->AddDefinition("CMAKE_SYSTEM_VERSION", tsp); return true; } diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index 7b58389..483d4ab 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -69,9 +69,9 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage( rc = trc; } mf->AddDefinition("MSYS", "1"); - mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str()); - mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str()); - mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str()); + mf->AddDefinition("CMAKE_GENERATOR_CC", gcc); + mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx); + mf->AddDefinition("CMAKE_GENERATOR_RC", rc); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); if (!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile() && diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx index e218b4b..d9fc505 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.cxx +++ b/Source/cmGlobalMinGWMakefileGenerator.cxx @@ -44,9 +44,9 @@ void cmGlobalMinGWMakefileGenerator::EnableLanguage( if (!trc.empty()) { rc = trc; } - mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str()); - mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str()); - mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str()); + mf->AddDefinition("CMAKE_GENERATOR_CC", gcc); + mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx); + mf->AddDefinition("CMAKE_GENERATOR_RC", rc); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); } diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 55374a4..4a3cadd 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -445,7 +445,7 @@ bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf) this->DefaultPlatformName = "Tegra-Android"; this->DefaultPlatformToolset = "Default"; this->NsightTegraVersion = v; - mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v.c_str()); + mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v); } return true; @@ -659,8 +659,7 @@ bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf) if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) { return false; } - mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND", - this->GetMSBuildCommand().c_str()); + mf->AddDefinition("CMAKE_VS_MSBUILD_COMMAND", this->GetMSBuildCommand()); return true; } diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 6509b56..cd48474 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -182,7 +182,7 @@ void cmGlobalVisualStudio14Generator::SetWindowsTargetPlatformVersion( mf->DisplayStatus(e.str(), -1); } mf->AddDefinition("CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION", - this->WindowsTargetPlatformVersion.c_str()); + this->WindowsTargetPlatformVersion); } bool cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 8764ee4..8401efb 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -121,8 +121,7 @@ bool cmGlobalVisualStudio7Generator::FindMakeProgram(cmMakefile* mf) if (!this->cmGlobalVisualStudioGenerator::FindMakeProgram(mf)) { return false; } - mf->AddDefinition("CMAKE_VS_DEVENV_COMMAND", - this->GetDevEnvCommand().c_str()); + mf->AddDefinition("CMAKE_VS_DEVENV_COMMAND", this->GetDevEnvCommand()); return true; } @@ -268,7 +267,7 @@ bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s, cmMakefile* mf) { mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION", - this->GetIntelProjectVersion().c_str()); + this->GetIntelProjectVersion()); return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf); } diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 85ddc85..cc6e421 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -54,8 +54,7 @@ void cmGlobalVisualStudio8Generator::EnableLanguage( void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf) { if (this->TargetsWindowsCE()) { - mf->AddDefinition("CMAKE_VS_WINCE_VERSION", - this->WindowsCEVersion.c_str()); + mf->AddDefinition("CMAKE_VS_WINCE_VERSION", this->WindowsCEVersion); } } diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index cd0355f..ba541a9 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -57,7 +57,7 @@ void cmGlobalVisualStudioGenerator::EnableLanguage( std::vector<std::string> const& lang, cmMakefile* mf, bool optional) { mf->AddDefinition("CMAKE_VS_PLATFORM_NAME_DEFAULT", - this->DefaultPlatformName.c_str()); + this->DefaultPlatformName); this->cmGlobalGenerator::EnableLanguage(lang, mf, optional); } @@ -69,7 +69,7 @@ bool cmGlobalVisualStudioGenerator::SetGeneratorPlatform(std::string const& p, } else if (this->GetPlatformName() == "Itanium") { mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE"); } - mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName().c_str()); + mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName()); return this->cmGlobalGenerator::SetGeneratorPlatform(p, mf); } @@ -488,7 +488,7 @@ bool cmGlobalVisualStudioGenerator::FindMakeProgram(cmMakefile* mf) // directly instead of needing a helper module to do it, so we // do not actually need to put CMAKE_MAKE_PROGRAM into the cache. if (cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM"))) { - mf->AddDefinition("CMAKE_MAKE_PROGRAM", this->GetVSMakeProgram().c_str()); + mf->AddDefinition("CMAKE_MAKE_PROGRAM", this->GetVSMakeProgram()); } return true; } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index d99a906..8f4ae62 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -241,8 +241,7 @@ bool cmGlobalXCodeGenerator::FindMakeProgram(cmMakefile* mf) // directly instead of needing a helper module to do it, so we // do not actually need to put CMAKE_MAKE_PROGRAM into the cache. if (cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM"))) { - mf->AddDefinition("CMAKE_MAKE_PROGRAM", - this->GetXcodeBuildCommand().c_str()); + mf->AddDefinition("CMAKE_MAKE_PROGRAM", this->GetXcodeBuildCommand()); } return true; } @@ -283,8 +282,7 @@ bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts, } this->GeneratorToolset = ts; if (!this->GeneratorToolset.empty()) { - mf->AddDefinition("CMAKE_XCODE_PLATFORM_TOOLSET", - this->GeneratorToolset.c_str()); + mf->AddDefinition("CMAKE_XCODE_PLATFORM_TOOLSET", this->GeneratorToolset); } return true; } @@ -293,7 +291,7 @@ void cmGlobalXCodeGenerator::EnableLanguage( std::vector<std::string> const& lang, cmMakefile* mf, bool optional) { mf->AddDefinition("XCODE", "1"); - mf->AddDefinition("XCODE_VERSION", this->VersionString.c_str()); + mf->AddDefinition("XCODE_VERSION", this->VersionString); if (!mf->GetDefinition("CMAKE_CONFIGURATION_TYPES")) { mf->AddCacheDefinition( "CMAKE_CONFIGURATION_TYPES", "Debug;Release;MinSizeRel;RelWithDebInfo", diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index a2e665f..d024256 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -222,7 +222,7 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args) value += varArgsExpanded[item]; } - this->Makefile->AddDefinition(variableName, value.c_str()); + this->Makefile->AddDefinition(variableName, value); return true; } @@ -246,7 +246,7 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args) std::string::size_type(listString.empty() || args.empty()); listString += &";"[offset] + cmJoin(cmMakeRange(args).advance(2), ";"); - this->Makefile->AddDefinition(listName, listString.c_str()); + this->Makefile->AddDefinition(listName, listString); return true; } @@ -271,7 +271,7 @@ bool cmListCommand::HandlePrependCommand(std::vector<std::string> const& args) listString.insert(0, cmJoin(cmMakeRange(args).advance(2), ";") + &";"[offset]); - this->Makefile->AddDefinition(listName, listString.c_str()); + this->Makefile->AddDefinition(listName, listString); return true; } @@ -299,7 +299,7 @@ bool cmListCommand::HandlePopBackCommand(std::vector<std::string> const& args) // Ok, assign elements to be removed to the given variables for (; !varArgsExpanded.empty() && ai != args.cend(); ++ai) { assert(!ai->empty()); - this->Makefile->AddDefinition(*ai, varArgsExpanded.back().c_str()); + this->Makefile->AddDefinition(*ai, varArgsExpanded.back()); varArgsExpanded.pop_back(); } // Undefine the rest variables if the list gets empty earlier... @@ -308,8 +308,7 @@ bool cmListCommand::HandlePopBackCommand(std::vector<std::string> const& args) } } - this->Makefile->AddDefinition(listName, - cmJoin(varArgsExpanded, ";").c_str()); + this->Makefile->AddDefinition(listName, cmJoin(varArgsExpanded, ";")); } else if (ai != args.cend()) { // The list is empty, but some args were given @@ -347,7 +346,7 @@ bool cmListCommand::HandlePopFrontCommand(std::vector<std::string> const& args) auto vi = varArgsExpanded.begin(); for (; vi != varArgsExpanded.end() && ai != args.cend(); ++ai, ++vi) { assert(!ai->empty()); - this->Makefile->AddDefinition(*ai, vi->c_str()); + this->Makefile->AddDefinition(*ai, *vi); } varArgsExpanded.erase(varArgsExpanded.begin(), vi); // Undefine the rest variables if the list gets empty earlier... @@ -356,8 +355,7 @@ bool cmListCommand::HandlePopFrontCommand(std::vector<std::string> const& args) } } - this->Makefile->AddDefinition(listName, - cmJoin(varArgsExpanded, ";").c_str()); + this->Makefile->AddDefinition(listName, cmJoin(varArgsExpanded, ";")); } else if (ai != args.cend()) { // The list is empty, but some args were given @@ -391,7 +389,7 @@ bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args) if (it != varArgsExpanded.end()) { std::ostringstream indexStream; indexStream << std::distance(varArgsExpanded.begin(), it); - this->Makefile->AddDefinition(variableName, indexStream.str().c_str()); + this->Makefile->AddDefinition(variableName, indexStream.str()); return true; } @@ -437,7 +435,7 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args) args.end()); std::string value = cmJoin(varArgsExpanded, ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -465,7 +463,7 @@ bool cmListCommand::HandleJoinCommand(std::vector<std::string> const& args) std::string value = cmJoin(cmMakeRange(varArgsExpanded.begin(), varArgsExpanded.end()), glue); - this->Makefile->AddDefinition(variableName, value.c_str()); + this->Makefile->AddDefinition(variableName, value); return true; } @@ -494,7 +492,7 @@ bool cmListCommand::HandleRemoveItemCommand( cmRemoveMatching(varArgsExpanded, cmMakeRange(remBegin, remEnd)); std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -515,7 +513,7 @@ bool cmListCommand::HandleReverseCommand(std::vector<std::string> const& args) std::string value = cmJoin(cmReverseRange(varArgsExpanded), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -540,7 +538,7 @@ bool cmListCommand::HandleRemoveDuplicatesCommand( std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -1091,7 +1089,7 @@ bool cmListCommand::HandleTransformCommand( } this->Makefile->AddDefinition(command.OutputName, - cmJoin(varArgsExpanded, ";").c_str()); + cmJoin(varArgsExpanded, ";")); return true; } @@ -1300,7 +1298,7 @@ bool cmListCommand::HandleSortCommand(std::vector<std::string> const& args) } std::string value = cmJoin(varArgsExpanded, ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -1349,7 +1347,7 @@ bool cmListCommand::HandleSublistCommand(std::vector<std::string> const& args) : size_type(start + length); std::vector<std::string> sublist(varArgsExpanded.begin() + start, varArgsExpanded.begin() + end); - this->Makefile->AddDefinition(variableName, cmJoin(sublist, ";").c_str()); + this->Makefile->AddDefinition(variableName, cmJoin(sublist, ";")); return true; } @@ -1406,7 +1404,7 @@ bool cmListCommand::HandleRemoveAtCommand(std::vector<std::string> const& args) std::vector<std::string>::const_iterator argsBegin = varArgsExpanded.begin(); std::string value = cmJoin(cmMakeRange(argsBegin, argsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } @@ -1500,6 +1498,6 @@ bool cmListCommand::FilterRegex(std::vector<std::string> const& args, std::remove_if(argsBegin, argsEnd, MatchesRegex(regex, includeMatches)); std::string value = cmJoin(cmMakeRange(argsBegin, newArgsEnd), ";"); - this->Makefile->AddDefinition(listName, value.c_str()); + this->Makefile->AddDefinition(listName, value); return true; } diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx index b1fee8d..3fd7343 100644 --- a/Source/cmLoadCacheCommand.cxx +++ b/Source/cmLoadCacheCommand.cxx @@ -153,7 +153,7 @@ void cmLoadCacheCommand::CheckLine(const char* line) // prefix. var = this->Prefix + var; if (!value.empty()) { - this->Makefile->AddDefinition(var, value.c_str()); + this->Makefile->AddDefinition(var, value); } else { this->Makefile->RemoveDefinition(var); } diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index 78f4f83..5ae660a 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -230,7 +230,7 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args, } // Report what file was loaded for this command. - this->Makefile->AddDefinition(reportVar, fullPath.c_str()); + this->Makefile->AddDefinition(reportVar, fullPath); // find the init function std::string initFuncName = args[0] + "Init"; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index d177278..242ffe3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2973,7 +2973,7 @@ void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target, // back to the directory-level values set by the user. cmMakefile* mf = this->Makefile; cmMakefile::ScopePushPop varScope(mf); - mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName.c_str()); + mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName); cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING"); cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE"); cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER"); @@ -3012,7 +3012,7 @@ void cmLocalGenerator::GenerateFrameworkInfoPList( // back to the directory-level values set by the user. cmMakefile* mf = this->Makefile; cmMakefile::ScopePushPop varScope(mf); - mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName.c_str()); + mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName); cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE"); cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER"); cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING"); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1867809..0fb3237 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -557,8 +557,9 @@ void cmMakefile::IncludeScope::EnforceCMP0011() bool cmMakefile::ReadDependentFile(const std::string& filename, bool noPolicyScope) { - this->AddDefinition("CMAKE_PARENT_LIST_FILE", - this->GetDefinition("CMAKE_CURRENT_LIST_FILE")); + if (const char* def = this->GetDefinition("CMAKE_CURRENT_LIST_FILE")) { + this->AddDefinition("CMAKE_PARENT_LIST_FILE", def); + } std::string filenametoread = cmSystemTools::CollapseFullPath( filename, this->GetCurrentSourceDirectory()); @@ -641,9 +642,9 @@ void cmMakefile::ReadListFile(cmListFile const& listFile, this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE"); std::string currentFile = this->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE"); - this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread.c_str()); + this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread); this->AddDefinition("CMAKE_CURRENT_LIST_DIR", - cmSystemTools::GetFilenamePath(filenametoread).c_str()); + cmSystemTools::GetFilenamePath(filenametoread)); this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE"); @@ -664,10 +665,10 @@ void cmMakefile::ReadListFile(cmListFile const& listFile, } this->CheckForUnusedVariables(); - this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str()); - this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str()); + this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile); + this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile); this->AddDefinition("CMAKE_CURRENT_LIST_DIR", - cmSystemTools::GetFilenamePath(currentFile).c_str()); + cmSystemTools::GetFilenamePath(currentFile)); this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR"); @@ -1535,7 +1536,7 @@ void cmMakefile::Configure() cmSystemTools::MakeDirectory(filesDir); assert(cmSystemTools::FileExists(currentStart, true)); - this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str()); + this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart); cmListFile listFile; if (!listFile.ParseFile(currentStart.c_str(), this->GetMessenger(), @@ -1783,12 +1784,8 @@ void cmMakefile::AddSystemIncludeDirectories(const std::set<std::string>& incs) } } -void cmMakefile::AddDefinition(const std::string& name, const char* value) +void cmMakefile::AddDefinition(const std::string& name, cm::string_view value) { - if (!value) { - return; - } - if (this->VariableInitialized(name)) { this->LogUnused("changing definition", name); } @@ -1798,7 +1795,7 @@ void cmMakefile::AddDefinition(const std::string& name, const char* value) cmVariableWatch* vv = this->GetVariableWatch(); if (vv) { vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS, - value, this); + value.data(), this); } #endif } @@ -3273,20 +3270,20 @@ std::string const& cmMakefile::GetHomeOutputDirectory() const void cmMakefile::SetScriptModeFile(std::string const& scriptfile) { - this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile.c_str()); + this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile); } void cmMakefile::SetArgcArgv(const std::vector<std::string>& args) { std::ostringstream strStream; strStream << args.size(); - this->AddDefinition("CMAKE_ARGC", strStream.str().c_str()); + this->AddDefinition("CMAKE_ARGC", strStream.str()); // this->MarkVariableAsUsed("CMAKE_ARGC"); for (unsigned int t = 0; t < args.size(); ++t) { std::ostringstream tmpStream; tmpStream << "CMAKE_ARGV" << t; - this->AddDefinition(tmpStream.str(), args[t].c_str()); + this->AddDefinition(tmpStream.str(), args[t]); // this->MarkVariableAsUsed(tmpStream.str().c_str()); } } @@ -3367,8 +3364,9 @@ void cmMakefile::AddTargetObject(std::string const& tgtName, void cmMakefile::EnableLanguage(std::vector<std::string> const& lang, bool optional) { - this->AddDefinition("CMAKE_CFG_INTDIR", - this->GetGlobalGenerator()->GetCMakeCFGIntDir()); + if (const char* def = this->GetGlobalGenerator()->GetCMakeCFGIntDir()) { + this->AddDefinition("CMAKE_CFG_INTDIR", def); + } // If RC is explicitly listed we need to do it after other languages. // On some platforms we enable RC implicitly while enabling others. // Do not let that look like recursive enable_language(RC). @@ -4220,7 +4218,7 @@ void cmMakefile::StoreMatches(cmsys::RegularExpression& re) std::string const& m = re.match(i); if (!m.empty()) { std::string const& var = matchVariables[i]; - this->AddDefinition(var, m.c_str()); + this->AddDefinition(var, m); this->MarkVariableAsUsed(var); highest = static_cast<char>('0' + i); } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index e685644..18b81d4 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -17,6 +17,8 @@ #include <unordered_map> #include <vector> +#include "cm_string_view.hxx" + #include "cmAlgorithms.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" @@ -263,11 +265,11 @@ public: * Add a variable definition to the build. This variable * can be used in CMake to refer to lists, directories, etc. */ - void AddDefinition(const std::string& name, const char* value); + void AddDefinition(const std::string& name, cm::string_view value); /** * Add bool variable definition to the build. */ - void AddDefinitionBool(const std::string& name, bool value); + void AddDefinitionBool(const std::string& name, bool); //! Add a definition to this makefile and the global cmake cache. void AddCacheDefinition(const std::string& name, const char* value, const char* doc, cmStateEnums::CacheEntryType type, diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx index 5213432..0f8aef7 100644 --- a/Source/cmParseArgumentsCommand.cxx +++ b/Source/cmParseArgumentsCommand.cxx @@ -75,7 +75,7 @@ static void PassParsedArguments( for (auto const& iter : singleValArgs) { if (!iter.second.empty()) { - makefile.AddDefinition(prefix + iter.first, iter.second.c_str()); + makefile.AddDefinition(prefix + iter.first, iter.second); } else { makefile.RemoveDefinition(prefix + iter.first); } @@ -84,7 +84,7 @@ static void PassParsedArguments( for (auto const& iter : multiValArgs) { if (!iter.second.empty()) { makefile.AddDefinition(prefix + iter.first, - JoinList(iter.second, parseFromArgV).c_str()); + JoinList(iter.second, parseFromArgV)); } else { makefile.RemoveDefinition(prefix + iter.first); } @@ -92,15 +92,14 @@ static void PassParsedArguments( if (!unparsed.empty()) { makefile.AddDefinition(prefix + "UNPARSED_ARGUMENTS", - JoinList(unparsed, parseFromArgV).c_str()); + JoinList(unparsed, parseFromArgV)); } else { makefile.RemoveDefinition(prefix + "UNPARSED_ARGUMENTS"); } if (!keywordsMissingValues.empty()) { - makefile.AddDefinition( - prefix + "KEYWORDS_MISSING_VALUES", - cmJoin(cmMakeRange(keywordsMissingValues), ";").c_str()); + makefile.AddDefinition(prefix + "KEYWORDS_MISSING_VALUES", + cmJoin(cmMakeRange(keywordsMissingValues), ";")); } else { makefile.RemoveDefinition(prefix + "KEYWORDS_MISSING_VALUES"); } diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index e3d3bd8..1159ef7 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -45,12 +45,12 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, this->Makefile->GetCurrentSourceDirectory().c_str(), "Value Computed by CMake", cmStateEnums::STATIC); - this->Makefile->AddDefinition( - "PROJECT_BINARY_DIR", this->Makefile->GetCurrentBinaryDirectory().c_str()); - this->Makefile->AddDefinition( - "PROJECT_SOURCE_DIR", this->Makefile->GetCurrentSourceDirectory().c_str()); + this->Makefile->AddDefinition("PROJECT_BINARY_DIR", + this->Makefile->GetCurrentBinaryDirectory()); + this->Makefile->AddDefinition("PROJECT_SOURCE_DIR", + this->Makefile->GetCurrentSourceDirectory()); - this->Makefile->AddDefinition("PROJECT_NAME", projectName.c_str()); + this->Makefile->AddDefinition("PROJECT_NAME", projectName); // Set the CMAKE_PROJECT_NAME variable to be the highest-level // project name in the tree. If there are two project commands @@ -60,7 +60,7 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, // will work. if (!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME") || (this->Makefile->IsRootMakefile())) { - this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", projectName.c_str()); + this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", projectName); this->Makefile->AddCacheDefinition( "CMAKE_PROJECT_NAME", projectName.c_str(), "Value Computed by CMake", cmStateEnums::STATIC); @@ -258,24 +258,24 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, std::string vv; vv = projectName + "_VERSION"; - this->Makefile->AddDefinition("PROJECT_VERSION", version_string.c_str()); - this->Makefile->AddDefinition(vv, version_string.c_str()); + this->Makefile->AddDefinition("PROJECT_VERSION", version_string); + this->Makefile->AddDefinition(vv, version_string); vv = projectName + "_VERSION_MAJOR"; this->Makefile->AddDefinition("PROJECT_VERSION_MAJOR", - version_components[0].c_str()); - this->Makefile->AddDefinition(vv, version_components[0].c_str()); + version_components[0]); + this->Makefile->AddDefinition(vv, version_components[0]); vv = projectName + "_VERSION_MINOR"; this->Makefile->AddDefinition("PROJECT_VERSION_MINOR", - version_components[1].c_str()); - this->Makefile->AddDefinition(vv, version_components[1].c_str()); + version_components[1]); + this->Makefile->AddDefinition(vv, version_components[1]); vv = projectName + "_VERSION_PATCH"; this->Makefile->AddDefinition("PROJECT_VERSION_PATCH", - version_components[2].c_str()); - this->Makefile->AddDefinition(vv, version_components[2].c_str()); + version_components[2]); + this->Makefile->AddDefinition(vv, version_components[2]); vv = projectName + "_VERSION_TWEAK"; this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK", - version_components[3].c_str()); - this->Makefile->AddDefinition(vv, version_components[3].c_str()); + version_components[3]); + this->Makefile->AddDefinition(vv, version_components[3]); // Also, try set top level variables TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION", version_string.c_str()); TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MAJOR", @@ -327,14 +327,12 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args, } } - this->Makefile->AddDefinition("PROJECT_DESCRIPTION", description.c_str()); - this->Makefile->AddDefinition(projectName + "_DESCRIPTION", - description.c_str()); + this->Makefile->AddDefinition("PROJECT_DESCRIPTION", description); + this->Makefile->AddDefinition(projectName + "_DESCRIPTION", description); TopLevelCMakeVarCondSet("CMAKE_PROJECT_DESCRIPTION", description.c_str()); - this->Makefile->AddDefinition("PROJECT_HOMEPAGE_URL", homepage.c_str()); - this->Makefile->AddDefinition(projectName + "_HOMEPAGE_URL", - homepage.c_str()); + this->Makefile->AddDefinition("PROJECT_HOMEPAGE_URL", homepage); + this->Makefile->AddDefinition(projectName + "_HOMEPAGE_URL", homepage); TopLevelCMakeVarCondSet("CMAKE_PROJECT_HOMEPAGE_URL", homepage.c_str()); if (languages.empty()) { diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index 9a764c6..f5852a9 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -89,6 +89,6 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args, } // Store the final list of source files. - this->Makefile->AddDefinition(sourceList, sourceListValue.c_str()); + this->Makefile->AddDefinition(sourceList, sourceListValue); return true; } diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index 2223e2d..361d7b3 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -132,7 +132,7 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args, } // Store the final list of source files and headers. - this->Makefile->AddDefinition(sourceList, sourceListValue.c_str()); - this->Makefile->AddDefinition(headerList, headerListValue.c_str()); + this->Makefile->AddDefinition(sourceList, sourceListValue); + this->Makefile->AddDefinition(headerList, headerListValue); return true; } diff --git a/Source/cmRemoveCommand.cxx b/Source/cmRemoveCommand.cxx index a64ad8c..d0ee4d4 100644 --- a/Source/cmRemoveCommand.cxx +++ b/Source/cmRemoveCommand.cxx @@ -52,7 +52,7 @@ bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args, } // add the definition - this->Makefile->AddDefinition(variable, value.c_str()); + this->Makefile->AddDefinition(variable, value); return true; } diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx index 28cbdc0..ab4a0c7 100644 --- a/Source/cmSeparateArgumentsCommand.cxx +++ b/Source/cmSeparateArgumentsCommand.cxx @@ -69,7 +69,7 @@ bool cmSeparateArgumentsCommand::InitialPass( if (const char* def = this->Makefile->GetDefinition(var)) { std::string value = def; std::replace(value.begin(), value.end(), ' ', ';'); - this->Makefile->AddDefinition(var, value.c_str()); + this->Makefile->AddDefinition(var, value); } } else { // Parse the command line. @@ -97,7 +97,7 @@ bool cmSeparateArgumentsCommand::InitialPass( value += si; } } - this->Makefile->AddDefinition(var, value.c_str()); + this->Makefile->AddDefinition(var, value); } return true; diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index 41555e8..b36878c 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -154,7 +154,7 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args, type, force); } else { // add the definition - this->Makefile->AddDefinition(variable, value.c_str()); + this->Makefile->AddDefinition(variable, value); } return true; } diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 4ad0870..259d92a 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -123,7 +123,7 @@ bool cmStringCommand::HandleHashCommand(std::vector<std::string> const& args) std::unique_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); if (hash) { std::string out = hash->HashString(args[2]); - this->Makefile->AddDefinition(args[1], out.c_str()); + this->Makefile->AddDefinition(args[1], out); return true; } return false; @@ -153,7 +153,7 @@ bool cmStringCommand::HandleToUpperLowerCommand( } // Store the output in the provided variable. - this->Makefile->AddDefinition(outvar, output.c_str()); + this->Makefile->AddDefinition(outvar, output); return true; } @@ -179,7 +179,7 @@ bool cmStringCommand::HandleAsciiCommand(std::vector<std::string> const& args) } } // Store the output in the provided variable. - this->Makefile->AddDefinition(outvar, output.c_str()); + this->Makefile->AddDefinition(outvar, output); return true; } @@ -216,7 +216,7 @@ bool cmStringCommand::HandleConfigureCommand( this->Makefile->ConfigureString(args[1], output, atOnly, escapeQuotes); // Store the output in the provided variable. - this->Makefile->AddDefinition(args[2], output.c_str()); + this->Makefile->AddDefinition(args[2], output); return true; } @@ -295,7 +295,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args) } // Store the output in the provided variable. - this->Makefile->AddDefinition(outvar, output.c_str()); + this->Makefile->AddDefinition(outvar, output); return true; } @@ -342,7 +342,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args) } // Store the output in the provided variable. - this->Makefile->AddDefinition(outvar, output.c_str()); + this->Makefile->AddDefinition(outvar, output); return true; } @@ -383,7 +383,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args) } // Store the output in the provided variable. - this->Makefile->AddDefinition(outvar, output.c_str()); + this->Makefile->AddDefinition(outvar, output); return true; } @@ -430,7 +430,7 @@ bool cmStringCommand::HandleFindCommand(std::vector<std::string> const& args) if (std::string::npos != pos) { std::ostringstream s; s << pos; - this->Makefile->AddDefinition(outvar, s.str().c_str()); + this->Makefile->AddDefinition(outvar, s.str()); return true; } @@ -505,7 +505,7 @@ bool cmStringCommand::HandleReplaceCommand( cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(), replaceExpression.c_str()); - this->Makefile->AddDefinition(variableName, input.c_str()); + this->Makefile->AddDefinition(variableName, input); return true; } @@ -538,8 +538,7 @@ bool cmStringCommand::HandleSubstringCommand( return false; } - this->Makefile->AddDefinition(variableName, - stringValue.substr(begin, end).c_str()); + this->Makefile->AddDefinition(variableName, stringValue.substr(begin, end)); return true; } @@ -581,7 +580,7 @@ bool cmStringCommand::HandleAppendCommand(std::vector<std::string> const& args) value = oldValue; } value += cmJoin(cmMakeRange(args).advance(2), std::string()); - this->Makefile->AddDefinition(variable, value.c_str()); + this->Makefile->AddDefinition(variable, value); return true; } @@ -605,7 +604,7 @@ bool cmStringCommand::HandlePrependCommand( if (oldValue) { value += oldValue; } - this->Makefile->AddDefinition(variable, value.c_str()); + this->Makefile->AddDefinition(variable, value); return true; } @@ -637,7 +636,7 @@ bool cmStringCommand::joinImpl(std::vector<std::string> const& args, // both `CONCAT` and `JOIN` sub-commands. std::string value = cmJoin(cmMakeRange(args).advance(varIdx + 1), glue); - this->Makefile->AddDefinition(variableName, value.c_str()); + this->Makefile->AddDefinition(variableName, value); return true; } @@ -653,7 +652,7 @@ bool cmStringCommand::HandleMakeCIdentifierCommand( const std::string& variableName = args[2]; this->Makefile->AddDefinition(variableName, - cmSystemTools::MakeCidentifier(input).c_str()); + cmSystemTools::MakeCidentifier(input)); return true; } @@ -672,7 +671,7 @@ bool cmStringCommand::HandleGenexStripCommand( const std::string& variableName = args[2]; - this->Makefile->AddDefinition(variableName, result.c_str()); + this->Makefile->AddDefinition(variableName, result); return true; } @@ -711,8 +710,8 @@ bool cmStringCommand::HandleStripCommand(std::vector<std::string> const& args) outLength = endPos - startPos + 1; } - this->Makefile->AddDefinition( - variableName, stringValue.substr(startPos, outLength).c_str()); + this->Makefile->AddDefinition(variableName, + stringValue.substr(startPos, outLength)); return true; } @@ -765,7 +764,7 @@ bool cmStringCommand::HandleRepeatCommand(std::vector<std::string> const& args) break; } - this->Makefile->AddDefinition(variableName, result.c_str()); + this->Makefile->AddDefinition(variableName, result); return true; } @@ -871,7 +870,7 @@ bool cmStringCommand::HandleTimestampCommand( cmTimestamp timestamp; std::string result = timestamp.CurrentTime(formatString, utcFlag); - this->Makefile->AddDefinition(outputVariable, result.c_str()); + this->Makefile->AddDefinition(outputVariable, result); return true; } @@ -954,7 +953,7 @@ bool cmStringCommand::HandleUuidCommand(std::vector<std::string> const& args) uuid = cmSystemTools::UpperCase(uuid); } - this->Makefile->AddDefinition(outputVariable, uuid.c_str()); + this->Makefile->AddDefinition(outputVariable, uuid); return true; #else std::ostringstream e; diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index a92c2a0..ed944ac 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -137,7 +137,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, // now put the output into the variables if (!this->RunOutputVariable.empty()) { this->Makefile->AddDefinition(this->RunOutputVariable, - runOutputContents.c_str()); + runOutputContents); } if (!this->OutputVariable.empty()) { @@ -148,8 +148,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv, if (compileOutput) { runOutputContents = compileOutput + runOutputContents; } - this->Makefile->AddDefinition(this->OutputVariable, - runOutputContents.c_str()); + this->Makefile->AddDefinition(this->OutputVariable, runOutputContents); } } } https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f2ba968ef2a1c46e117dcd8eec34a55775f3d5f4 commit f2ba968ef2a1c46e117dcd8eec34a55775f3d5f4 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Fri Jul 19 11:08:38 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Wed Jul 24 11:11:25 2019 +0200 cmMakefile: Simplify and rename AddDefinitionBool This simplifies the `cmMakefile::AddDefinition` method with bool value overload to call the string based `cmMakefile::AddDefinition` method with either an "ON" or "OFF" string. Also the method is renamed to `cmMakefile::AddDefinitionBool` diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 85040dd..fc319b3 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -360,7 +360,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) cmSystemTools::GetCTestCommand().c_str()); this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME", cmSystemTools::GetCMakeCommand().c_str()); - this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", true); + this->Makefile->AddDefinitionBool("CTEST_RUN_CURRENT_SCRIPT", true); this->SetRunCurrentScript(true); this->UpdateElapsedTime(); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ec4107b..baa8559 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -511,7 +511,7 @@ void cmGlobalGenerator::EnableLanguage( bool fatalError = false; - mf->AddDefinition("RUN_CONFIGURE", true); + mf->AddDefinitionBool("RUN_CONFIGURE", true); std::string rootBin = this->CMakeInstance->GetHomeOutputDirectory(); rootBin += "/CMakeFiles"; diff --git a/Source/cmIncludeGuardCommand.cxx b/Source/cmIncludeGuardCommand.cxx index 505b07c..3b126b0 100644 --- a/Source/cmIncludeGuardCommand.cxx +++ b/Source/cmIncludeGuardCommand.cxx @@ -85,7 +85,7 @@ bool cmIncludeGuardCommand::InitialPass(std::vector<std::string> const& args, status.SetReturnInvoked(); return true; } - mf->AddDefinition(includeGuardVar, true); + mf->AddDefinitionBool(includeGuardVar, true); break; case DIRECTORY: if (CheckIncludeGuardIsSet(mf, includeGuardVar)) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 3177adc..1867809 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1803,6 +1803,11 @@ void cmMakefile::AddDefinition(const std::string& name, const char* value) #endif } +void cmMakefile::AddDefinitionBool(const std::string& name, bool value) +{ + this->AddDefinition(name, value ? "ON" : "OFF"); +} + void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, const char* doc, cmStateEnums::CacheEntryType type, @@ -1848,23 +1853,6 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, this->StateSnapshot.RemoveDefinition(name); } -void cmMakefile::AddDefinition(const std::string& name, bool value) -{ - if (this->VariableInitialized(name)) { - this->LogUnused("changing definition", name); - } - - this->StateSnapshot.SetDefinition(name, value ? "ON" : "OFF"); - -#ifdef CMAKE_BUILD_WITH_CMAKE - cmVariableWatch* vv = this->GetVariableWatch(); - if (vv) { - vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS, - value ? "ON" : "OFF", this); - } -#endif -} - void cmMakefile::CheckForUnusedVariables() const { if (!this->WarnUnused) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 1eca18c..e685644 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -264,17 +264,16 @@ public: * can be used in CMake to refer to lists, directories, etc. */ void AddDefinition(const std::string& name, const char* value); + /** + * Add bool variable definition to the build. + */ + void AddDefinitionBool(const std::string& name, bool value); //! Add a definition to this makefile and the global cmake cache. void AddCacheDefinition(const std::string& name, const char* value, const char* doc, cmStateEnums::CacheEntryType type, bool force = false); /** - * Add bool variable definition to the build. - */ - void AddDefinition(const std::string& name, bool); - - /** * Remove a variable definition from the build. This is not valid * for cache entries, and will only affect the current makefile. */ diff --git a/Source/cmVariableRequiresCommand.cxx b/Source/cmVariableRequiresCommand.cxx index c02157a..9878ff1 100644 --- a/Source/cmVariableRequiresCommand.cxx +++ b/Source/cmVariableRequiresCommand.cxx @@ -42,7 +42,7 @@ bool cmVariableRequiresCommand::InitialPass( // if reqVar is set to true, but requirementsMet is false , then // set reqVar to false. if (!reqVar || (!requirementsMet && this->Makefile->IsOn(reqVar))) { - this->Makefile->AddDefinition(resultVariable, requirementsMet); + this->Makefile->AddDefinitionBool(resultVariable, requirementsMet); } if (!requirementsMet) { https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9b5cc4253135c7811936b05525e013e04a390d02 commit 9b5cc4253135c7811936b05525e013e04a390d02 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Fri Jul 19 10:38:54 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Wed Jul 24 11:11:25 2019 +0200 cmDefinitions: Remove const char* based Set method - Removes `cmDefinitions::Set` method overload that takes a `const char*` value argument. - Updates calls to `cmDefinitions::Set` to use the `cm::string_view` based version instead. diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index b6a08bc..4d8810a 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -32,16 +32,6 @@ public: static bool HasKey(const std::string& key, StackIter begin, StackIter end); - /** Set (or unset if null) a value associated with a key. */ - void Set(const std::string& key, const char* value) - { - if (value) { - this->Set(key, cm::string_view(value)); - } else { - this->Unset(key); - } - } - /** Set a value associated with a key. */ void Set(const std::string& key, cm::string_view value); diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 0b12a65..6f9c935 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -308,8 +308,8 @@ cmStateSnapshot cmState::Reset() pos->Parent = this->VarTree.Root(); pos->Root = this->VarTree.Root(); - pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir.c_str()); - pos->Vars->Set("CMAKE_BINARY_DIR", binDir.c_str()); + pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir); + pos->Vars->Set("CMAKE_BINARY_DIR", binDir); } this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "", diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 63bec71..110ec56 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -222,14 +222,14 @@ bool cmStateSnapshot::IsInitialized(std::string const& name) const } void cmStateSnapshot::SetDefinition(std::string const& name, - std::string const& value) + cm::string_view value) { - this->Position->Vars->Set(name, value.c_str()); + this->Position->Vars->Set(name, value); } void cmStateSnapshot::RemoveDefinition(std::string const& name) { - this->Position->Vars->Set(name, nullptr); + this->Position->Vars->Unset(name); } std::vector<std::string> cmStateSnapshot::UnusedKeys() const @@ -264,7 +264,11 @@ bool cmStateSnapshot::RaiseScope(std::string const& var, const char* varDef) cmDefinitions::Raise(var, this->Position->Vars, this->Position->Root); // Now update the definition in the parent scope. - this->Position->Parent->Set(var, varDef); + if (varDef) { + this->Position->Parent->Set(var, varDef); + } else { + this->Position->Parent->Unset(var); + } return true; } diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h index c315f48..da39127 100644 --- a/Source/cmStateSnapshot.h +++ b/Source/cmStateSnapshot.h @@ -9,6 +9,8 @@ #include <string> #include <vector> +#include "cm_string_view.hxx" + #include "cmLinkedTree.h" #include "cmPolicies.h" #include "cmStateTypes.h" @@ -24,7 +26,7 @@ public: std::string const* GetDefinition(std::string const& name) const; bool IsInitialized(std::string const& name) const; - void SetDefinition(std::string const& name, std::string const& value); + void SetDefinition(std::string const& name, cm::string_view value); void RemoveDefinition(std::string const& name); std::vector<std::string> UnusedKeys() const; std::vector<std::string> ClosureKeys() const; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e268840c0a5db59f97c0fbc77aaae621520b83a3 commit e268840c0a5db59f97c0fbc77aaae621520b83a3 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Fri Jul 19 10:14:59 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Wed Jul 24 11:11:25 2019 +0200 cmDefinitions: Add Unset and cm::string_view based Set methods - The `cmDefinitions::Def` struct is simplified by removing an unused constructor and the `std_string` type definition. The std::string value becomes a member variable instead of being derived from. - The `cmDefinitions::Unset` method is added that unsets a definition. It has the same functionality as calling `cmDefinitions::Set` with a `nullptr` value argument, - The `cmDefinitions::Set` method gets an overloaded version that takes a `cm::string_view` as value argument. - The originl `cmDefinitions::Set` method with `const char*` argument is refactored to either call the `cm::string_view` based `cmDefinitions::Set` overload or `cmDefinitions::Unset`, depending on whether the value `const char*` is a nullptr (`Unset`) or not (`Set`). diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index 35cdc5a..42e70d6 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -36,7 +36,7 @@ const std::string* cmDefinitions::Get(const std::string& key, StackIter begin, StackIter end) { Def const& def = cmDefinitions::GetInternal(key, begin, end, false); - return def.Exists ? &def : nullptr; + return def.Exists ? &def.Value : nullptr; } void cmDefinitions::Raise(const std::string& key, StackIter begin, @@ -56,11 +56,16 @@ bool cmDefinitions::HasKey(const std::string& key, StackIter begin, return false; } -void cmDefinitions::Set(const std::string& key, const char* value) +void cmDefinitions::Set(const std::string& key, cm::string_view value) { this->Map[key] = Def(value); } +void cmDefinitions::Unset(const std::string& key) +{ + this->Map[key] = Def(); +} + std::vector<std::string> cmDefinitions::UnusedKeys() const { std::vector<std::string> keys; diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index 6c252be..b6a08bc 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -5,12 +5,14 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include "cm_string_view.hxx" + +#include "cmLinkedTree.h" + #include <string> #include <unordered_map> #include <vector> -#include "cmLinkedTree.h" - /** \class cmDefinitions * \brief Store a scope of variable definitions for CMake language. * @@ -31,7 +33,20 @@ public: static bool HasKey(const std::string& key, StackIter begin, StackIter end); /** Set (or unset if null) a value associated with a key. */ - void Set(const std::string& key, const char* value); + void Set(const std::string& key, const char* value) + { + if (value) { + this->Set(key, cm::string_view(value)); + } else { + this->Unset(key); + } + } + + /** Set a value associated with a key. */ + void Set(const std::string& key, cm::string_view value); + + /** Unset a definition. */ + void Unset(const std::string& key); std::vector<std::string> UnusedKeys() const; @@ -40,24 +55,17 @@ public: static cmDefinitions MakeClosure(StackIter begin, StackIter end); private: - // String with existence boolean. - struct Def : public std::string + /** String with existence boolean. */ + struct Def { - private: - typedef std::string std_string; - public: Def() = default; - Def(const char* v) - : std_string(v ? v : "") - , Exists(v ? true : false) - { - } - Def(const std_string& v) - : std_string(v) + Def(cm::string_view value) + : Value(value) , Exists(true) { } + std::string Value; bool Exists = false; bool Used = false; }; https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=451fd329a88f26bacce7e9939ef767876b385050 commit 451fd329a88f26bacce7e9939ef767876b385050 Author: Sebastian Holtermann <sebh...@xwmw.org> AuthorDate: Fri Jul 19 09:59:40 2019 +0200 Commit: Sebastian Holtermann <sebh...@xwmw.org> CommitDate: Wed Jul 24 11:11:25 2019 +0200 cmDefinitions: Cleanups diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index 894447c..35cdc5a 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -13,10 +13,12 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key, StackIter end, bool raise) { assert(begin != end); - MapType::iterator i = begin->Map.find(key); - if (i != begin->Map.end()) { - i->second.Used = true; - return i->second; + { + MapType::iterator it = begin->Map.find(key); + if (it != begin->Map.end()) { + it->second.Used = true; + return it->second; + } } StackIter it = begin; ++it; @@ -27,7 +29,7 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key, if (!raise) { return def; } - return begin->Map.insert(MapType::value_type(key, def)).first->second; + return begin->Map.emplace(key, def).first->second; } const std::string* cmDefinitions::Get(const std::string& key, StackIter begin, @@ -47,8 +49,7 @@ bool cmDefinitions::HasKey(const std::string& key, StackIter begin, StackIter end) { for (StackIter it = begin; it != end; ++it) { - MapType::const_iterator i = it->Map.find(key); - if (i != it->Map.end()) { + if (it->Map.find(key) != it->Map.end()) { return true; } } @@ -97,8 +98,8 @@ cmDefinitions cmDefinitions::MakeClosure(StackIter begin, StackIter end) std::vector<std::string> cmDefinitions::ClosureKeys(StackIter begin, StackIter end) { - std::set<std::string> bound; std::vector<std::string> defined; + std::set<std::string> bound; for (StackIter it = begin; it != end; ++it) { defined.reserve(defined.size() + it->Map.size()); ----------------------------------------------------------------------- Summary of changes: Source/CPack/cmCPackGenerator.cxx | 13 +- Source/CPack/cpack.cxx | 21 ++-- Source/CTest/cmCTestBuildCommand.cxx | 5 +- Source/CTest/cmCTestHandlerCommand.cxx | 17 ++- Source/CTest/cmCTestMemCheckCommand.cxx | 4 +- Source/CTest/cmCTestRunScriptCommand.cxx | 2 +- Source/CTest/cmCTestScriptHandler.cxx | 20 ++-- Source/CTest/cmCTestSubmitCommand.cxx | 2 +- Source/CTest/cmCTestTestHandler.cxx | 3 +- Source/cmAlgorithms.h | 52 +++----- Source/cmAuxSourceDirectoryCommand.cxx | 2 +- Source/cmBuildCommand.cxx | 2 +- Source/cmCMakeHostSystemInformationCommand.cxx | 2 +- Source/cmCMakeMinimumRequired.cxx | 3 +- Source/cmCMakePolicyCommand.cxx | 3 +- Source/cmCPluginAPI.cxx | 6 +- Source/cmCoreTryCompile.cxx | 5 +- Source/cmCreateTestSourceList.cxx | 11 +- Source/cmDefinitions.cxx | 26 ++-- Source/cmDefinitions.h | 30 +++-- Source/cmExecProgramCommand.cxx | 2 +- Source/cmExecuteProcessCommand.cxx | 2 +- Source/cmFLTKWrapUICommand.cxx | 3 +- Source/cmFileCommand.cxx | 55 ++++----- Source/cmFileInstaller.cxx | 2 +- Source/cmFindPackageCommand.cxx | 20 ++-- Source/cmForEachCommand.cxx | 8 +- Source/cmFunctionCommand.cxx | 10 +- Source/cmGetCMakePropertyCommand.cxx | 2 +- Source/cmGetDirectoryPropertyCommand.cxx | 8 +- Source/cmGetFilenameComponentCommand.cxx | 4 +- Source/cmGetPropertyCommand.cxx | 4 +- Source/cmGetSourceFilePropertyCommand.cxx | 2 +- Source/cmGetTargetPropertyCommand.cxx | 4 +- Source/cmGlobalGenerator.cxx | 7 +- Source/cmGlobalGhsMultiGenerator.cxx | 2 +- Source/cmGlobalMSYSMakefileGenerator.cxx | 6 +- Source/cmGlobalMinGWMakefileGenerator.cxx | 6 +- Source/cmGlobalVisualStudio10Generator.cxx | 5 +- Source/cmGlobalVisualStudio14Generator.cxx | 2 +- Source/cmGlobalVisualStudio7Generator.cxx | 5 +- Source/cmGlobalVisualStudio8Generator.cxx | 3 +- Source/cmGlobalVisualStudioGenerator.cxx | 6 +- Source/cmGlobalXCodeGenerator.cxx | 8 +- Source/cmIncludeGuardCommand.cxx | 2 +- Source/cmListCommand.cxx | 38 +++--- Source/cmLoadCacheCommand.cxx | 2 +- Source/cmLoadCommandCommand.cxx | 2 +- Source/cmLocalGenerator.cxx | 4 +- Source/cmMakefile.cxx | 60 ++++------ Source/cmMakefile.h | 13 +- Source/cmParseArgumentsCommand.cxx | 11 +- Source/cmProjectCommand.cxx | 42 ++++--- Source/cmQTWrapCPPCommand.cxx | 2 +- Source/cmQTWrapUICommand.cxx | 4 +- Source/cmRemoveCommand.cxx | 2 +- Source/cmSeparateArgumentsCommand.cxx | 4 +- Source/cmSetCommand.cxx | 2 +- Source/cmSourceFileLocation.cxx | 3 +- Source/cmState.cxx | 4 +- Source/cmStateSnapshot.cxx | 12 +- Source/cmStateSnapshot.h | 4 +- Source/cmStringCommand.cxx | 41 ++++--- Source/cmSystemTools.cxx | 160 ++++++++++--------------- Source/cmSystemTools.h | 38 ++++-- Source/cmTryRunCommand.cxx | 5 +- Source/cmVariableRequiresCommand.cxx | 2 +- Source/kwsys/CommandLineArguments.cxx | 6 +- Source/kwsys/RegularExpression.cxx | 3 +- Source/kwsys/RegularExpression.hxx.in | 18 ++- Source/kwsys/SystemTools.cxx | 10 +- 71 files changed, 419 insertions(+), 480 deletions(-) hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org https://cmake.org/mailman/listinfo/cmake-commits