mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Trim additional new lines at the end of the generated CMakeLists.txt
This commit is contained in:
committed by
Duncan Ogilvie
parent
3fb095210a
commit
d3829fb6cd
+12
-3
@@ -1378,10 +1378,19 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch the generated CMakeLists.txt output from the stringstream buffer
|
||||
auto generated_cmake = ss.str();
|
||||
|
||||
// Make sure the file ends in a single newline
|
||||
while (!generated_cmake.empty() && std::isspace(generated_cmake.back())) {
|
||||
generated_cmake.pop_back();
|
||||
}
|
||||
generated_cmake += '\n';
|
||||
|
||||
// Generate CMakeLists.txt
|
||||
auto list_path = fs::path(path) / "CMakeLists.txt";
|
||||
|
||||
auto should_regenerate = [&list_path, &ss]() {
|
||||
auto should_regenerate = [&list_path, &generated_cmake]() {
|
||||
if (!fs::exists(list_path))
|
||||
return true;
|
||||
|
||||
@@ -1391,11 +1400,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
}
|
||||
|
||||
std::string data((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||
return data != ss.str();
|
||||
return data != generated_cmake;
|
||||
}();
|
||||
|
||||
if (should_regenerate) {
|
||||
create_file(list_path, ss.str());
|
||||
create_file(list_path, generated_cmake);
|
||||
}
|
||||
|
||||
auto generate_subdir = [path, &project](const fs::path &sub) {
|
||||
|
||||
Generated
-1
@@ -109,4 +109,3 @@ add_test(
|
||||
"$<TARGET_FILE:cmkr>"
|
||||
build
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user