Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuildConfig: handle LDFLAGS #1103

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading