diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/BackendUtils.cpp | 2 | ||||
-rw-r--r-- | backend/ninja/Ninja.cpp | 106 |
2 files changed, 90 insertions, 18 deletions
diff --git a/backend/BackendUtils.cpp b/backend/BackendUtils.cpp index b790978..26608c7 100644 --- a/backend/BackendUtils.cpp +++ b/backend/BackendUtils.cpp @@ -79,7 +79,7 @@ namespace backend string filePathUtf8 = toUtf8(pathNative.c_str()); ninjaProject->addTestSourceDir(filePathUtf8.c_str()); } - else if(recursive && !directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs())) + else if(recursive && !directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs()) && !_tinydir_strcmp(pathNative.c_str(), TINYDIR_STRING("sibs-build"))) { FileString projectConfPath = file->path; #if OS_FAMILY == OS_FAMILY_WINDOWS diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 9d5dc42..ca88f40 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -365,9 +365,9 @@ namespace backend if(config.getCompiler() == Compiler::GCC && config.getSanitize()) { return { - ninja::NinjaArg("-fno-omit-frame-pointer"), - ninja::NinjaArg("-fsanitize=address"), - ninja::NinjaArg("-fsanitize=undefined") + ninja::NinjaArg::createRaw("-fno-omit-frame-pointer"), + ninja::NinjaArg::createRaw("-fsanitize=address"), + ninja::NinjaArg::createRaw("-fsanitize=undefined") }; } return {}; @@ -384,19 +384,19 @@ namespace backend case OPT_LEV_DEBUG: { return { - ninja::NinjaArg("-Og"), - ninja::NinjaArg("-g3"), - ninja::NinjaArg("-D_FORTIFY_SOURCE=2"), - ninja::NinjaArg("-D_GLIBCXX_ASSERTIONS"), - ninja::NinjaArg("-fasynchronous-unwind-tables") + ninja::NinjaArg::createRaw("-Og"), + ninja::NinjaArg::createRaw("-g3"), + ninja::NinjaArg::createRaw("-D_FORTIFY_SOURCE=2"), + ninja::NinjaArg::createRaw("-D_GLIBCXX_ASSERTIONS"), + ninja::NinjaArg::createRaw("-fasynchronous-unwind-tables") }; } case OPT_LEV_RELEASE: { return { - ninja::NinjaArg("-O3"), - ninja::NinjaArg("-g0"), - ninja::NinjaArg("-DNDEBUG") + ninja::NinjaArg::createRaw("-O3"), + ninja::NinjaArg::createRaw("-g0"), + ninja::NinjaArg::createRaw("-DNDEBUG") }; } } @@ -409,16 +409,16 @@ namespace backend case OPT_LEV_DEBUG: { return { - ninja::NinjaArg("/Od"), - ninja::NinjaArg("/MTd") + ninja::NinjaArg::createRaw("/Od"), + ninja::NinjaArg::createRaw("/MTd") }; } case OPT_LEV_RELEASE: { return { - ninja::NinjaArg("/Ox"), - ninja::NinjaArg("/MT"), - ninja::NinjaArg("/DNDEBUG") + ninja::NinjaArg::createRaw("/Ox"), + ninja::NinjaArg::createRaw("/MT"), + ninja::NinjaArg::createRaw("/DNDEBUG") }; } } @@ -459,6 +459,74 @@ namespace backend return cIncludes; } + static vector<ninja::NinjaArg> extractIncludesFromCFlag(Compiler compiler, const ninja::NinjaArg &cflag) + { + vector<ninja::NinjaArg> result; + string includeStartStr; + + switch (compiler) + { + case Compiler::GCC: + { + includeStartStr = "-I"; + break; + } + case Compiler::MSVC: + { + includeStartStr = "/I"; + } + default: + assert(false); + break; + } + + size_t index = 0; + while(index != string::npos) + { + char endChar = ' '; + size_t includeStartIndex = cflag.arg.find(includeStartStr, index); + if(includeStartIndex == string::npos) + break; + else if(includeStartIndex > 0) + { + if(cflag.arg[includeStartIndex - 1] == '"' || cflag.arg[includeStartIndex - 1] == '\'') + endChar = cflag.arg[includeStartIndex - 1]; + } + includeStartIndex += includeStartStr.length(); + size_t includeEndIndex = cflag.arg.find(endChar, includeStartIndex); + index = includeEndIndex; + + if(includeEndIndex == string::npos) + includeEndIndex = cflag.arg.length(); + + result.push_back(ninja::NinjaArg::createRaw(cflag.arg.substr(includeStartIndex, includeEndIndex - includeStartIndex))); + } + + return result; + } + + static vector<ninja::NinjaArg> extractIncludesFromCFlags(Compiler compiler, const vector<ninja::NinjaArg> &cflags) + { + vector<ninja::NinjaArg> result; + for(const ninja::NinjaArg &cflag : cflags) + { + vector<ninja::NinjaArg> subCFlags = extractIncludesFromCFlag(compiler, cflag); + result.insert(result.end(), subCFlags.begin(), subCFlags.end()); + } + return result; + } + + static vector<ninja::NinjaArg> convertCFlagsIncludesToZigIncludes(Compiler compiler, const vector<ninja::NinjaArg> &cflags) + { + vector<ninja::NinjaArg> result; + result = extractIncludesFromCFlags(compiler, cflags); + for(ninja::NinjaArg &include : result) + { + include.arg = "-isystem \"" + include.arg + "\""; + } + return result; + } + Result<bool> Ninja::build(const SibsConfig &config, const _tinydir_char_t *savePath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback) { if (!sourceFiles.empty()) @@ -739,7 +807,10 @@ namespace backend compileCppRule->depFile = "$out.d"; // TODO: Specify -mconsole or -mwindows for windows. - // TODO: Convert sibs defines to const variables in a zig file that other zig files can include (like a config file) + // TODO: Convert sibs defines to const variables in a zig file that other zig files can include (like a config file). + + // TODO: Find a way to do this more efficiently + vector<ninja::NinjaArg> cflagsIncludes = convertCFlagsIncludesToZigIncludes(config.getCompiler(), cflags); vector<ninja::NinjaArg> compileZigArgs = { ninja::NinjaArg::createRaw("zig build-obj"), ninja::NinjaArg::createRaw("$in"), @@ -749,6 +820,7 @@ namespace backend ninja::NinjaArg::createRaw("--library c"), // TODO: Remove this if project does not depend on c libraries or project only has .zig files ninja::NinjaArg::createRaw("$globalIncDirZig") }; + compileZigArgs.insert(compileZigArgs.end(), cflagsIncludes.begin(), cflagsIncludes.end()); if(config.getOptimizationLevel() == sibs::OPT_LEV_RELEASE) { |