Skip to content

Commit ee7fe38

Browse files
authored
Merge pull request #100 from build-cpp/include-subdir-bugfix
Fix a bug where includes in a subdir would not work
2 parents d2e3760 + 66b2aad commit ee7fe38

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/cmake_generator.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,12 @@ static std::string tolf(const std::string &str) {
445445
};
446446

447447
struct Generator {
448-
Generator(const parser::Project &project) : project(project) {
448+
Generator(const parser::Project &project, const fs::path &path) : project(project), path(path) {
449449
}
450450
Generator(const Generator &) = delete;
451451

452452
const parser::Project &project;
453+
fs::path path;
453454
std::stringstream ss;
454455
int indent = 0;
455456

@@ -479,8 +480,8 @@ struct Generator {
479480
void inject_includes(const std::vector<std::string> &includes) {
480481
if (!includes.empty()) {
481482
for (const auto &file : includes) {
482-
if (!fs::is_regular_file(file)) {
483-
throw std::runtime_error("Include '" + file + "' does not exist");
483+
if (!fs::exists(path / file)) {
484+
throw std::runtime_error("Include not found: " + file);
484485
}
485486
cmd("include")(file);
486487
}
@@ -627,7 +628,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
627628
}
628629
}
629630

630-
Generator gen(project);
631+
Generator gen(project, path);
631632

632633
// Helper lambdas for more convenient CMake generation
633634
auto &ss = gen.ss;
@@ -1123,7 +1124,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
11231124
continue;
11241125
const auto &source_path = fs::path(path) / source;
11251126
if (!fs::exists(source_path)) {
1126-
throw_target_error("Source file does not exist " + source);
1127+
throw_target_error("Source file not found: " + source);
11271128
}
11281129
}
11291130
break;

0 commit comments

Comments
 (0)