aboutsummaryrefslogtreecommitdiff
path: root/backend/BackendUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/BackendUtils.cpp')
-rw-r--r--backend/BackendUtils.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/backend/BackendUtils.cpp b/backend/BackendUtils.cpp
index 37a5002..158cd12 100644
--- a/backend/BackendUtils.cpp
+++ b/backend/BackendUtils.cpp
@@ -1,10 +1,15 @@
#include "BackendUtils.hpp"
#include "../include/FileUtil.hpp"
+#include "../include/Exec.hpp"
#include "ninja/Ninja.hpp"
using namespace std;
using namespace sibs;
+static const char *cCompilerPath = nullptr;
+static const char *cppCompilerPath = nullptr;
+static const char *linkerPath = nullptr;
+
namespace backend
{
static bool isPathSubPathOf(const FileString &path, const FileString &subPathOf)
@@ -125,4 +130,117 @@ namespace backend
return true;
});
}
+
+ string BackendUtils::getCompilerCExecutable(Compiler compiler)
+ {
+ if(cCompilerPath)
+ return cCompilerPath;
+
+ char *cc = std::getenv("CC");
+ if(cc)
+ {
+ cCompilerPath = cc;
+ return cCompilerPath;
+ }
+
+ switch(compiler)
+ {
+ case Compiler::GCC:
+ cCompilerPath = "ccache cc";
+ break;
+ case Compiler::MINGW_W64:
+ cCompilerPath = "x86_64-w64-mingw32-cc";
+ break;
+ case Compiler::MSVC:
+ cCompilerPath = "cl.exe";
+ break;
+ }
+ return cCompilerPath;
+ }
+
+ string BackendUtils::getCompilerCppExecutable(Compiler compiler)
+ {
+ if(cppCompilerPath)
+ return cppCompilerPath;
+
+ char *cxx = std::getenv("CXX");
+ if(cxx)
+ {
+ cppCompilerPath = cxx;
+ return cppCompilerPath;
+ }
+
+ switch(compiler)
+ {
+ case Compiler::GCC:
+ cppCompilerPath = "ccache c++";
+ break;
+ case Compiler::MINGW_W64:
+ cppCompilerPath = "x86_64-w64-mingw32-c++";
+ break;
+ case Compiler::MSVC:
+ cppCompilerPath = "cl.exe";
+ break;
+ }
+ return cppCompilerPath;
+ }
+
+ string BackendUtils::getCompilerLinker(Compiler compiler)
+ {
+ if(linkerPath)
+ return linkerPath;
+
+ char *ar = std::getenv("AR");
+ if(ar)
+ {
+ linkerPath = ar;
+ return linkerPath;
+ }
+
+ switch(compiler)
+ {
+ case Compiler::GCC:
+ linkerPath = "ar";
+ break;
+ case Compiler::MINGW_W64:
+ linkerPath = "x86_64-w64-mingw32-ar";
+ break;
+ case Compiler::MSVC:
+ linkerPath = "lib.exe";
+ break;
+ }
+ return linkerPath;
+ }
+
+ RuntimeCompilerType BackendUtils::getCCompilerType(Compiler compiler)
+ {
+ RuntimeCompilerType cCompilerType = RuntimeCompilerType::NONE;
+ Result<ExecResult> cCompilerVersion = exec(toFileString(getCompilerCExecutable(compiler)) + TINYDIR_STRING(" --version"));
+ if(cCompilerVersion && cCompilerVersion.unwrap().exitCode == 0)
+ {
+ if(cCompilerVersion.unwrap().execStdout.find("Emscripten") != string::npos)
+ cCompilerType = RuntimeCompilerType::EMSCRIPTEN;
+ else if(cCompilerVersion.unwrap().execStdout.find("clang") != string::npos)
+ cCompilerType = RuntimeCompilerType::CLANG;
+ else
+ cCompilerType = RuntimeCompilerType::OTHER;
+ }
+ return cCompilerType;
+ }
+
+ RuntimeCompilerType BackendUtils::getCppCompilerType(Compiler compiler)
+ {
+ RuntimeCompilerType cppCompilerType = RuntimeCompilerType::NONE;
+ Result<ExecResult> cppCompilerVersion = exec(toFileString(getCompilerCppExecutable(compiler)) + TINYDIR_STRING(" --version"));
+ if(cppCompilerVersion && cppCompilerVersion.unwrap().exitCode == 0)
+ {
+ if(cppCompilerVersion.unwrap().execStdout.find("Emscripten") != string::npos)
+ cppCompilerType = RuntimeCompilerType::EMSCRIPTEN;
+ else if(cppCompilerVersion.unwrap().execStdout.find("clang") != string::npos)
+ cppCompilerType = RuntimeCompilerType::CLANG;
+ else
+ cppCompilerType = RuntimeCompilerType::OTHER;
+ }
+ return cppCompilerType;
+ }
}