Skip to content

Commit

Permalink
Merge pull request #120 from anthonyprintup/new-lines-fix
Browse files Browse the repository at this point in the history
Trim additional newline characters at the end of CMakeLists.txt
  • Loading branch information
mrexodia authored Sep 16, 2023
2 parents 3fb0952 + d3829fb commit 2202aa8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/cmake_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion tests/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2202aa8

Please sign in to comment.