diff options
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 |