aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--backend/ninja/Ninja.cpp57
2 files changed, 24 insertions, 35 deletions
diff --git a/README.md b/README.md
index e128b25..17b4b0f 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,7 @@ Automatic cross compilation (`sibs build --platform <platform>`)currently only w
Cross compilation does currently not work if you have zig files as zig doesn't support libc when cross compiling at the moment.
You can run `scripts/mingw_package.py` to automatically copy dynamic library dependencies of your executable to the same directory as the executable, so the library can be found when running the executable on windows; this also allows you to bundle your application and distribute it without external dependencies. To run `scripts/mingw_package.py` you need to install pefile python library `sudo pip install pefile`.
-Manual cross compilation can be done by replacing c, c++ compilers and linker (ar) using the environment variable CC, CXX and AR.
+Manual cross compilation can be done by replacing c, c++ compilers and static library archiver (ar) using the environment variable CC, CXX and AR.
# IDE support
Sibs generates a compile_commands.json in the project root directory when executing `sibs build` and tools that support clang completion can be used, such as YouCompleteMe or cquery.
There are several editors that support YouCompleteMe, including Vim, Emacs and Visual Studio Code. Visual studio code now also supports clang completion with C/C++ extension by Microsoft. I recommend using Visual Studio Code along with cquery (https://github.com/cquery-project/cquery/wiki), which gives you very good IDE support for your C/C++ projects.
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 08ef41d..0408ca4 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -698,11 +698,21 @@ namespace backend
return result;
}
+ static FileString array_to_file_string(const std::vector<FileString> &vec) {
+ FileString result;
+ for(const FileString &str : vec) {
+ if(!result.empty())
+ result += TINYDIR_STRING(" ");
+ result += str;
+ }
+ return result;
+ }
+
Result<bool> Ninja::build(const SibsConfig &config, const _tinydir_char_t *savePath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
{
- std::vector<FileString> cCompilerName = BackendUtils::getCompilerCExecutable(config.getCompiler());
- std::vector<FileString> cppCompilerName = BackendUtils::getCompilerCppExecutable(config.getCompiler());
- std::vector<FileString> compilerLinker = BackendUtils::getCompilerLinker(config.getCompiler());
+ FileString cCompilerName = array_to_file_string(BackendUtils::getCompilerCExecutable(config.getCompiler()));
+ FileString cppCompilerName = array_to_file_string(BackendUtils::getCompilerCppExecutable(config.getCompiler()));
+ FileString compilerLinker = array_to_file_string(BackendUtils::getCompilerLinker(config.getCompiler()));
RuntimeCompilerType cCompilerType = BackendUtils::getCCompilerType(config.getCompiler());
RuntimeCompilerType cppCompilerType = BackendUtils::getCppCompilerType(config.getCompiler());
@@ -1000,13 +1010,8 @@ namespace backend
ninja::NinjaArg("-Wnon-virtual-dtor")
});
- for(auto it = cCompilerName.rbegin(), end = cCompilerName.rend(); it != end; ++it) {
- compileCCommand.insert(compileCCommand.begin(), ninja::NinjaArg(*it));
- }
-
- for(auto it = cppCompilerName.rbegin(), end = cppCompilerName.rend(); it != end; ++it) {
- compileCppCommand.insert(compileCppCommand.begin(), ninja::NinjaArg(*it));
- }
+ compileCCommand.insert(compileCCommand.begin(), ninja::NinjaArg(cCompilerName));
+ compileCppCommand.insert(compileCppCommand.begin(), ninja::NinjaArg(cppCompilerName));
break;
}
case Compiler::MSVC:
@@ -1326,13 +1331,9 @@ namespace backend
case Compiler::GCC:
{
if(usesCppFiles) {
- for(const FileString &arg : cppCompilerName) {
- buildExeArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildExeArgs.push_back(ninja::NinjaArg(cppCompilerName));
} else {
- for(const FileString &arg : cCompilerName) {
- buildExeArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildExeArgs.push_back(ninja::NinjaArg(cCompilerName));
}
string rpath = extractDynamicLibDirsFromLinkerFlags(dynamicLinkerFlags);
buildExeArgs.insert(buildExeArgs.end(), {
@@ -1383,9 +1384,7 @@ namespace backend
}
case Compiler::MSVC:
{
- for(const FileString &arg : cppCompilerName) {
- buildExeArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildExeArgs.push_back(ninja::NinjaArg(cppCompilerName));
// TODO: Do not link all of these. Find a way to only link the ones that are needed
buildExeArgs.insert(buildExeArgs.end(), {
ninja::NinjaArg::createRaw("$in"),
@@ -1483,9 +1482,7 @@ namespace backend
case Compiler::MINGW_W64:
case Compiler::GCC:
{
- for(const FileString &arg : compilerLinker) {
- buildStaticArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildStaticArgs.push_back(ninja::NinjaArg(compilerLinker));
buildStaticArgs.insert(buildStaticArgs.end(), {
ninja::NinjaArg::createRaw("rcs"),
ninja::NinjaArg::createRaw("$out"),
@@ -1495,9 +1492,7 @@ namespace backend
}
case Compiler::MSVC:
{
- for(const FileString &arg : compilerLinker) {
- buildStaticArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildStaticArgs.push_back(ninja::NinjaArg(compilerLinker));
buildStaticArgs.insert(buildStaticArgs.end(), {
ninja::NinjaArg::createRaw("/OUT:$out"),
ninja::NinjaArg::createRaw("$in")
@@ -1576,13 +1571,9 @@ namespace backend
case Compiler::GCC:
{
if(usesCppFiles) {
- for(const FileString &arg : cppCompilerName) {
- buildDynamicArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildDynamicArgs.push_back(ninja::NinjaArg(cppCompilerName));
} else {
- for(const FileString &arg : cCompilerName) {
- buildDynamicArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildDynamicArgs.push_back(ninja::NinjaArg(cCompilerName));
}
buildDynamicArgs.insert(buildDynamicArgs.end(), {
ninja::NinjaArg::createRaw("$in"),
@@ -1625,9 +1616,7 @@ namespace backend
}
case Compiler::MSVC:
{
- for(const FileString &arg : compilerLinker) {
- buildDynamicArgs.push_back(ninja::NinjaArg(arg));
- }
+ buildDynamicArgs.push_back(ninja::NinjaArg(compilerLinker));
buildDynamicArgs.insert(buildDynamicArgs.end(), {
ninja::NinjaArg::createRaw("/OUT:$out"),
ninja::NinjaArg::createRaw("$in"),