From 9f9507d75ccdff561a390c441d45c000382c42fc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Nov 2018 08:15:07 +0100 Subject: Use dll files for mingw, use mingw cmake --- backend/BackendUtils.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) (limited to 'backend/BackendUtils.cpp') 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 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 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; + } } -- cgit v1.2.3