diff options
author | Roland Reichwein <mail@reichwein.it> | 2024-05-09 15:37:06 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2024-05-09 15:37:06 +0200 |
commit | 242b03bc8da841a9527ad845eb60275008155afb (patch) | |
tree | ca36edb74ccfe34662c8a2b1c72295df77b50254 /LanguageSettings.cpp | |
parent | 7dabda20e11138f2235b12271d569cd3256ebf3a (diff) |
Run tests
Diffstat (limited to 'LanguageSettings.cpp')
-rw-r--r-- | LanguageSettings.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/LanguageSettings.cpp b/LanguageSettings.cpp index 3ded5cf..57a550d 100644 --- a/LanguageSettings.cpp +++ b/LanguageSettings.cpp @@ -1,7 +1,9 @@ #include "LanguageSettings.h" +#include <algorithm> #include <cstdlib> #include <iostream> +#include <numeric> #include <stdexcept> #include <string> #include <vector> @@ -11,6 +13,7 @@ #include <libreichwein/stringhelper.h> namespace fs = std::filesystem; +using namespace std::string_literals; namespace { std::string env_value(const std::string& key) { @@ -65,10 +68,20 @@ LanguageSettings::LanguageSettings(): } } -std::string LanguageSettings::getCompileCommand(const std::filesystem::path& target, const std::filesystem::path &source) const +std::string LanguageSettings::getCompileCommand(const std::filesystem::path& target, + const std::filesystem::path &source, + 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();})}; + // compile: $(CXX) $(CXXFLAGS) -c $< -o $@ - return fmt::format("{} {} -c {} -o {}", CXX, CXXFLAGS, source.string(), target.string()); + return fmt::format("{}{}{} -c {} -o {}", + CXX, + CXXFLAGS.empty() ? ""s : (" "s + CXXFLAGS), + includes, + source.string(), + target.string()); } std::string LanguageSettings::getLinkCommand(const std::filesystem::path& target, @@ -77,23 +90,20 @@ std::string LanguageSettings::getLinkCommand(const std::filesystem::path& target { // link: $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ - std::string input_string; - for (const auto& i: inputs) { - if (!input_string.empty()) { - input_string += " "; - } - input_string += i.string(); - } + std::string input_string{std::accumulate(inputs.begin(), inputs.end(), std::string{}, + [](const std::string& sum, const fs::path& p){ return sum + " " + p.string(); })}; - std::string link_libs_string; - for (const auto& i: link_libs) { - if (!link_libs_string.empty()) { - link_libs_string += " "; - } - link_libs_string += "-l" + i; - } + std::string link_libs_string{std::accumulate(link_libs.begin(), link_libs.end(), std::string(), + [](const std::string& sum, const std::string& i){ return sum + " -l" + i; })}; - return fmt::format("{} {} {} {} {} {} -o {}", CXX, CXXFLAGS, input_string, LDLIBS, LIBS, link_libs_string, target.string()); + return fmt::format("{}{}{}{}{}{} -o {}", + CXX, + CXXFLAGS.empty() ? ""s : (" "s + CXXFLAGS), + input_string, + LDLIBS.empty() ? ""s : (" "s + LDLIBS), + LIBS.empty() ? ""s : (" "s + LIBS), + link_libs_string, + target.string()); } std::string LanguageSettings::getDepCommand(const std::filesystem::path& target, const std::filesystem::path &source) const |