diff options
Diffstat (limited to 'src/tools.cc')
-rw-r--r-- | src/tools.cc | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/tools.cc b/src/tools.cc index 4aaa515..ddb1463 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -8,35 +8,44 @@ #include <cassert> -ToolChain getToolChain(ctor::output_system system) +ctor::toolchain getToolChain(const std::string& compiler) { - const auto& c = ctor::get_configuration(); - std::string compiler; - switch(system) - { - case ctor::output_system::host: - compiler = c.get(ctor::cfg::host_cxx, "g++"); - break; - case ctor::output_system::build: - compiler = c.get(ctor::cfg::build_cxx, "g++"); - break; - } - std::filesystem::path cc(compiler); auto cc_cmd = cc.stem().string(); // Note: "g++" is a substring of "clang++" so "clang++" must be tested first. if(cc_cmd.find("clang++") != std::string::npos) { - return ToolChain::clang; + return ctor::toolchain::clang; } else if(cc_cmd.find("g++") != std::string::npos) { - return ToolChain::gcc; + return ctor::toolchain::gcc; } std::cerr << "Unsupported output system.\n"; - return ToolChain::gcc; + return ctor::toolchain::gcc; +} + +ctor::toolchain getToolChain(ctor::output_system system) +{ + const auto& cfg = ctor::get_configuration(); + if(system == ctor::output_system::host) + { + if(cfg.host_toolchain != ctor::toolchain::none) + { + return cfg.host_toolchain; + } + return getToolChain(cfg.get(ctor::cfg::host_cxx, "g++")); + } + else + { + if(cfg.build_toolchain != ctor::toolchain::none) + { + return cfg.build_toolchain; + } + return getToolChain(cfg.get(ctor::cfg::build_cxx, "g++")); + } } namespace @@ -86,15 +95,18 @@ std::vector<std::string> getOptionGcc(opt option, const std::string& arg) } } -std::vector<std::string> getOption(ToolChain tool_chain, +std::vector<std::string> getOption(ctor::toolchain toolchain, opt option, const std::string& arg) { - switch(tool_chain) + switch(toolchain) { - case ToolChain::gcc: - case ToolChain::clang: + case ctor::toolchain::gcc: + case ctor::toolchain::clang: return getOptionGcc(option, arg); + case ctor::toolchain::any: + case ctor::toolchain::none: + break; } std::cerr << "Unsupported tool-chain.\n"; @@ -123,13 +135,16 @@ std::pair<opt, std::string> getOptionGcc(const std::string& flag) } std::pair<opt, std::string> getOption(const std::string& flag, - ToolChain tool_chain) + ctor::toolchain toolchain) { - switch(tool_chain) + switch(toolchain) { - case ToolChain::gcc: - case ToolChain::clang: + case ctor::toolchain::gcc: + case ctor::toolchain::clang: return getOptionGcc(flag); + case ctor::toolchain::any: + case ctor::toolchain::none: + break; } std::cerr << "Unsupported tool-chain.\n"; |