aboutsummaryrefslogtreecommitdiff
path: root/src/GlobalLib.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-01-02 17:38:18 +0100
committerdec05eba <dec05eba@protonmail.com>2018-01-02 20:10:53 +0100
commit87a65f6913429b26e63fdee17cb8cfe93990db35 (patch)
treec2cfac67fc09f9c364869a107a140c34c5b73fd8 /src/GlobalLib.cpp
parente8afe1630280335e5c7f4938f7c265b8798049d1 (diff)
Add support for cmake
Not working fully yet, will investigate why
Diffstat (limited to 'src/GlobalLib.cpp')
-rw-r--r--src/GlobalLib.cpp159
1 files changed, 85 insertions, 74 deletions
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index 69c4ebb..3334655 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -4,6 +4,7 @@
#include "../include/Conf.hpp"
#include "../include/curl.hpp"
#include "../include/Archive.hpp"
+#include "../include/CmakeModule.hpp"
using namespace std;
@@ -147,43 +148,7 @@ namespace sibs
errMsg += ")";
return Result<bool>::Err(errMsg);
}
-
- backend::Ninja ninja;
- // TODO: Use same source file finder as in main.cpp
- FileWalkCallbackFunc collectSourceFiles = [&ninja, &sibsConfig, &collectSourceFiles](tinydir_file *file)
- {
- FileString pathNative = file->path;
-#if OS_FAMILY == OS_FAMILY_WINDOWS
- replaceChar(pathNative, L'/', L'\\');
-#endif
- if(file->is_reg)
- {
- if (isSourceFile(file))
- {
- string fileNameNative = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size() + 1);
- ninja.addSourceFile(fileNameNative.c_str());
- }
- else
- {
- //printf("Ignoring non-source file: %s\n", file->path + projectPath.size());
- }
- }
- else
- {
- // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests...
- // OR I believe there is no reason to run tests in dependencies. The main projects tests should cover that?
- // But you might want to know exactly which dependency is causing issue and which part of it...
- if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(pathNative.c_str(), sibsConfig.getTestPath()))
- {
- string filePathUtf8 = toUtf8(pathNative.c_str());
- ninja.addTestSourceDir(filePathUtf8.c_str());
- }
- else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs()))
- walkDir(file->path, collectSourceFiles);
- }
- };
- walkDir(packageDir.c_str(), collectSourceFiles);
-
+
FileString buildPath = packageDir + TINYDIR_STRING("/sibs-build/");
switch (sibsConfig.getOptimizationLevel())
{
@@ -214,60 +179,106 @@ namespace sibs
break;
}
}
-
- if (!ninja.getSourceFiles().empty())
+
+ if(sibsConfig.shouldUseCmake())
+ {
+ CmakeModule cmakeModule;
+ Result<bool> cmakeCompileResult = cmakeModule.compile(sibsConfig, buildPath, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
+ if(!cmakeCompileResult)
+ return cmakeCompileResult;
+ }
+ else
{
- string libPath = toUtf8(buildPath);
- switch (sibsConfig.getCompiler())
+ backend::Ninja ninja;
+ // TODO: Use same source file finder as in main.cpp
+ FileWalkCallbackFunc collectSourceFiles = [&ninja, &sibsConfig, &collectSourceFiles](tinydir_file *file)
{
- case Compiler::GCC:
+ FileString pathNative = file->path;
+ #if OS_FAMILY == OS_FAMILY_WINDOWS
+ replaceChar(pathNative, L'/', L'\\');
+ #endif
+ if(file->is_reg)
{
- libPath += "/lib";
- libPath += name;
- if (sibsConfig.getPackageType() == PackageType::STATIC)
+ if (isSourceFile(file))
{
- libPath += ".a";
- string libPathCmd = "'";
- libPathCmd += libPath;
- libPathCmd += "'";
- staticLinkerFlagCallbackFunc(libPathCmd);
+ string fileNameNative = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size() + 1);
+ ninja.addSourceFile(fileNameNative.c_str());
}
else
{
- libPath += ".so";
- string libPathCmd = "'";
- libPathCmd += libPath;
- libPathCmd += "'";
- dynamicLinkerFlagCallbackFunc(libPathCmd);
+ //printf("Ignoring non-source file: %s\n", file->path + projectPath.size());
}
- break;
}
- case Compiler::MSVC:
+ else
{
- libPath += "/";
- libPath += name;
- if (sibsConfig.getPackageType() == PackageType::STATIC)
+ // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests...
+ // OR I believe there is no reason to run tests in dependencies. The main projects tests should cover that?
+ // But you might want to know exactly which dependency is causing issue and which part of it...
+ if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(pathNative.c_str(), sibsConfig.getTestPath()))
{
- libPath += ".lib";
- string libPathCmd = "\"";
- libPathCmd += libPath;
- libPathCmd += "\"";
- staticLinkerFlagCallbackFunc(libPathCmd);
+ string filePathUtf8 = toUtf8(pathNative.c_str());
+ ninja.addTestSourceDir(filePathUtf8.c_str());
}
- else
+ else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs()))
+ walkDir(file->path, collectSourceFiles);
+ }
+ };
+ walkDir(packageDir.c_str(), collectSourceFiles);
+
+ if (!ninja.getSourceFiles().empty())
+ {
+ string libPath = toUtf8(buildPath);
+ switch (sibsConfig.getCompiler())
+ {
+ case Compiler::GCC:
{
- libPath += ".lib";
- string libPathCmd = "\"";
- libPathCmd += libPath;
- libPathCmd += "\"";
- dynamicLinkerFlagCallbackFunc(libPathCmd);
+ libPath += "/lib";
+ libPath += name;
+ if (sibsConfig.getPackageType() == PackageType::STATIC)
+ {
+ libPath += ".a";
+ string libPathCmd = "'";
+ libPathCmd += libPath;
+ libPathCmd += "'";
+ staticLinkerFlagCallbackFunc(libPathCmd);
+ }
+ else
+ {
+ libPath += ".so";
+ string libPathCmd = "'";
+ libPathCmd += libPath;
+ libPathCmd += "'";
+ dynamicLinkerFlagCallbackFunc(libPathCmd);
+ }
+ break;
+ }
+ case Compiler::MSVC:
+ {
+ libPath += "/";
+ libPath += name;
+ if (sibsConfig.getPackageType() == PackageType::STATIC)
+ {
+ libPath += ".lib";
+ string libPathCmd = "\"";
+ libPathCmd += libPath;
+ libPathCmd += "\"";
+ staticLinkerFlagCallbackFunc(libPathCmd);
+ }
+ else
+ {
+ libPath += ".lib";
+ string libPathCmd = "\"";
+ libPathCmd += libPath;
+ libPathCmd += "\"";
+ dynamicLinkerFlagCallbackFunc(libPathCmd);
+ }
+ break;
}
- break;
}
}
- }
- return ninja.build(sibsConfig, buildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
+ return ninja.build(sibsConfig, buildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
+ }
}
Result<bool> GlobalLib::downloadDependency(const Dependency &dependency)