Skip to content

Commit

Permalink
Set Make's default CXX
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Oct 4, 2024
1 parent b05bf18 commit 75358ba
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BuildConfig.hpp"

#include "Algos.hpp"
#include "Command.hpp"
#include "Exception.hpp"
#include "Git2.hpp"
#include "Logger.hpp"
Expand Down Expand Up @@ -109,15 +110,32 @@ struct BuildConfig {
std::optional<std::unordered_set<std::string>> all;

std::string OUT_DIR;
std::string CXX = "clang++";
std::string CXX;
std::vector<std::string> CXXFLAGS;
std::vector<std::string> DEFINES;
std::vector<std::string> INCLUDES = { "-I../../include" };
std::vector<std::string> LIBS;

BuildConfig() = default;
explicit BuildConfig(const std::string& packageName)
: packageName{ packageName }, buildOutDir{ packageName + ".d" } {}
: packageName{ packageName }, buildOutDir{ packageName + ".d" } {
if (const char* cxx = std::getenv("CXX")) {
CXX = cxx;
} else {
CommandOutput out = Command("make").addArg("--print-data-base").output();
if (out.exitCode == EXIT_SUCCESS) {
std::istringstream iss(out.output);
std::string line;

while (std::getline(iss, line)) {
if (line.starts_with("CXX = ")) {
CXX = line.substr(6);
return;
}
}
}
throw PoacError("failed to get CXX from make");
}
}

void setOutDir(const bool isDebug) {
if (isDebug) {
Expand Down Expand Up @@ -593,7 +611,7 @@ BuildConfig::addDefine(

void
BuildConfig::setVariables(const bool isDebug) {
this->defineCondVar("CXX", CXX);
this->defineSimpleVar("CXX", CXX);

CXXFLAGS.push_back("-std=c++" + getPackageEdition().getString());
if (shouldColor()) {
Expand Down Expand Up @@ -816,9 +834,6 @@ configureBuild(BuildConfig& config, const bool isDebug) {
if (!fs::exists(outDir)) {
fs::create_directories(outDir);
}
if (const char* cxx = std::getenv("CXX")) {
config.CXX = cxx;
}

config.setVariables(isDebug);

Expand Down Expand Up @@ -999,7 +1014,7 @@ namespace tests {

void
testCycleVars() {
BuildConfig config;
BuildConfig config("test");
config.defineSimpleVar("a", "b", { "b" });
config.defineSimpleVar("b", "c", { "c" });
config.defineSimpleVar("c", "a", { "a" });
Expand All @@ -1017,7 +1032,7 @@ testCycleVars() {

void
testSimpleVars() {
BuildConfig config;
BuildConfig config("test");
config.defineSimpleVar("c", "3", { "b" });
config.defineSimpleVar("b", "2", { "a" });
config.defineSimpleVar("a", "1");
Expand All @@ -1036,7 +1051,7 @@ testSimpleVars() {

void
testDependOnUnregisteredVar() {
BuildConfig config;
BuildConfig config("test");
config.defineSimpleVar("a", "1", { "b" });

std::ostringstream oss;
Expand All @@ -1049,7 +1064,7 @@ testDependOnUnregisteredVar() {

void
testCycleTargets() {
BuildConfig config;
BuildConfig config("test");
config.defineTarget("a", { "echo a" }, { "b" });
config.defineTarget("b", { "echo b" }, { "c" });
config.defineTarget("c", { "echo c" }, { "a" });
Expand All @@ -1067,7 +1082,7 @@ testCycleTargets() {

void
testSimpleTargets() {
BuildConfig config;
BuildConfig config("test");
config.defineTarget("a", { "echo a" });
config.defineTarget("b", { "echo b" }, { "a" });
config.defineTarget("c", { "echo c" }, { "b" });
Expand All @@ -1092,7 +1107,7 @@ testSimpleTargets() {

void
testDependOnUnregisteredTarget() {
BuildConfig config;
BuildConfig config("test");
config.defineTarget("a", { "echo a" }, { "b" });

std::ostringstream oss;
Expand Down

0 comments on commit 75358ba

Please sign in to comment.