aboutsummaryrefslogtreecommitdiff
path: root/backend/BackendUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-03-21 14:56:51 +0100
committerdec05eba <dec05eba@protonmail.com>2018-03-21 14:58:31 +0100
commit23117906c571714b0b55caf35cf9f876d1f9fa2e (patch)
tree21574306de1efb6eafd2af48f5188bf9e3550dd8 /backend/BackendUtils.cpp
parentb44ff4ec7d2c2458aab04b5daf79134e5d284f6e (diff)
Add sub projects (should be used with git submodules)
Fix issue where static lib dependencies are not built correctly because their dynamic lib dependencies are not propagated to dependant project
Diffstat (limited to 'backend/BackendUtils.cpp')
-rw-r--r--backend/BackendUtils.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/backend/BackendUtils.cpp b/backend/BackendUtils.cpp
new file mode 100644
index 0000000..68794f5
--- /dev/null
+++ b/backend/BackendUtils.cpp
@@ -0,0 +1,85 @@
+#include "BackendUtils.hpp"
+#include "../include/FileUtil.hpp"
+#include "ninja/Ninja.hpp"
+
+using namespace std;
+using namespace sibs;
+
+namespace backend
+{
+ bool isPathSubPathOf(const FileString &path, const FileString &subPathOf)
+ {
+ return _tinydir_strncmp(path.c_str(), subPathOf.c_str(), subPathOf.size()) == 0;
+ }
+
+ const _tinydir_char_t *sourceFileExtensions[] = { TINYDIR_STRING("c"), TINYDIR_STRING("cc"), TINYDIR_STRING("cpp"), TINYDIR_STRING("cxx"), TINYDIR_STRING("c++") };
+ bool BackendUtils::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;
+ }
+
+ void BackendUtils::collectSourceFiles(const _tinydir_char_t *projectPath, Ninja *ninjaProject, const SibsConfig &sibsConfig)
+ {
+ walkDir(projectPath, [ninjaProject, &sibsConfig](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 filePathUtf8 = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size());
+ ninjaProject->addSourceFile(filePathUtf8.c_str());
+ }
+ else
+ {
+ //printf("Ignoring non-source file: %s\n", file->path + projectPath.size());
+ }
+ }
+ else
+ {
+ if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(pathNative.c_str(), sibsConfig.getTestPath()))
+ {
+ string filePathUtf8 = toUtf8(pathNative.c_str());
+ ninjaProject->addTestSourceDir(filePathUtf8.c_str());
+ }
+ else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs()))
+ {
+ FileString projectConfPath = file->path;
+ #if OS_FAMILY == OS_FAMILY_WINDOWS
+ projectConfPath += L'\\';
+ #else
+ projectConfPath += '/';
+ #endif
+ projectConfPath += TINYDIR_STRING("project.conf");
+
+ auto projectConfFileType = getFileType(projectConfPath.c_str());
+ if(projectConfFileType == FileType::REGULAR)
+ {
+ backend::Ninja *subProject = new backend::Ninja();
+
+ SibsConfig *subProjectConfig = new SibsConfig(sibsConfig.getCompiler(), file->path, sibsConfig.getOptimizationLevel(), false);
+ FileString subProjectBuildPath;
+ readSibsConfig(file->path, projectConfPath, *subProjectConfig, subProjectBuildPath);
+
+ collectSourceFiles(file->path, subProject, *subProjectConfig);
+ ninjaProject->addSubProject(subProject, subProjectConfig, move(subProjectBuildPath));
+ }
+ else
+ collectSourceFiles(file->path, ninjaProject, sibsConfig);
+ }
+ }
+ });
+ }
+}