summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2024-05-09 16:50:36 +0200
committerRoland Reichwein <mail@reichwein.it>2024-05-09 16:50:36 +0200
commit1eaf818aa9339f29d08cf79601836c0ea763c622 (patch)
treed56554c99df8c2cfe0642e2f91e5c96d26dd8fe9
parent242b03bc8da841a9527ad845eb60275008155afb (diff)
Use specified includepath
-rw-r--r--Builder.cpp39
-rw-r--r--Builder.h4
-rw-r--r--LanguageSettings.cpp2
3 files changed, 34 insertions, 11 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)};
diff --git a/Builder.h b/Builder.h
index b167e65..42c5af4 100644
--- a/Builder.h
+++ b/Builder.h
@@ -24,11 +24,13 @@ public:
private:
std::unordered_map<std::filesystem::path, std::vector<std::filesystem::path>> get_dependencies(const boost::property_tree::ptree& ptree) const;
std::vector<std::filesystem::path> dependencies_of(const std::filesystem::path& p) const;
- std::vector<std::filesystem::path> include_paths_of(const std::filesystem::path& p) const;
+ std::vector<std::filesystem::path> include_paths_of_object(const std::filesystem::path& p) const;
+ std::filesystem::path target_from_object(const std::filesystem::path& object) const;
std::vector<std::string> link_libs_of(const std::filesystem::path& p) const;
bool is_outdated(const std::filesystem::path& p) const;
bool is_outdated(const std::filesystem::path& p, const std::vector<std::filesystem::path> &dependencies) const;
std::vector<std::filesystem::path> make_depfile_from(const std::filesystem::path& p) const;
+ std::filesystem::path get_compile_unit_source_from_object(const std::filesystem::path& path);
void build_file(const std::filesystem::path& p);
void build_filelist();
diff --git a/LanguageSettings.cpp b/LanguageSettings.cpp
index 57a550d..1d243d5 100644
--- a/LanguageSettings.cpp
+++ b/LanguageSettings.cpp
@@ -73,7 +73,7 @@ std::string LanguageSettings::getCompileCommand(const std::filesystem::path& tar
const std::vector<std::filesystem::path>& includepaths) const
{
std::string includes{std::accumulate(includepaths.begin(), includepaths.end(), std::string{},
- [](const std::string& sum, const fs::path& p){ return sum + " " + p.string();})};
+ [](const std::string& sum, const fs::path& p){ return sum + " -I" + p.string();})};
// compile: $(CXX) $(CXXFLAGS) -c $< -o $@
return fmt::format("{}{}{} -c {} -o {}",