|
|
@ -137,6 +137,27 @@ struct Command {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string quote(const std::string &str) {
|
|
|
|
|
|
|
|
// Don't quote arguments that don't need quoting
|
|
|
|
|
|
|
|
if (str.find(' ') == std::string::npos && str.find('\"') == std::string::npos && str.find("${") == std::string::npos) {
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
result += "\"";
|
|
|
|
|
|
|
|
for (char ch : str) {
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
|
|
|
|
case '\\':
|
|
|
|
|
|
|
|
case '\"':
|
|
|
|
|
|
|
|
result += '\\';
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
result += ch;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result += "\"";
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *indent(int n) {
|
|
|
|
const char *indent(int n) {
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
ss << '\t';
|
|
|
|
ss << '\t';
|
|
|
@ -152,7 +173,7 @@ struct Command {
|
|
|
|
|
|
|
|
|
|
|
|
ss << '\n';
|
|
|
|
ss << '\n';
|
|
|
|
for (const auto &value : vec) {
|
|
|
|
for (const auto &value : vec) {
|
|
|
|
ss << indent(depth + 1) << value << '\n';
|
|
|
|
ss << indent(depth + 1) << quote(value) << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -165,7 +186,7 @@ struct Command {
|
|
|
|
|
|
|
|
|
|
|
|
ss << '\n';
|
|
|
|
ss << '\n';
|
|
|
|
for (const auto &itr : map) {
|
|
|
|
for (const auto &itr : map) {
|
|
|
|
ss << indent(depth + 1) << itr.first << ' ' << itr.second << '\n';
|
|
|
|
ss << indent(depth + 1) << itr.first << ' ' << quote(itr.second) << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -228,10 +249,20 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
auto endl = [&ss]() { ss << '\n'; };
|
|
|
|
auto endl = [&ss]() { ss << '\n'; };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto tolf = [](const std::string &str) {
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
for (char ch : str) {
|
|
|
|
|
|
|
|
if (ch != '\r') {
|
|
|
|
|
|
|
|
result += ch;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
comment("This file was generated automatically by cmkr.").endl();
|
|
|
|
comment("This file was generated automatically by cmkr.").endl();
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmake.inject_before.empty()) {
|
|
|
|
if (!cmake.inject_before.empty()) {
|
|
|
|
ss << cmake.inject_before << "\n\n";
|
|
|
|
ss << tolf(cmake.inject_before) << "\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmake.include_before.empty()) {
|
|
|
|
if (!cmake.include_before.empty()) {
|
|
|
@ -291,7 +322,7 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmake.inject_after.empty()) {
|
|
|
|
if (!cmake.inject_after.empty()) {
|
|
|
|
ss << cmake.inject_after << "\n\n";
|
|
|
|
ss << tolf(cmake.inject_after) << "\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!cmake.include_after.empty()) {
|
|
|
|
if (!cmake.include_after.empty()) {
|
|
|
@ -429,7 +460,7 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!target.inject_before.empty()) {
|
|
|
|
if (!target.inject_before.empty()) {
|
|
|
|
ss << target.inject_before << "\n\n";
|
|
|
|
ss << tolf(target.inject_before) << "\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!target.include_before.empty()) {
|
|
|
|
if (!target.include_before.empty()) {
|
|
|
@ -469,7 +500,7 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!target.inject_after.empty()) {
|
|
|
|
if (!target.inject_after.empty()) {
|
|
|
|
ss << target.inject_after << "\n\n";
|
|
|
|
ss << tolf(target.inject_after) << "\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!target.include_after.empty()) {
|
|
|
|
if (!target.include_after.empty()) {
|
|
|
@ -541,8 +572,7 @@ int generate_cmake(const char *path, bool root) {
|
|
|
|
|
|
|
|
|
|
|
|
auto list_path = fs::path(path) / "CMakeLists.txt";
|
|
|
|
auto list_path = fs::path(path) / "CMakeLists.txt";
|
|
|
|
|
|
|
|
|
|
|
|
auto should_regenerate = [&list_path, &ss]()
|
|
|
|
auto should_regenerate = [&list_path, &ss]() {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!fs::exists(list_path))
|
|
|
|
if (!fs::exists(list_path))
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|