aboutsummaryrefslogtreecommitdiff
path: root/src/GlobalLib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GlobalLib.cpp')
-rw-r--r--src/GlobalLib.cpp109
1 files changed, 2 insertions, 107 deletions
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index eee37dd..8618cfd 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -1,5 +1,6 @@
#include "../include/GlobalLib.hpp"
#include "../include/FileUtil.hpp"
+#include "../backend/BackendUtils.hpp"
#include "../backend/ninja/Ninja.hpp"
#include "../include/Conf.hpp"
#include "../include/curl.hpp"
@@ -46,26 +47,6 @@ namespace sibs
}
}
}
-
- const _tinydir_char_t *sourceFileExtensions[] = { TINYDIR_STRING("c"),TINYDIR_STRING("cc"), TINYDIR_STRING("cpp"), TINYDIR_STRING("cxx") };
- bool isSourceFile(tinydir_file *file)
- {
- if(!file->is_reg)
- return false;
-
- for(const _tinydir_char_t *sourceFileExtension : sourceFileExtensions)
- {
- if(_tinydir_strcmp(sourceFileExtension, file->extension) == 0)
- return true;
- }
-
- return false;
- }
-
- bool isPathSubPathOf(const _tinydir_char_t *path, const FileString &subPathOf)
- {
- return _tinydir_strncmp(path, subPathOf.c_str(), subPathOf.size()) == 0;
- }
Result<bool> GlobalLib::getLibs(const std::vector<PackageListDependency*> &libs, const SibsConfig &parentConfig, const FileString &globalLibRootDir, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
{
@@ -284,93 +265,7 @@ namespace sibs
else
{
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);
-
- if (!ninja.getSourceFiles().empty())
- {
- string libPath = toUtf8(buildPath);
- switch (sibsConfig.getCompiler())
- {
- case Compiler::GCC:
- {
- libPath += "/lib";
- libPath += dependencyName;
- 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 += dependencyName;
- 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;
- }
- }
- }
-
+ backend::BackendUtils::collectSourceFiles(packageDir.c_str(), &ninja, sibsConfig);
return ninja.build(sibsConfig, buildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
}
}