From ab712cf153e543e84a5c6484e19d22ba90bdbeff Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 31 Dec 2017 06:17:54 +0100 Subject: Add cmake building, add ignore dirs option Sometimes it's not possible to build new sibs with older sibs because of changes that break backwards compatbility. If sibs installation fails with sibs, use cmake. --- .gitignore | 5 +++-- CMakeLists.txt | 24 ++++++++++++++++++++++++ backend/ninja/Ninja.cpp | 5 +++-- cmake/install.sh | 12 ++++++++++++ include/Conf.hpp | 7 +++++++ include/FileUtil.hpp | 1 + project.conf | 1 + src/Conf.cpp | 31 +++++++++++++++++++++++++++++++ src/FileUtil.cpp | 26 +++++++++++++++++++++++--- src/GlobalLib.cpp | 5 +++-- src/main.cpp | 2 +- 11 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 CMakeLists.txt create mode 100755 cmake/install.sh diff --git a/.gitignore b/.gitignore index 29a2471..1ea6946 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -sibs-build +sibs-build/ .idea/ .kdev4/ sibs.kdev4 -build +build/ +cmake/build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c9bf973 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.0.2) +project(sibs) + +set(CMAKE_CXX_STANDARD 11) + +set(SOURCE_FILES + external/xxhash.c + backend/ninja/Ninja.cpp + src/main.cpp + src/FileUtil.cpp + src/Conf.cpp + src/PkgConfig.cpp + src/Exec.cpp + src/GlobalLib.cpp + src/curl.cpp + src/Archive.cpp) + +find_package(CURL REQUIRED) +find_package(LibArchive REQUIRED) + +add_executable(sibs ${SOURCE_FILES}) + +include_directories(${CURL_INCLUDE_DIR} ${LibArchive_INCLUDE_DIR}) +target_link_libraries(sibs ${CURL_LIBRARIES} ${LibArchive_LIBRARIES}) diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 0b46891..f83835f 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -624,7 +624,7 @@ namespace backend case Compiler::MSVC: { // TODO: Do not link all of these. Find a way to only link the ones that are needed - result += " LINK_ARGS = Ws2_32.lib Wldap32.lib Crypt32.lib Advapi32.lib Gdi32.lib User32.lib "; + result += " LINK_ARGS = Ws2_32.lib Wldap32.lib Crypt32.lib Advapi32.lib Gdi32.lib User32.lib Userenv.lib "; break; } } @@ -683,7 +683,7 @@ namespace backend result += join(objectNames, " "); result += "\n"; // TODO: Do not link all of these. Find a way to only link the ones that are needed - result += " LINK_ARGS = Ws2_32.lib Wldap32.lib Crypt32.lib Advapi32.lib Gdi32.lib User32.lib "; + result += " LINK_ARGS = Ws2_32.lib Wldap32.lib Crypt32.lib Advapi32.lib Gdi32.lib User32.lib Userenv.lib "; projectGeneratedBinary += config.getPackageName() + ".lib"; break; } @@ -781,6 +781,7 @@ namespace backend backend::Ninja ninja; if(!projectGeneratedBinary.empty()) ninja.addDependency(projectGeneratedBinary); + // TODO: Use same source file finder as in main.cpp walkDirFilesRecursive(testSourceDirNative.c_str(), [&ninja, &sibsTestConfig](tinydir_file *file) { if (isSourceFile(file)) diff --git a/cmake/install.sh b/cmake/install.sh new file mode 100755 index 0000000..384ad5d --- /dev/null +++ b/cmake/install.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -e + +scriptpath="$(dirname "$0")" +mkdir -p "$scriptpath/build/release" +cd "$scriptpath/build/release" +cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ../../../ +ninja +sudo cp sibs /usr/bin/ +echo "Copied $scriptpath/build/release/sibs to /usr/bin/sibs" +echo "Installation successful!" diff --git a/include/Conf.hpp b/include/Conf.hpp index 2cb387c..d8ce3a8 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -140,6 +140,7 @@ namespace sibs bool containsPlatform(const std::vector &platforms, Platform platform); const char* asString(Platform platform); const char* asString(OptimizationLevel optLevel); + bool directoryToIgnore(const FileString &dir, const std::vector &ignoreDirList); class SibsConfig : public ConfigCallback { @@ -209,6 +210,11 @@ namespace sibs return releaseStaticLibs; } + const std::vector& getIgnoreDirs() const + { + return ignoreDirs; + } + void setPackageType(PackageType packageType) { this->packageType = packageType; @@ -232,6 +238,7 @@ namespace sibs std::vector includeDirs; std::vector exposeIncludeDirs; std::vector platforms; + std::vector ignoreDirs; std::unordered_map defines; OptimizationLevel optimizationLevel; std::vector debugStaticLibs; diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp index f2679a0..90b9ca3 100644 --- a/include/FileUtil.hpp +++ b/include/FileUtil.hpp @@ -53,6 +53,7 @@ namespace sibs // Note: Will not delete created directories if this operation fails for some reason Result createDirectoryRecursive(const _tinydir_char_t *path); Result getRealPath(const _tinydir_char_t *path); + bool pathEquals(const std::string &path, const std::string &otherPath); } #endif //SIBS_FILEUTIL_HPP diff --git a/project.conf b/project.conf index 0222ce6..c331766 100644 --- a/project.conf +++ b/project.conf @@ -5,6 +5,7 @@ version = "0.1.2" authors = ["DEC05EBA <0xdec05eba@gmail.com>"] tests = "tests" platforms = ["linux32", "linux64", "win64"] +ignore_dirs = ["cmake"] [dependencies] libcurl = "7.57.0" diff --git a/src/Conf.cpp b/src/Conf.cpp index 4217846..032d89f 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -383,6 +383,17 @@ namespace sibs } } + bool directoryToIgnore(const FileString &dir, const vector &ignoreDirList) + { + string dirUtf8 = toUtf8(dir); + for(const string &ignoreDir : ignoreDirList) + { + if(pathEquals(dirUtf8, ignoreDir)) + return true; + } + return false; + } + bool SibsConfig::isDefined(const std::string &name) const { return defines.find(name) != defines.end(); @@ -574,6 +585,26 @@ namespace sibs else throw ParserException("Expected package.platforms to be a list, was a single value"); } + else if(name.equals("ignore_dirs")) + { + if (value.isList()) + { + string projectPathUtf8 = toUtf8(projectPath); + // TODO: Checking for duplicate declaration should be done in the config parser + if (!ignoreDirs.empty()) + throw ParserException("Found duplicate declaration of package.ignore_dirs"); + + for (const StringView &ignoreDir : value.asList()) + { + string ignoreDirFull = projectPathUtf8; + ignoreDirFull += "/"; + ignoreDirFull += string(ignoreDir.data, ignoreDir.size); + ignoreDirs.emplace_back(ignoreDirFull); + } + } + else + throw ParserException("Expected package.ignore_dirs to be a list, was a single value"); + } } else if (currentObject.equals(CONFIG_SYSTEM_PLATFORM)) { diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index db68bb4..e53aa85 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -308,8 +308,6 @@ namespace sibs } #else -#pragma comment(lib, "Userenv.lib") - Result getHomeDir() { BOOL ret; @@ -410,4 +408,26 @@ namespace sibs return Result::Ok(fullPath); } #endif -} \ No newline at end of file + + // TODO: Support better path equality check. For example if path contains several slashes in a row: /home/userName/.sibs//lib////libraryName + // then it should equal: /home/userName/.sibs/lib/libraryName + // Maybe check with OS operation if they refer to the same inode? + bool pathEquals(const std::string &path, const std::string &otherPath) + { + if(path.size() != otherPath.size()) + return false; + + size_t size = path.size(); + for(size_t i = 0; i < size; ++i) + { + char c = path[i]; + char otherC = otherPath[i]; + if(c == '\\') c = '/'; + if(otherC == '\\') otherC = '/'; + if(c != otherC) + return false; + } + + return true; + } +} diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index ac8fd59..69c4ebb 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -149,6 +149,7 @@ namespace sibs } 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; @@ -177,7 +178,7 @@ namespace sibs string filePathUtf8 = toUtf8(pathNative.c_str()); ninja.addTestSourceDir(filePathUtf8.c_str()); } - else + else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs())) walkDir(file->path, collectSourceFiles); } }; @@ -306,4 +307,4 @@ namespace sibs return Archive::extract(libArchivedFilePath.c_str(), libPath.c_str()); } -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 1c2492c..88a837f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -249,7 +249,7 @@ int buildProject(int argc, const _tinydir_char_t **argv) string filePathUtf8 = toUtf8(pathNative.c_str()); ninja.addTestSourceDir(filePathUtf8.c_str()); } - else + else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs())) walkDir(file->path, collectSourceFiles); } }; -- cgit v1.2.3