summaryrefslogtreecommitdiffhomepage
path: root/LanguageSettings.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2024-05-18 16:31:14 +0200
committerRoland Reichwein <mail@reichwein.it>2024-05-18 16:31:14 +0200
commitf857007dbb6a0a26a6828017da64540eda452fbf (patch)
treea2fc22abb236c6f07a9b9425a87b18f5f2e189f8 /LanguageSettings.cpp
parent8a4dfbbbe76a2aef35427b7915d6e28bab165c43 (diff)
Link different kinds of libs
Diffstat (limited to 'LanguageSettings.cpp')
-rw-r--r--LanguageSettings.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/LanguageSettings.cpp b/LanguageSettings.cpp
index 5eae731..5bec072 100644
--- a/LanguageSettings.cpp
+++ b/LanguageSettings.cpp
@@ -72,7 +72,7 @@ std::string LanguageSettings::getCompileCommand(const std::filesystem::path& tar
std::string LanguageSettings::getLinkCommand(const std::filesystem::path& target,
const std::vector<std::filesystem::path> &inputs,
- const std::vector<std::string>& link_libs) const
+ const std::vector<std::filesystem::path>& link_libs) const
{
std::string input_string{std::accumulate(inputs.begin(), inputs.end(), std::string{},
[](const std::string& sum, const fs::path& p){ return sum + " " + p.string(); })};
@@ -88,8 +88,16 @@ std::string LanguageSettings::getLinkCommand(const std::filesystem::path& target
std::string LDFLAGS_add{is_dynamic_lib(target) ? fmt::format(" -shared -Wl,-soname,{}",
soname_shorter(target.string()).string()) : ""s};
- 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; })};
+ std::string link_libs_string;
+ for (const auto& i: link_libs) {
+ if (is_static_lib(i.string())) {
+ input_string += " " + i.string();
+ } else if (is_dynamic_lib(i.string()) || is_dynamic_lib_link(i.string())) {
+ input_string += " -L" + i.parent_path().string() + " -l" + dynamic_lib_name(i);
+ } else { // link external dynamic lib, e.g. "fmt"
+ link_libs_string += " -l" + i.string();
+ }
+ }
// link: $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@
return fmt::format("{}{}{}{}{}{}{} -o {}",