diff options
Diffstat (limited to 'src/configure.cc')
-rw-r--r-- | src/configure.cc | 120 |
1 files changed, 115 insertions, 5 deletions
diff --git a/src/configure.cc b/src/configure.cc index 995e340..bb663d6 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,17 +27,49 @@ 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}; if(!initialised) { - cfg.build_toolchain = getToolChain(cfg.get(ctor::cfg::build_cxx, "/usr/bin/g++")); + std::string cxx_prog{"g++"}; + auto cxx_env = getenv("CXX"); + if(cxx_env) + { + cxx_prog = cxx_env; + } + + cfg.build_toolchain = getToolChain(cfg.get(ctor::cfg::build_cxx, cxx_prog)); initialised = true; } 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") + +/* + +?get_configuration@ctor@@YAABUconfiguration@1@XZ +??__Fcfg@?1??get_configuration@ctor@@YAABUconfiguration@1@XZ@YAXXZ + += + +?default_get_configuration@@YAABUconfiguration@ctor@@XZ +??__Fcfg@?1??default_get_configuration@@YAABUconfiguration@ctor@@XZ@YAXXZ + +*/ +//#pragma comment(linker, "/alternatename:??__Fcfg@?1??get_configuration@ctor@@YAABUconfiguration@1@XZ@YAXXZ=??__Fcfg@?1??default_get_configuration@@YAABUconfiguration@ctor@@XZ@YAXXZ") +#endif namespace ctor { std::optional<std::string> includedir; @@ -69,7 +103,7 @@ bool ctor::configuration::has(const std::string& key) const return tools.find(key) != tools.end(); } -const std::string& ctor::configuration::get(const std::string& key, const std::string& default_value) const +std::string ctor::configuration::get(const std::string& key, const std::string& default_value) const { if(key == ctor::cfg::ctor_includedir && ctor::includedir) { @@ -91,14 +125,68 @@ const std::string& ctor::configuration::get(const std::string& key, const std::s 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; } +/* +class Args + : public std::vector<char*> +{ +public: + Args(const std::vector<std::string>& args) + { + string_data.push_back("./ctor"); + push_back(string_data.back().data()); + for(const auto& arg : args) + { + string_data.push_back(arg); + push_back(string_data.back().data()); + } + } + std::deque<std::string> string_data; +}; + */ class Args : public std::vector<char*> { @@ -136,6 +224,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; @@ -358,13 +449,12 @@ int regenerateCache(ctor::settings& settings, opt.add("help", no_argument, 'h', "Print this help text.", - [&]() { + [&]() -> int { std::cout << "Configure how to build with " << name << "\n"; std::cout << "Usage: " << name << " configure [options]\n\n"; std::cout << "Options:\n"; opt.help(); exit(0); - return 0; }); opt.process(static_cast<int>(vargs.size()), vargs.data()); @@ -651,6 +741,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; @@ -863,6 +954,25 @@ 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 ret = regenerateCache(settings, args_span[0], args, env); if(ret != 0) { |