summaryrefslogtreecommitdiff
path: root/src/configure.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2022-05-23 18:46:13 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2022-06-06 10:21:43 +0200
commite9023132d506a9223d6c7c315a3cdf118effd30e (patch)
tree93e97fd0d04b0604d134918a1d194f2e282a3c03 /src/configure.cc
parent1523880f97eab00120c029d55bab47252f31f166 (diff)
Added support for manual externals (inherit flags and set include/lib paths from configure).
Diffstat (limited to 'src/configure.cc')
-rw-r--r--src/configure.cc97
1 files changed, 77 insertions, 20 deletions
diff --git a/src/configure.cc b/src/configure.cc
index 4df6026..02e8224 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -15,10 +15,14 @@
#include "libctor.h"
#include "tasks.h"
#include "rebuild.h"
+#include "externals.h"
std::filesystem::path configurationFile("configuration.cc");
std::filesystem::path configHeaderFile("config.h");
+std::map<std::string, std::string> external_includedir;
+std::map<std::string, std::string> external_libdir;
+
const Configuration default_configuration{};
const Configuration& __attribute__((weak)) configuration()
{
@@ -143,6 +147,9 @@ public:
}
};
+// helper constant for the visitor
+template<class> inline constexpr bool always_false_v = false;
+
int regenerateCache(const Settings& default_settings,
const std::vector<std::string>& args,
const std::map<std::string, std::string>& env)
@@ -249,6 +256,51 @@ int regenerateCache(const Settings& default_settings,
return 0;
});
+ // Resolv externals
+ ExternalConfigurations externalConfigs;
+ for(std::size_t i = 0; i < numExternalConfigFiles; ++i)
+ {
+ auto newExternalConfigs = externalConfigFiles[i].cb();
+ externalConfigs.insert(externalConfigs.end(),
+ newExternalConfigs.begin(),
+ newExternalConfigs.end());
+ }
+
+ auto add_path_args =
+ [&](const std::string& name)
+ {
+ opt.add(name + "-includedir", required_argument, key++,
+ "Set path to " + name + " header file.",
+ [&]() {
+ external_includedir[name] = optarg;
+ return 0;
+ });
+
+ opt.add(name + "-libdir", required_argument, key++,
+ "Set path to " + name + " libraries.",
+ [&]() {
+ external_libdir[name] = optarg;
+ return 0;
+ });
+ };
+
+ for(const auto& ext : externalConfigs)
+ {
+ std::visit([&](auto&& arg)
+ {
+ using T = std::decay_t<decltype(arg)>;
+ if constexpr (std::is_same_v<T, ExternalManual>)
+ {
+ add_path_args(ext.name);
+ }
+ else
+ {
+ static_assert(always_false_v<T>, "non-exhaustive visitor!");
+ }
+ }, ext.external);
+
+ }
+
opt.add("help", no_argument, 'h',
"Print this help text.",
[&]() {
@@ -325,16 +377,6 @@ int regenerateCache(const Settings& default_settings,
std::string build_ar = locate(build_arch, ar_prog);
std::string build_ld = locate(build_arch, ld_prog);
- // Resolv externals
- ExternalConfigurations externalConfigs;
- for(std::size_t i = 0; i < numExternalConfigFiles; ++i)
- {
- auto newExternalConfigs = externalConfigFiles[i].cb();
- externalConfigs.insert(externalConfigs.end(),
- newExternalConfigs.begin(),
- newExternalConfigs.end());
- }
-
std::cout << "Writing results to: " << configurationFile.string() << "\n";
{
std::ofstream istr(configurationFile);
@@ -380,44 +422,59 @@ int regenerateCache(const Settings& default_settings,
istr << " },\n";
istr << " .externals = {\n";
- for(const auto& externalConfig : externalConfigs)
+ for(const auto& ext : externalConfigs)
{
- istr << " { \"" << externalConfig.name << "\", {\n";
+ istr << " { \"" << ext.name << "\", {\n";
+ Flags resolved_flags;
+ if(std::holds_alternative<ExternalManual>(ext.external))
+ {
+ if(auto ret = resolv(settings, ext.name,
+ std::get<ExternalManual>(ext.external),
+ resolved_flags))
+ {
+ return ret;
+ }
+ }
+ else
+ {
+ std::cout << "Unknown external type\n";
+ return 1;
+ }
- if(!externalConfig.flags.cxxflags.empty())
+ if(!resolved_flags.cxxflags.empty())
{
istr << " .cxxflags = {";
- for(const auto& flag : externalConfig.flags.cxxflags)
+ for(const auto& flag : resolved_flags.cxxflags)
{
istr << "\"" << flag << "\",";
}
istr << "},\n";
}
- if(!externalConfig.flags.cflags.empty())
+ if(!resolved_flags.cflags.empty())
{
istr << " .cflags = {";
- for(const auto& flag : externalConfig.flags.cflags)
+ for(const auto& flag : resolved_flags.cflags)
{
istr << "\"" << flag << "\",";
}
istr << "},\n";
}
- if(!externalConfig.flags.ldflags.empty())
+ if(!resolved_flags.ldflags.empty())
{
istr << " .ldflags = {";
- for(const auto& flag : externalConfig.flags.ldflags)
+ for(const auto& flag : resolved_flags.ldflags)
{
istr << "\"" << flag << "\",";
}
istr << "},\n";
}
- if(!externalConfig.flags.asmflags.empty())
+ if(!resolved_flags.asmflags.empty())
{
istr << " .asmflags = {";
- for(const auto& flag : externalConfig.flags.asmflags)
+ for(const auto& flag : resolved_flags.asmflags)
{
istr << "\"" << flag << "\",";
}