aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-02-16 02:06:56 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:58 +0200
commit6d3c3132bbc0421c42e587b869984fd39f0b35a2 (patch)
treed503e2163f82293713bbe0773b79b1b3342c130b /src
parent04f7cf535992f05ea56c701f25a6adad564796ae (diff)
Fix cmake build library dependency order
Diffstat (limited to 'src')
-rw-r--r--src/CmakeModule.cpp8
-rw-r--r--src/FileUtil.cpp31
2 files changed, 35 insertions, 4 deletions
diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp
index 9e399ac..8c97b6e 100644
--- a/src/CmakeModule.cpp
+++ b/src/CmakeModule.cpp
@@ -276,13 +276,13 @@ namespace sibs
string buildPathUtf8 = toUtf8(buildPath);
nprintf("Searching for libraries generate by cmake in build path: %s\n", buildPathUtf8.c_str());
- walkDirFilesRecursive(buildPath.c_str(),
- [&config, &parentProjStaticLinkerFlagCallbackFunc, &parentProjDynamicLinkerFlagCallbackFunc, dynamicLibExtension](tinydir_file *file)
+ walkDirFilesRecursiveSortTimestamp(buildPath.c_str(),
+ [&config, &parentProjStaticLinkerFlagCallbackFunc, &parentProjDynamicLinkerFlagCallbackFunc, dynamicLibExtension](const FileWithTimestamp &filedata)
{
bool isStatic = config.getPackageType() == PackageType::STATIC;
- if((!isStatic && _tinydir_strcmp(file->extension, dynamicLibExtension) == 0) || (isStatic && _tinydir_strcmp(file->extension, CONFIG_STATIC_LIB_FILE_EXTENSION) == 0))
+ if((!isStatic && _tinydir_strcmp(filedata.extension.c_str(), dynamicLibExtension) == 0) || (isStatic && _tinydir_strcmp(filedata.extension.c_str(), CONFIG_STATIC_LIB_FILE_EXTENSION) == 0))
{
- string libFileUtf8 = toUtf8(file->path);
+ string libFileUtf8 = toUtf8(filedata.filepath);
nprintf("Library generated by cmake: %s\n", libFileUtf8.c_str());
switch(config.getPackageType())
diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp
index 2a0b290..b78e257 100644
--- a/src/FileUtil.cpp
+++ b/src/FileUtil.cpp
@@ -1,5 +1,7 @@
#include "../include/FileUtil.hpp"
#include <cstdio>
+#include <vector>
+#include <algorithm>
#if OS_FAMILY == OS_FAMILY_POSIX
#include <unistd.h>
@@ -249,6 +251,35 @@ namespace sibs
return true;
}
+ bool walkDirFilesRecursiveSortTimestamp(const _tinydir_char_t *directory, SortedFileWalkCallbackFunc callbackFunc)
+ {
+ std::vector<FileWithTimestamp> files;
+ walkDirFilesRecursive(directory, [&files](tinydir_file *file) {
+ FileWithTimestamp filedata;
+ filedata.filepath = file->path;
+ filedata.extension = file->extension;
+ filedata.last_modified = file->_s.st_mtim;
+ files.push_back(std::move(filedata));
+ return true;
+ });
+
+ std::sort(files.begin(), files.end(), [](const FileWithTimestamp &filedata_a, const FileWithTimestamp &filedata_b) {
+ if(filedata_a.last_modified.tv_sec < filedata_b.last_modified.tv_sec)
+ return true;
+ else if(filedata_a.last_modified.tv_sec == filedata_b.last_modified.tv_sec && filedata_a.last_modified.tv_nsec <= filedata_b.last_modified.tv_nsec)
+ return true;
+ else
+ return false;
+ });
+
+ for(const FileWithTimestamp &filedata : files) {
+ if(!callbackFunc(filedata))
+ return false;
+ }
+
+ return true;
+ }
+
Result<StringView> getFileContent(const _tinydir_char_t *filepath)
{
#if OS_FAMILY == OS_FAMILY_POSIX