diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-01-05 05:27:17 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-01-05 05:27:22 +0100 |
commit | cf160bdab6595e9888f23bf9df0cf03613068240 (patch) | |
tree | 28c7e3c4d811dad4eb6547b37e8b3a438c366ea2 /backend | |
parent | a548abb5a6a83c9318e9db3cf71170a7610e2758 (diff) |
Get cflags from pkg config dependency
Diffstat (limited to 'backend')
-rw-r--r-- | backend/ninja/Ninja.cpp | 29 | ||||
-rw-r--r-- | backend/ninja/Ninja.hpp | 2 |
2 files changed, 21 insertions, 10 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 1990926..50cd577 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -238,7 +238,7 @@ namespace backend // TODO: First check if pkg-config is installed. If it's not, only check dependencies that exists in the dependencies sub directory. // If pkg-config is installed and dependency is not installed, check in dependencies sub directory. - Result<bool> Ninja::getLinkerFlags(const SibsConfig &config, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback) const + Result<bool> Ninja::getLinkerFlags(const SibsConfig &config, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback, CflagsCallbackFunc cflagsCallbackFunc) const { const vector<Dependency> &dependencies = config.getDependencies(); if(dependencies.empty()) return Result<bool>::Ok(true); @@ -268,10 +268,10 @@ namespace backend } } - Result<string> pkgConfigLinkerFlagsResult = PkgConfig::getDynamicLibsLinkerFlags(pkgConfigDependencies); - if (pkgConfigLinkerFlagsResult.isErr()) + Result<PkgConfigFlags> pkgConfigFlagsResult = PkgConfig::getDynamicLibsFlags(pkgConfigDependencies); + if (!pkgConfigFlagsResult) { - printf("%s, using global lib...\n", pkgConfigLinkerFlagsResult.getErrMsg().c_str()); + printf("%s, using global lib...\n", pkgConfigFlagsResult.getErrMsg().c_str()); globalLibDependencies.reserve(globalLibDependencies.size() + pkgConfigDependencies.size()); for (const Dependency &pkgConfigDependency : pkgConfigDependencies) { @@ -281,8 +281,11 @@ namespace backend } else { - if (!pkgConfigLinkerFlagsResult.unwrap().empty()) - dynamicLinkerFlagCallback(pkgConfigLinkerFlagsResult.unwrap()); + const PkgConfigFlags &pkgConfigFlag = pkgConfigFlagsResult.unwrap(); + if (!pkgConfigFlag.linkerFlags.empty()) + dynamicLinkerFlagCallback(pkgConfigFlag.linkerFlags); + if(!pkgConfigFlag.cflags.empty()) + cflagsCallbackFunc(pkgConfigFlag.cflags); } #else for (const Dependency &dependency : dependencies) @@ -381,8 +384,15 @@ namespace backend allLinkerFlags += " "; allLinkerFlags += linkerFlag; }; + + string cflags; + auto cflagsCallbackFunc = [&cflags](const string &dependencyCflags) + { + cflags += " "; + cflags += dependencyCflags; + }; - Result<bool> linkerFlags = getLinkerFlags(config, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallback, globalIncludeDirCallback); + Result<bool> linkerFlags = getLinkerFlags(config, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallback, globalIncludeDirCallback, cflagsCallbackFunc); if (linkerFlags.isErr()) return Result<bool>::Err(linkerFlags.getErrMsg()); @@ -587,14 +597,15 @@ namespace backend case Compiler::GCC: { // -Werror - result += " '-I" + config.getPackageName() + "@exe' '-I..' -Wall -Wextra -Werror=return-type -fexceptions -fdiagnostics-show-option '-fdiagnostics-color=always' '-pipe' '-D_FILE_OFFSET_BITS=64' '-Winvalid-pch' '-Wnon-virtual-dtor' " + optimizationFlags + " '-g'"; + result += " '-I" + config.getPackageName() + "@exe' " + cflags + " '-I..' -Wall -Wextra -Werror=return-type -fexceptions -fdiagnostics-show-option '-fdiagnostics-color=always' '-pipe' '-D_FILE_OFFSET_BITS=64' '-Winvalid-pch' '-Wnon-virtual-dtor' " + optimizationFlags + " '-g'"; break; } case Compiler::MSVC: { result += " "; result += optimizationFlags; - result += " /EHsc"; + result += " /EHsc "; + result += cflags; switch (config.getOptimizationLevel()) { case OPT_LEV_DEBUG: diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp index eeea1be..fc6842f 100644 --- a/backend/ninja/Ninja.hpp +++ b/backend/ninja/Ninja.hpp @@ -34,7 +34,7 @@ namespace backend bool containsSourceFile(const std::string &filepath) const; bool containsTestSourceDir(const std::string &dir) const; bool containsDependency(const std::string &dependency) const; - sibs::Result<bool> getLinkerFlags(const sibs::SibsConfig &config, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback, sibs::GlobalIncludeDirCallbackFunc globalIncludeDirCallback) const; + sibs::Result<bool> getLinkerFlags(const sibs::SibsConfig &config, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback, sibs::GlobalIncludeDirCallbackFunc globalIncludeDirCallback, sibs::CflagsCallbackFunc cflagsCallbackFunc) const; sibs::Result<bool> compile(const _tinydir_char_t *buildFilePath); private: std::vector<std::string> sourceFiles; |