Skip to content

Commit 07d99c5

Browse files
authored
Merge pull request #68 from build-cpp/headers-crash
Fix the way target.headers is merged into target.sources
2 parents 153bdbe + 5af2385 commit 07d99c5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

include/project_parser.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ struct Target {
6767
TargetType type = target_last;
6868
std::string type_name;
6969

70-
ConditionVector headers;
7170
ConditionVector sources;
7271

7372
// https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html#project-commands

src/project_parser.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,18 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
487487
throw std::runtime_error(format_key_error(error, target.type_name, t.find("type")));
488488
}
489489

490-
t.optional("headers", target.headers);
491490
t.optional("sources", target.sources);
492491

492+
// Merge the headers into the sources
493+
ConditionVector headers;
494+
t.optional("headers", headers);
495+
for (const auto &itr : headers) {
496+
auto &dest = target.sources[itr.first];
497+
for (const auto &jtr : itr.second) {
498+
dest.push_back(jtr);
499+
}
500+
}
501+
493502
t.optional("compile-definitions", target.compile_definitions);
494503
t.optional("private-compile-definitions", target.private_compile_definitions);
495504

@@ -514,12 +523,6 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
514523
t.optional("precompile-headers", target.precompile_headers);
515524
t.optional("private-precompile-headers", target.private_precompile_headers);
516525

517-
if (!target.headers.empty()) {
518-
auto &sources = target.sources.nth(0).value();
519-
const auto &headers = target.headers.nth(0)->second;
520-
sources.insert(sources.end(), headers.begin(), headers.end());
521-
}
522-
523526
t.optional("condition", target.condition);
524527
t.optional("alias", target.alias);
525528

0 commit comments

Comments
 (0)