aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/BackendUtils.cpp118
-rw-r--r--backend/BackendUtils.hpp13
-rw-r--r--backend/ninja/Ninja.cpp107
-rw-r--r--include/CmakeModule.hpp1
-rw-r--r--src/CmakeModule.cpp20
-rw-r--r--src/main.cpp1
6 files changed, 157 insertions, 103 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;
}
diff --git a/include/CmakeModule.hpp b/include/CmakeModule.hpp
index 0df4a2e..ad28f57 100644
--- a/include/CmakeModule.hpp
+++ b/include/CmakeModule.hpp
@@ -9,5 +9,6 @@ namespace sibs
{
public:
Result<bool> compile(const SibsConfig &config, const FileString &buildPath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
+ static void setCmakePath(const FileString &path);
};
}
diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp
index a573e85..ed04e26 100644
--- a/src/CmakeModule.cpp
+++ b/src/CmakeModule.cpp
@@ -2,6 +2,7 @@
#include "../include/Exec.hpp"
#include "../include/GlobalLib.hpp"
#include "../include/PkgConfig.hpp"
+#include "../backend/BackendUtils.hpp"
#if OS_FAMILY == OS_FAMILY_POSIX
#define nprintf printf
@@ -10,9 +11,17 @@
#endif
using namespace std;
+using namespace backend;
namespace sibs
{
+ static FileString cmakePath = TINYDIR_STRING("cmake");
+
+ void CmakeModule::setCmakePath(const FileString &path)
+ {
+ cmakePath = path;
+ }
+
Result<bool> CmakeModule::compile(const SibsConfig &config, const FileString &buildPath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
{
// TODO: Make packaging work with cmake projects
@@ -128,7 +137,8 @@ namespace sibs
if (createBuildDirResult.isErr())
return createBuildDirResult;
- FileString cmd = TINYDIR_STRING("cmake ");
+ FileString cmd = cmakePath;
+ cmd += TINYDIR_STRING(" ");
if(config.getCompiler() == Compiler::GCC)
{
if(config.getSanitize())
@@ -207,12 +217,16 @@ namespace sibs
if(config.getPackageType() != PackageType::EXECUTABLE)
{
+ const _tinydir_char_t *dynamicLibExtension = TINYDIR_STRING(CONFIG_DYNAMIC_LIB_FILE_EXTENSION);
+ if(config.getCompiler() == Compiler::MINGW_W64)
+ dynamicLibExtension = TINYDIR_STRING("dll");
+
string buildPathUtf8 = toUtf8(buildPath);
nprintf("Searching for libraries generate by cmake in build path: %s\n", buildPathUtf8.c_str());
walkDirFilesRecursive(buildPath.c_str(),
- [&config, &parentProjStaticLinkerFlagCallbackFunc, &parentProjDynamicLinkerFlagCallbackFunc](tinydir_file *file)
+ [&config, &parentProjStaticLinkerFlagCallbackFunc, &parentProjDynamicLinkerFlagCallbackFunc, dynamicLibExtension](tinydir_file *file)
{
- if(_tinydir_strcmp(file->extension, CONFIG_DYNAMIC_LIB_FILE_EXTENSION) == 0 || _tinydir_strcmp(file->extension, CONFIG_STATIC_LIB_FILE_EXTENSION) == 0)
+ if(_tinydir_strcmp(file->extension, dynamicLibExtension) == 0 || _tinydir_strcmp(file->extension, CONFIG_STATIC_LIB_FILE_EXTENSION) == 0)
{
string libFileUtf8 = toUtf8(file->path);
nprintf("Library generated by cmake: %s\n", libFileUtf8.c_str());
diff --git a/src/main.cpp b/src/main.cpp
index 1265d3d..c8e9b27 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -559,6 +559,7 @@ static int buildProject(int argc, const _tinydir_char_t **argv)
{
compiler = Compiler::MINGW_W64;
PkgConfig::setPkgConfigPath(TINYDIR_STRING("x86_64-w64-mingw32-pkg-config"));
+ CmakeModule::setCmakePath(TINYDIR_STRING("x86_64-w64-mingw32-cmake"));
}
#else
Compiler compiler = Compiler::MSVC;