From 5809172695f0b174ae036dc829e6d3176d926342 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 1 Feb 2025 20:37:32 +0100 Subject: WIP --- src/configure.cc | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) (limited to 'src/configure.cc') 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 #include #include +#include +#include #include @@ -25,7 +27,11 @@ const std::filesystem::path configHeaderFile("config.h"); std::map external_includedir; std::map 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 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) { -- cgit v1.2.3