aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CmakeModule.cpp1
-rw-r--r--src/PkgConfig.cpp62
2 files changed, 62 insertions, 1 deletions
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