aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-14 15:22:06 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-14 15:22:12 +0100
commit28d6b571139998915bce147abb58617884431192 (patch)
tree1b79ab0b85973beac33d833db5bc9be472a4dedd /src
parentc244361b8ae743bcb326b9a1a168f2fdcab491e8 (diff)
Add support for dynamic libraries (shared objects)
Diffstat (limited to 'src')
-rw-r--r--src/GlobalLib.cpp52
-rw-r--r--src/PkgConfig.cpp4
2 files changed, 39 insertions, 17 deletions
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index 617f993..a07e23d 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -55,7 +55,7 @@ namespace sibs
return false;
}
- Result<string> GlobalLib::getStaticLibsLinkerFlags(const string &globalLibRootDir, const string &name, const string &version, LinkerFlagCallbackFunc linkerFlagCallbackFunc)
+ Result<string> GlobalLib::getLibsLinkerFlags(const string &globalLibRootDir, const string &name, const string &version, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc)
{
Result<bool> packageExistsResult = validatePackageExists(globalLibRootDir, name);
if(packageExistsResult.isErr())
@@ -121,7 +121,22 @@ namespace sibs
return Result<string>::Err(errMsg);
}
- backend::Ninja ninja(backend::Ninja::LibraryType::STATIC);
+ backend::Ninja::LibraryType libraryType;
+ switch(sibsConfig.getPackageType())
+ {
+ case PackageType::STATIC:
+ libraryType = backend::Ninja::LibraryType::STATIC;
+ break;
+ case PackageType::DYNAMIC:
+ case PackageType::LIBRARY:
+ libraryType = backend::Ninja::LibraryType::DYNAMIC;
+ break;
+ default:
+ assert(false);
+ return Result<string>::Err("Unexpected error");
+ }
+
+ backend::Ninja ninja(libraryType);
walkDirFilesRecursive(packageDir.c_str(), [&ninja, &packageDir](tinydir_file *file)
{
if (isSourceFile(file))
@@ -141,15 +156,26 @@ namespace sibs
else
{
string debugBuildPath = packageDir + "/sibs-build/debug";
- string staticLibPath = debugBuildPath;
- staticLibPath += "/lib";
- staticLibPath += name;
- staticLibPath += ".a";
-
- string staticLibPathCmd = "'";
- staticLibPathCmd += staticLibPath;
- staticLibPathCmd += "'";
- linkerFlagCallbackFunc(staticLibPathCmd);
+ string libPath = debugBuildPath;
+ libPath += "/lib";
+ libPath += name;
+ if(libraryType == backend::Ninja::LibraryType::STATIC)
+ {
+ libPath += ".a";
+ string libPathCmd = "'";
+ libPathCmd += libPath;
+ libPathCmd += "'";
+ staticLinkerFlagCallbackFunc(libPathCmd);
+ libPath += ".a";
+ }
+ else
+ {
+ libPath += ".so";
+ string libPathCmd = "'";
+ libPathCmd += libPath;
+ libPathCmd += "'";
+ dynamicLinkerFlagCallbackFunc(libPathCmd);
+ }
// TODO: Use different directories depending on the project type, but .o build files should be in the same directory
// no matter what project type, since they are used for executables, static/dynamic libraries
@@ -157,7 +183,7 @@ namespace sibs
if(createBuildDirResult.isErr())
return Result<string>::Err(createBuildDirResult);
- Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str(), linkerFlagCallbackFunc);
+ Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc);
if (buildFileResult.isErr())
return Result<string>::Err(buildFileResult.getErrMsg());
@@ -165,7 +191,7 @@ namespace sibs
if (buildResult.isErr())
return Result<string>::Err(buildResult.getErrMsg());
- return Result<string>::Ok(staticLibPath);
+ return Result<string>::Ok(libPath);
}
}
diff --git a/src/PkgConfig.cpp b/src/PkgConfig.cpp
index 5f85549..620b1a7 100644
--- a/src/PkgConfig.cpp
+++ b/src/PkgConfig.cpp
@@ -25,9 +25,7 @@ namespace sibs
command += "'";
Result<ExecResult> execResult = exec(command.c_str());
if(execResult.isErr())
- {
return Result<bool>::Err(execResult.getErrMsg());
- }
if(execResult.unwrap().exitCode == 1)
{
@@ -63,9 +61,7 @@ namespace sibs
command += "'";
Result<ExecResult> execResult = exec(command.c_str());
if(execResult.isErr())
- {
return Result<bool>::Err(execResult.getErrMsg());
- }
if(execResult.unwrap().exitCode == 1)
{