diff options
author | Roland Reichwein <mail@reichwein.it> | 2024-05-09 16:50:36 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2024-05-09 16:50:36 +0200 |
commit | 1eaf818aa9339f29d08cf79601836c0ea763c622 (patch) | |
tree | d56554c99df8c2cfe0642e2f91e5c96d26dd8fe9 /Builder.cpp | |
parent | 242b03bc8da841a9527ad845eb60275008155afb (diff) |
Use specified includepath
Diffstat (limited to 'Builder.cpp')
-rw-r--r-- | Builder.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/Builder.cpp b/Builder.cpp index 57f731e..e74809b 100644 --- a/Builder.cpp +++ b/Builder.cpp @@ -179,6 +179,16 @@ Builder::Builder(const pt::ptree& ptree, const std::string& target): // to prevent creation of .d files in clean() } +// given a compiled compile unit (*.o), find its source file +fs::path Builder::get_compile_unit_source_from_object(const fs::path& path) { + std::vector<fs::path> source_files{dependencies_of(path)}; + auto it{std::find_if(source_files.begin(), source_files.end(), is_compile_unit_source_by_extension)}; + if (it == source_files.end()) { + throw std::runtime_error(fmt::format("No source file found for {}", path.string())); + } + return *it; +} + std::vector<fs::path> Builder::dependencies_of(const fs::path& p) const { try { @@ -197,10 +207,26 @@ std::vector<std::string> Builder::link_libs_of(const fs::path& p) const } } -std::vector<fs::path> Builder::include_paths_of(const fs::path& p) const +fs::path Builder::target_from_object(const fs::path& object) const +{ + for (const auto& target: _all_targets) { + const auto& deps{dependencies_of(target)}; + auto it{std::find(deps.cbegin(), deps.cend(), object)}; + if (it != deps.cend()) { + return target; + } + } + + throw std::runtime_error("No target found which depends on object "s + object.string()); +} + +std::vector<fs::path> Builder::include_paths_of_object(const fs::path& object) const { + fs::path target{target_from_object(object)}; + + // include paths from target try { - return _include_paths.at(p); + return _include_paths.at(target); } catch (const std::out_of_range& ex) { return {}; // empty by default } @@ -288,13 +314,8 @@ void Builder::build_file(const fs::path& p) { if (p.extension() == ".o") { // compile - std::vector<fs::path> source_files{dependencies_of(p)}; - auto it{std::find_if(source_files.begin(), source_files.end(), is_compile_unit_source_by_extension)}; - if (it == source_files.end()) { - throw std::runtime_error(fmt::format("No source file found for {}", p.string())); - } - //std::cout << "DEBUG: " << (*_include_paths.begin()).first << " " << (*_include_paths.begin()).second.size() << " " << p.string() << std::endl; - command = _lang.getCompileCommand(p, *it, include_paths_of(p)); + fs::path source_file{get_compile_unit_source_from_object(p)}; + command = _lang.getCompileCommand(p, source_file, include_paths_of_object(p)); } else { // link std::vector<fs::path> objects{dependencies_of(p)}; |