summaryrefslogtreecommitdiff
path: root/src/tools.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2022-12-28 13:49:53 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2023-01-12 15:15:53 +0100
commitcc4e14d243f4e7e1ad487d8865c5ffc8423e473d (patch)
tree10473afd8cf2f6bd6385e1d50b0e2699069fb3eb /src/tools.cc
parent430801b1307b4c820885f161d0b003011c892d77 (diff)
Add detected toolchain to configuration.cc
Diffstat (limited to 'src/tools.cc')
-rw-r--r--src/tools.cc63
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";