aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--backend/ninja/Ninja.cpp29
-rw-r--r--backend/ninja/Ninja.hpp2
-rw-r--r--include/Linker.hpp1
-rw-r--r--include/PkgConfig.hpp8
-rw-r--r--include/Result.hpp8
-rw-r--r--project.conf2
-rw-r--r--src/CmakeModule.cpp1
-rw-r--r--src/PkgConfig.cpp62
9 files changed, 102 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 1ea6946..67847e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ sibs-build/
sibs.kdev4
build/
cmake/build/
+cmake-build-debug/
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;
diff --git a/include/Linker.hpp b/include/Linker.hpp
index 90bebe2..acf31e4 100644
--- a/include/Linker.hpp
+++ b/include/Linker.hpp
@@ -7,6 +7,7 @@ namespace sibs
{
using LinkerFlagCallbackFunc = std::function<void(const std::string&)>;
using GlobalIncludeDirCallbackFunc = std::function<void(const std::string&)>;
+ using CflagsCallbackFunc = std::function<void(const std::string&)>;
}
#endif //SIBS_LINKER_HPP
diff --git a/include/PkgConfig.hpp b/include/PkgConfig.hpp
index e525843..e41b216 100644
--- a/include/PkgConfig.hpp
+++ b/include/PkgConfig.hpp
@@ -10,6 +10,12 @@
namespace sibs
{
+ struct PkgConfigFlags
+ {
+ std::string linkerFlags;
+ std::string cflags;
+ };
+
class PkgConfig
{
public:
@@ -17,6 +23,8 @@ namespace sibs
static Result<bool> validatePackageExists(const std::string &name);
static Result<bool> validatePackageVersionAtLeast(const std::string &name, const std::string &version);
static Result<std::string> getDynamicLibsLinkerFlags(const std::vector<Dependency> &libs);
+ static Result<std::string> getDynamicLibsCflags(const std::vector<Dependency> &libs);
+ static Result<PkgConfigFlags> getDynamicLibsFlags(const std::vector<Dependency> &libs);
};
}
#endif // OS_FAMILY_POSIX
diff --git a/include/Result.hpp b/include/Result.hpp
index e8f4d12..22cee35 100644
--- a/include/Result.hpp
+++ b/include/Result.hpp
@@ -16,6 +16,13 @@ namespace sibs
result.errorCode = 0;
return result;
}
+
+ static Result Ok(const T &&value)
+ {
+ Result result(value);
+ result.errorCode = 0;
+ return result;
+ }
template <typename OtherType>
static Result Err(const Result<OtherType> &other)
@@ -57,6 +64,7 @@ namespace sibs
operator bool () { return isOk(); }
private:
Result(const T &_value = T()) : value(_value) {}
+ Result(const T &&_value) : value(_value) {}
private:
T value;
std::string errMsg;
diff --git a/project.conf b/project.conf
index 93665a5..2271dbe 100644
--- a/project.conf
+++ b/project.conf
@@ -5,7 +5,7 @@ version = "0.1.3"
authors = ["DEC05EBA <0xdec05eba@gmail.com>"]
tests = "tests"
platforms = ["linux32", "linux64", "win64"]
-ignore_dirs = ["cmake"]
+ignore_dirs = ["cmake", "cmake-build-debug", "build"]
[dependencies]
libcurl = "7.57.0"
diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp
index d82eaf6..8606a42 100644
--- a/src/CmakeModule.cpp
+++ b/src/CmakeModule.cpp
@@ -78,6 +78,7 @@ namespace sibs
}
}
+ // TODO: Use getDynamicLibsFlags instead which includes cflags?
Result<string> pkgConfigLinkerFlagsResult = PkgConfig::getDynamicLibsLinkerFlags(pkgConfigDependencies);
if (pkgConfigLinkerFlagsResult.isErr())
{
diff --git a/src/PkgConfig.cpp b/src/PkgConfig.cpp
index f9f8f9b..9a19387 100644
--- a/src/PkgConfig.cpp
+++ b/src/PkgConfig.cpp
@@ -16,7 +16,7 @@ namespace sibs
if(!isspace(input[i]))
return input.substr(0, i + 1);
}
- return input;
+ return "";
}
#if OS_FAMILY == OS_FAMILY_POSIX
@@ -143,5 +143,65 @@ namespace sibs
return Result<string>::Err(errMsg);
}
}
+
+ Result<string> PkgConfig::getDynamicLibsCflags(const vector<Dependency> &libs)
+ {
+ if(libs.empty()) return Result<string>::Ok("");
+
+ string args;
+ for(const Dependency &lib : libs)
+ {
+ args += " '";
+ args += lib.name;
+ args += "'";
+ }
+
+ string command = "pkg-config --cflags";
+ command += args;
+ Result<ExecResult> execResult = exec(command.c_str());
+ if(execResult.isErr())
+ return Result<string>::Err(execResult.getErrMsg());
+
+ if(execResult.unwrap().exitCode == 0)
+ {
+ execResult.unwrap().execStdout = trimRight(execResult.unwrap().execStdout);
+ return Result<string>::Ok(execResult.unwrap().execStdout);
+ }
+ else if(execResult.unwrap().exitCode == 1)
+ {
+ // TODO: This shouldn't happen because we check if each dependency is installed before this,
+ // but maybe the package is uninstalled somewhere between here...
+ // Would be better to recheck if each package is installed here again
+ // to know which package was uninstalled
+ return Result<string>::Err("Packages not found");
+ }
+ else if(execResult.unwrap().exitCode == 127)
+ {
+ return Result<string>::Err("pkg-config is not installed");
+ }
+ else
+ {
+ string errMsg = "Failed to get package dynamic lib cflags, Unknown error, exit code: ";
+ errMsg += to_string(execResult.unwrap().exitCode);
+ return Result<string>::Err(errMsg);
+ }
+ }
+
+ Result<PkgConfigFlags> PkgConfig::getDynamicLibsFlags(const vector<Dependency> &libs)
+ {
+ PkgConfigFlags flags;
+
+ Result<string> linkerFlagsResult = getDynamicLibsLinkerFlags(libs);
+ if(!linkerFlagsResult)
+ return Result<PkgConfigFlags>::Err(linkerFlagsResult);
+
+ Result<string> cflagsResult = getDynamicLibsCflags(libs);
+ if(!cflagsResult)
+ return Result<PkgConfigFlags>::Err(cflagsResult);
+
+ flags.linkerFlags = move(linkerFlagsResult.unwrap());
+ flags.cflags = move(cflagsResult.unwrap());
+ return Result<PkgConfigFlags>::Ok(flags);
+ }
}
#endif // OS_FAMILY_POSIX