aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/BackendUtils.cpp118
-rw-r--r--backend/BackendUtils.hpp13
-rw-r--r--backend/ninja/Ninja.cpp107
3 files changed, 138 insertions, 100 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;
+ }
}
diff --git a/backend/BackendUtils.hpp b/backend/BackendUtils.hpp
index f99d7e5..d53620c 100644
--- a/backend/BackendUtils.hpp
+++ b/backend/BackendUtils.hpp
@@ -5,6 +5,14 @@
namespace backend
{
class Ninja;
+
+ enum class RuntimeCompilerType
+ {
+ NONE,
+ OTHER,
+ CLANG,
+ EMSCRIPTEN
+ };
class BackendUtils
{
@@ -13,5 +21,10 @@ namespace backend
static sibs::Language getFileLanguage(const _tinydir_char_t *extension);
static sibs::Language getFileLanguage(tinydir_file *file);
static void collectSourceFiles(const _tinydir_char_t *projectPath, Ninja *ninjaProject, const sibs::SibsConfig &sibsConfig, bool recursive = true);
+ static std::string getCompilerCExecutable(sibs::Compiler compiler);
+ static std::string getCompilerCppExecutable(sibs::Compiler compiler);
+ static std::string getCompilerLinker(sibs::Compiler compiler);
+ static RuntimeCompilerType getCCompilerType(sibs::Compiler compiler);
+ static RuntimeCompilerType getCppCompilerType(sibs::Compiler compiler);
};
}
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 526fccb..d5bfc67 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -722,109 +722,14 @@ namespace backend
return result;
}
- static string getCompilerCExecutable(Compiler compiler)
- {
- char *cc = std::getenv("CC");
- if(cc)
- return cc;
-
- string result;
- switch(compiler)
- {
- case Compiler::GCC:
- result = "ccache cc";
- break;
- case Compiler::MINGW_W64:
- result = "x86_64-w64-mingw32-cc";
- break;
- case Compiler::MSVC:
- result = "cl.exe";
- break;
- }
- return result;
- }
-
- static string getCompilerCppExecutable(Compiler compiler)
- {
- char *cxx = std::getenv("CXX");
- if(cxx)
- return cxx;
-
- string result;
- switch(compiler)
- {
- case Compiler::GCC:
- result = "ccache c++";
- break;
- case Compiler::MINGW_W64:
- result = "x86_64-w64-mingw32-c++";
- break;
- case Compiler::MSVC:
- result = "cl.exe";
- break;
- }
- return result;
- }
-
- static string getCompilerLinker(Compiler compiler)
- {
- char *ar = std::getenv("AR");
- if(ar)
- return ar;
-
- string result;
- switch(compiler)
- {
- case Compiler::GCC:
- result = "ar";
- break;
- case Compiler::MINGW_W64:
- result = "x86_64-w64-mingw32-ar";
- break;
- case Compiler::MSVC:
- result = "lib.exe";
- break;
- }
- return result;
- }
-
- enum class RuntimeCompilerType
- {
- NONE,
- OTHER,
- CLANG,
- EMSCRIPTEN
- };
-
Result<bool> Ninja::build(const SibsConfig &config, const _tinydir_char_t *savePath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
{
- string cCompilerName = getCompilerCExecutable(config.getCompiler());
- string cppCompilerName = getCompilerCppExecutable(config.getCompiler());
- string compilerLinker = getCompilerLinker(config.getCompiler());
-
- RuntimeCompilerType cCompilerType = RuntimeCompilerType::NONE;
- Result<ExecResult> cCompilerVersion = exec(toFileString(cCompilerName) + 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;
- }
+ string cCompilerName = BackendUtils::getCompilerCExecutable(config.getCompiler());
+ string cppCompilerName = BackendUtils::getCompilerCppExecutable(config.getCompiler());
+ string compilerLinker = BackendUtils::getCompilerLinker(config.getCompiler());
- RuntimeCompilerType cppCompilerType = RuntimeCompilerType::NONE;
- Result<ExecResult> cppCompilerVersion = exec(toFileString(cppCompilerName) + 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;
- }
+ RuntimeCompilerType cCompilerType = BackendUtils::getCCompilerType(config.getCompiler());
+ RuntimeCompilerType cppCompilerType = BackendUtils::getCppCompilerType(config.getCompiler());
if(cCompilerType != RuntimeCompilerType::NONE && cppCompilerType != RuntimeCompilerType::NONE && cCompilerType != cppCompilerType)
return Result<bool>::Err("The c and c++ compiler has to be of the same type");
@@ -1608,6 +1513,8 @@ namespace backend
const char *fileExtension = CONFIG_DYNAMIC_LIB_FILE_EXTENSION;
if(compilerType == RuntimeCompilerType::EMSCRIPTEN)
fileExtension = "wasm";
+ else if(config.getCompiler() == Compiler::MINGW_W64)
+ fileExtension = "dll";
generatedFile = "lib" + config.getPackageName() + "." + fileExtension;
break;
}