summaryrefslogtreecommitdiff
path: root/src/configure.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/configure.cc')
-rw-r--r--src/configure.cc81
1 files changed, 80 insertions, 1 deletions
diff --git a/src/configure.cc b/src/configure.cc
index a43152f..b52824e 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -8,6 +8,8 @@
#include <fstream>
#include <optional>
#include <span>
+#include <vector>
+#include <deque>
#include <getoptpp/getoptpp.hpp>
@@ -25,7 +27,11 @@ const std::filesystem::path configHeaderFile("config.h");
std::map<std::string, std::string> external_includedir;
std::map<std::string, std::string> external_libdir;
+#if !defined(_WIN32)
const ctor::configuration& __attribute__((weak)) ctor::get_configuration()
+#else
+const ctor::configuration& default_get_configuration()
+#endif
{
static ctor::configuration cfg;
static bool initialised{false};
@@ -44,6 +50,14 @@ const ctor::configuration& __attribute__((weak)) ctor::get_configuration()
}
return cfg;
}
+#if defined(_WIN32)
+// Hack to make ctor::get_configuration "weak" linked
+// See:
+// https://stackoverflow.com/questions/2290587/gcc-style-weak-linking-in-visual-studio
+// and
+// https://stackoverflow.com/questions/11849853/how-to-list-functions-present-in-object-file
+#pragma comment(linker, "/alternatename:?get_configuration@ctor@@YAABUconfiguration@1@XZ=?default_get_configuration@@YAABUconfiguration@ctor@@XZ")
+#endif
namespace ctor {
std::optional<std::string> includedir;
@@ -100,11 +114,47 @@ std::string ctor::configuration::get(const std::string& key,
return ctor::conf_values[key];
}
- if(has(key))
+ if(tools.find(key) != tools.end())
{
return tools.at(key);
}
+ if(key == ctor::cfg::build_cxx)
+ {
+ auto e = std::getenv("CXX");
+ if(e)
+ {
+ return e;
+ }
+ }
+
+ if(key == ctor::cfg::build_cc)
+ {
+ auto e = std::getenv("CC");
+ if(e)
+ {
+ return e;
+ }
+ }
+
+ if(key == ctor::cfg::build_ld)
+ {
+ auto e = std::getenv("LD");
+ if(e)
+ {
+ return e;
+ }
+ }
+
+ if(key == ctor::cfg::build_ar)
+ {
+ auto e = std::getenv("AR");
+ if(e)
+ {
+ return e;
+ }
+ }
+
return default_value;
}
@@ -162,6 +212,9 @@ std::ostream& operator<<(std::ostream& stream, const ctor::toolchain& toolchain)
case ctor::toolchain::gcc:
stream << "ctor::toolchain::gcc";
break;
+ case ctor::toolchain::msvc:
+ stream << "ctor::toolchain::msvc";
+ break;
case ctor::toolchain::clang:
stream << "ctor::toolchain::clang";
break;
@@ -676,6 +729,7 @@ int regenerateCache(ctor::settings& settings,
{
ctor::conf_values[ctor::cfg::builddir] = builddir;
}
+
ctor::conf_values[ctor::cfg::host_cxx] = host_cxx;
ctor::conf_values[ctor::cfg::build_cxx] = build_cxx;
@@ -906,6 +960,31 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[])
env["PATH"] = path_env;
}
+ // Env vars for msvc
+ auto cl_env = getenv("CL");
+ if(cl_env)
+ {
+ env["CL"] = cl_env;
+ }
+
+ auto lib_env = getenv("LIB");
+ if(lib_env)
+ {
+ env["LIB"] = lib_env;
+ }
+
+ auto link_env = getenv("LINK");
+ if(link_env)
+ {
+ env["LINK"] = link_env;
+ }
+
+ auto include_env = getenv("INCLUDE");
+ if(include_env)
+ {
+ env["INCLUDE"] = include_env;
+ }
+
auto ret = regenerateCache(settings, args_span[0], args, env);
if(ret != 0)
{