Skip to content

Commit d3829fb

Browse files
anthonyprintupmrexodia
authored andcommitted
Trim additional new lines at the end of the generated CMakeLists.txt
1 parent 3fb0952 commit d3829fb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/cmake_generator.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,10 +1378,19 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
13781378
}
13791379
}
13801380

1381+
// Fetch the generated CMakeLists.txt output from the stringstream buffer
1382+
auto generated_cmake = ss.str();
1383+
1384+
// Make sure the file ends in a single newline
1385+
while (!generated_cmake.empty() && std::isspace(generated_cmake.back())) {
1386+
generated_cmake.pop_back();
1387+
}
1388+
generated_cmake += '\n';
1389+
13811390
// Generate CMakeLists.txt
13821391
auto list_path = fs::path(path) / "CMakeLists.txt";
13831392

1384-
auto should_regenerate = [&list_path, &ss]() {
1393+
auto should_regenerate = [&list_path, &generated_cmake]() {
13851394
if (!fs::exists(list_path))
13861395
return true;
13871396

@@ -1391,11 +1400,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
13911400
}
13921401

13931402
std::string data((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
1394-
return data != ss.str();
1403+
return data != generated_cmake;
13951404
}();
13961405

13971406
if (should_regenerate) {
1398-
create_file(list_path, ss.str());
1407+
create_file(list_path, generated_cmake);
13991408
}
14001409

14011410
auto generate_subdir = [path, &project](const fs::path &sub) {

tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)