summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx281
1 files changed, 101 insertions, 180 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 1501481..5f4e1fc 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -6,6 +6,7 @@
#include "cmDuration.h"
#include "cmProcessOutput.h"
#include "cmRange.h"
+#include "cmStringAlgorithms.h"
#include "cm_uv.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -176,36 +177,37 @@ void cmSystemTools::ExpandRegistryValues(std::string& source,
}
#endif
-std::string cmSystemTools::EscapeQuotes(const std::string& str)
+std::string cmSystemTools::EscapeQuotes(cm::string_view str)
{
std::string result;
result.reserve(str.size());
- for (const char* ch = str.c_str(); *ch != '\0'; ++ch) {
- if (*ch == '"') {
+ for (const char ch : str) {
+ if (ch == '"') {
result += '\\';
}
- result += *ch;
+ result += ch;
}
return result;
}
-std::string cmSystemTools::HelpFileName(std::string name)
+std::string cmSystemTools::HelpFileName(cm::string_view str)
{
+ std::string name(str);
cmSystemTools::ReplaceString(name, "<", "");
cmSystemTools::ReplaceString(name, ">", "");
return name;
}
-std::string cmSystemTools::TrimWhitespace(const std::string& s)
+std::string cmSystemTools::TrimWhitespace(cm::string_view str)
{
- std::string::const_iterator start = s.begin();
- while (start != s.end() && cm_isspace(*start)) {
+ auto start = str.begin();
+ while (start != str.end() && cm_isspace(*start)) {
++start;
}
- if (start == s.end()) {
- return "";
+ if (start == str.end()) {
+ return std::string();
}
- std::string::const_iterator stop = s.end() - 1;
+ auto stop = str.end() - 1;
while (cm_isspace(*stop)) {
--stop;
}
@@ -282,115 +284,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;
+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;
}
- for (char& c : v) {
- c = static_cast<char>(toupper(c));
- }
- 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)
{
@@ -1151,7 +1123,7 @@ void cmSystemTools::GlobDirs(const std::string& path,
}
}
-void cmSystemTools::ExpandListArgument(const std::string& arg,
+void cmSystemTools::ExpandListArgument(cm::string_view arg,
std::vector<std::string>& argsOut,
bool emptyArgs)
{
@@ -1159,25 +1131,29 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
if (!emptyArgs && arg.empty()) {
return;
}
+
// if there are no ; in the name then just copy the current string
- if (arg.find(';') == std::string::npos) {
- argsOut.push_back(arg);
+ if (arg.find(';') == cm::string_view::npos) {
+ argsOut.emplace_back(arg);
return;
}
+
std::string newArg;
- const char* last = arg.c_str();
// Break the string at non-escaped semicolons not nested in [].
int squareNesting = 0;
- for (const char* c = last; *c; ++c) {
+ cm::string_view::iterator last = arg.begin();
+ cm::string_view::iterator const cend = arg.end();
+ for (cm::string_view::iterator c = last; c != cend; ++c) {
switch (*c) {
case '\\': {
// We only want to allow escaping of semicolons. Other
// escapes should not be processed here.
- const char* next = c + 1;
- if (*next == ';') {
- newArg.append(last, c - last);
+ cm::string_view::iterator cnext = c + 1;
+ if ((cnext != cend) && *cnext == ';') {
+ newArg.append(last, c);
// Skip over the escape character
- last = c = next;
+ last = cnext;
+ c = cnext;
}
} break;
case '[': {
@@ -1190,7 +1166,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
// Break the string here if we are not nested inside square
// brackets.
if (squareNesting == 0) {
- newArg.append(last, c - last);
+ newArg.append(last, c);
// Skip over the semicolon
last = c + 1;
if (!newArg.empty() || emptyArgs) {
@@ -1205,15 +1181,15 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
} break;
}
}
- newArg.append(last);
+ newArg.append(last, cend);
if (!newArg.empty() || emptyArgs) {
// Add the last argument if the string is not empty.
- argsOut.push_back(newArg);
+ argsOut.push_back(std::move(newArg));
}
}
std::vector<std::string> cmSystemTools::ExpandedListArgument(
- const std::string& arg, bool emptyArgs)
+ cm::string_view arg, bool emptyArgs)
{
std::vector<std::string> argsOut;
ExpandListArgument(arg, argsOut, emptyArgs);
@@ -1264,65 +1240,6 @@ bool cmSystemTools::SimpleGlob(const std::string& glob,
return res;
}
-cmSystemTools::FileFormat cmSystemTools::GetFileFormat(std::string const& ext)
-{
- if (ext.empty()) {
- return cmSystemTools::NO_FILE_FORMAT;
- }
- if (ext == "c" || ext == ".c" || ext == "m" || ext == ".m") {
- return cmSystemTools::C_FILE_FORMAT;
- }
- if (ext == "C" || ext == ".C" || ext == "M" || ext == ".M" || ext == "c++" ||
- ext == ".c++" || ext == "cc" || ext == ".cc" || ext == "cpp" ||
- ext == ".cpp" || ext == "cxx" || ext == ".cxx" || ext == "mm" ||
- ext == ".mm") {
- return cmSystemTools::CXX_FILE_FORMAT;
- }
- if (ext == "f" || ext == ".f" || ext == "F" || ext == ".F" || ext == "f77" ||
- ext == ".f77" || ext == "f90" || ext == ".f90" || ext == "for" ||
- ext == ".for" || ext == "f95" || ext == ".f95") {
- return cmSystemTools::FORTRAN_FILE_FORMAT;
- }
- if (ext == "java" || ext == ".java") {
- return cmSystemTools::JAVA_FILE_FORMAT;
- }
- if (ext == "cu" || ext == ".cu") {
- return cmSystemTools::CUDA_FILE_FORMAT;
- }
- if (ext == "H" || ext == ".H" || ext == "h" || ext == ".h" || ext == "h++" ||
- ext == ".h++" || ext == "hm" || ext == ".hm" || ext == "hpp" ||
- ext == ".hpp" || ext == "hxx" || ext == ".hxx" || ext == "in" ||
- ext == ".in" || ext == "txx" || ext == ".txx") {
- return cmSystemTools::HEADER_FILE_FORMAT;
- }
- if (ext == "rc" || ext == ".rc") {
- return cmSystemTools::RESOURCE_FILE_FORMAT;
- }
- if (ext == "def" || ext == ".def") {
- return cmSystemTools::DEFINITION_FILE_FORMAT;
- }
- if (ext == "lib" || ext == ".lib" || ext == "a" || ext == ".a") {
- return cmSystemTools::STATIC_LIBRARY_FILE_FORMAT;
- }
- if (ext == "o" || ext == ".o" || ext == "obj" || ext == ".obj") {
- return cmSystemTools::OBJECT_FILE_FORMAT;
- }
-#ifdef __APPLE__
- if (ext == "dylib" || ext == ".dylib") {
- return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT;
- }
- if (ext == "so" || ext == ".so" || ext == "bundle" || ext == ".bundle") {
- return cmSystemTools::MODULE_FILE_FORMAT;
- }
-#else // __APPLE__
- if (ext == "so" || ext == ".so" || ext == "sl" || ext == ".sl" ||
- ext == "dll" || ext == ".dll") {
- return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT;
- }
-#endif // __APPLE__
- return cmSystemTools::UNKNOWN_FILE_FORMAT;
-}
-
std::string cmSystemTools::ConvertToOutputPath(std::string const& path)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
@@ -2456,7 +2373,8 @@ struct cmSystemToolsRPathInfo
#if defined(CMAKE_USE_ELF_PARSER)
bool cmSystemTools::ChangeRPath(std::string const& file,
std::string const& oldRPath,
- std::string const& newRPath, std::string* emsg,
+ std::string const& newRPath,
+ bool removeEnvironmentRPath, std::string* emsg,
bool* changed)
{
if (changed) {
@@ -2543,7 +2461,9 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
// Construct the new value which preserves the part of the path
// not being changed.
- rp[rp_count].Value = se[i]->Value.substr(0, prefix_len);
+ if (!removeEnvironmentRPath) {
+ rp[rp_count].Value = se[i]->Value.substr(0, prefix_len);
+ }
rp[rp_count].Value += newRPath;
rp[rp_count].Value += se[i]->Value.substr(pos + oldRPath.length());
@@ -2629,6 +2549,7 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
bool cmSystemTools::ChangeRPath(std::string const& /*file*/,
std::string const& /*oldRPath*/,
std::string const& /*newRPath*/,
+ bool /*removeEnvironmentRPath*/,
std::string* /*emsg*/, bool* /*changed*/)
{
return false;