1
1
#include " BuildConfig.hpp"
2
2
3
3
#include " Algos.hpp"
4
+ #include " Command.hpp"
4
5
#include " Exception.hpp"
5
6
#include " Git2.hpp"
6
7
#include " Logger.hpp"
@@ -109,15 +110,36 @@ struct BuildConfig {
109
110
std::optional<std::unordered_set<std::string>> all;
110
111
111
112
std::string OUT_DIR;
112
- std::string CXX = " clang++ " ;
113
+ std::string CXX;
113
114
std::vector<std::string> CXXFLAGS;
114
115
std::vector<std::string> DEFINES;
115
116
std::vector<std::string> INCLUDES = { " -I../../include" };
116
117
std::vector<std::string> LIBS;
117
118
118
- BuildConfig () = default ;
119
119
explicit BuildConfig (const std::string& packageName)
120
- : packageName{ packageName }, buildOutDir{ packageName + " .d" } {}
120
+ : packageName{ packageName }, buildOutDir{ packageName + " .d" } {
121
+ if (const char * cxx = std::getenv (" CXX" )) {
122
+ CXX = cxx;
123
+ } else {
124
+ std::string output = Command (" make" )
125
+ .addArg (" --print-data-base" )
126
+ .addArg (" --question" )
127
+ .addArg (" -f" )
128
+ .addArg (" /dev/null" )
129
+ .output ()
130
+ .output ;
131
+ std::istringstream iss (output);
132
+ std::string line;
133
+
134
+ while (std::getline (iss, line)) {
135
+ if (line.starts_with (" CXX = " )) {
136
+ CXX = line.substr (6 );
137
+ return ;
138
+ }
139
+ }
140
+ throw PoacError (" failed to get CXX from make" );
141
+ }
142
+ }
121
143
122
144
void setOutDir (const bool isDebug) {
123
145
if (isDebug) {
@@ -593,7 +615,7 @@ BuildConfig::addDefine(
593
615
594
616
void
595
617
BuildConfig::setVariables (const bool isDebug) {
596
- this ->defineCondVar (" CXX" , CXX);
618
+ this ->defineSimpleVar (" CXX" , CXX);
597
619
598
620
CXXFLAGS.push_back (" -std=c++" + getPackageEdition ().getString ());
599
621
if (shouldColor ()) {
@@ -816,9 +838,6 @@ configureBuild(BuildConfig& config, const bool isDebug) {
816
838
if (!fs::exists (outDir)) {
817
839
fs::create_directories (outDir);
818
840
}
819
- if (const char * cxx = std::getenv (" CXX" )) {
820
- config.CXX = cxx;
821
- }
822
841
823
842
config.setVariables (isDebug);
824
843
@@ -999,7 +1018,7 @@ namespace tests {
999
1018
1000
1019
void
1001
1020
testCycleVars () {
1002
- BuildConfig config;
1021
+ BuildConfig config ( " test " ) ;
1003
1022
config.defineSimpleVar (" a" , " b" , { " b" });
1004
1023
config.defineSimpleVar (" b" , " c" , { " c" });
1005
1024
config.defineSimpleVar (" c" , " a" , { " a" });
@@ -1017,7 +1036,7 @@ testCycleVars() {
1017
1036
1018
1037
void
1019
1038
testSimpleVars () {
1020
- BuildConfig config;
1039
+ BuildConfig config ( " test " ) ;
1021
1040
config.defineSimpleVar (" c" , " 3" , { " b" });
1022
1041
config.defineSimpleVar (" b" , " 2" , { " a" });
1023
1042
config.defineSimpleVar (" a" , " 1" );
@@ -1036,7 +1055,7 @@ testSimpleVars() {
1036
1055
1037
1056
void
1038
1057
testDependOnUnregisteredVar () {
1039
- BuildConfig config;
1058
+ BuildConfig config ( " test " ) ;
1040
1059
config.defineSimpleVar (" a" , " 1" , { " b" });
1041
1060
1042
1061
std::ostringstream oss;
@@ -1049,7 +1068,7 @@ testDependOnUnregisteredVar() {
1049
1068
1050
1069
void
1051
1070
testCycleTargets () {
1052
- BuildConfig config;
1071
+ BuildConfig config ( " test " ) ;
1053
1072
config.defineTarget (" a" , { " echo a" }, { " b" });
1054
1073
config.defineTarget (" b" , { " echo b" }, { " c" });
1055
1074
config.defineTarget (" c" , { " echo c" }, { " a" });
@@ -1067,7 +1086,7 @@ testCycleTargets() {
1067
1086
1068
1087
void
1069
1088
testSimpleTargets () {
1070
- BuildConfig config;
1089
+ BuildConfig config ( " test " ) ;
1071
1090
config.defineTarget (" a" , { " echo a" });
1072
1091
config.defineTarget (" b" , { " echo b" }, { " a" });
1073
1092
config.defineTarget (" c" , { " echo c" }, { " b" });
@@ -1092,7 +1111,7 @@ testSimpleTargets() {
1092
1111
1093
1112
void
1094
1113
testDependOnUnregisteredTarget () {
1095
- BuildConfig config;
1114
+ BuildConfig config ( " test " ) ;
1096
1115
config.defineTarget (" a" , { " echo a" }, { " b" });
1097
1116
1098
1117
std::ostringstream oss;
0 commit comments