Skip to content

Commit

Permalink
BuildConfig: handle LDFLAGS (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored Jan 19, 2025
1 parent bc3e252 commit 3d7e81e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ BuildConfig::setVariables() {
if (profile.lto) {
cxxflags.emplace_back("-flto");
}
for (const std::string_view flag : profile.cxxflags) {
for (const std::string& flag : profile.cxxflags) {
cxxflags.emplace_back(flag);
}

Expand All @@ -643,9 +643,7 @@ BuildConfig::setVariables() {
for (const std::string& flag : getEnvFlags("CXXFLAGS")) {
cxxflags.emplace_back(flag);
}
this->defineSimpleVar(
"CXXFLAGS", fmt::format("{:s}", fmt::join(cxxflags, " "))
);
defineSimpleVar("CXXFLAGS", fmt::format("{:s}", fmt::join(cxxflags, " ")));

const std::string pkgName = toMacroName(manifest.package.name);
const Version& pkgVersion = manifest.package.version;
Expand Down Expand Up @@ -686,19 +684,23 @@ BuildConfig::setVariables() {
addDefine(key, val);
}

this->defineSimpleVar(
defineSimpleVar(
"DEFINES", fmt::format("{:s}", fmt::join(this->defines, " "))
);
this->defineSimpleVar(
"INCLUDES", fmt::format("{:s}", fmt::join(includes, " "))
);
defineSimpleVar("INCLUDES", fmt::format("{:s}", fmt::join(includes, " ")));

// LDFLAGS from manifest
for (const std::string& flag : profile.ldflags) {
ldflags.emplace_back(flag);
}
// Environment variables takes the highest precedence and will be appended at
// last.
for (const std::string& flag : getEnvFlags("LDFLAGS")) {
libs.push_back(flag);
ldflags.push_back(flag);
}
this->defineSimpleVar("LIBS", fmt::format("{:s}", fmt::join(libs, " ")));
defineSimpleVar("LDFLAGS", fmt::format("{:s}", fmt::join(ldflags, " ")));

defineSimpleVar("LIBS", fmt::format("{:s}", fmt::join(libs, " ")));
}

Result<void>
Expand Down
3 changes: 2 additions & 1 deletion src/BuildConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inline const std::unordered_set<std::string> HEADER_FILE_EXTS{
// clang-format on

inline const std::string LINK_BIN_COMMAND =
"$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@";
"$(CXX) $(LDFLAGS) $^ $(LIBS) -o $@";
inline const std::string ARCHIVE_LIB_COMMAND = "ar rcs $@ $^";

enum class VarType : uint8_t {
Expand Down Expand Up @@ -75,6 +75,7 @@ class BuildConfig {

std::string cxx;
std::vector<std::string> cxxflags;
std::vector<std::string> ldflags;
std::vector<std::string> defines;
std::vector<std::string> includes = { "-I../../include" };
std::vector<std::string> libs;
Expand Down

0 comments on commit 3d7e81e

Please sign in to comment.