From f9666347840e519f6248c71688b57227bca4f454 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 29 Mar 2020 01:37:10 +0100 Subject: Add 'lib' config, for including external libraries without pkg-config --- README.md | 5 ++++- include/Conf.hpp | 6 ++++++ src/Conf.cpp | 15 +++++++++++++++ src/GlobalLib.cpp | 8 ++++++++ src/main.cpp | 8 ++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 700f16b..66cb9d2 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,8 @@ BOOST_COMPILE_STATIC = "1" BOOST_COMPILE_DYNAMIC = "1" [config] -include_dirs = ["include"] +include_dirs = ["include", "/opt/cuda/targets/x86_64-linux/include"] +libs = ["/usr/lib/libcuda.so"] ignore_dirs = ["examples"] expose_include_dirs = ["include"] error_on_warning = "true" @@ -190,6 +191,8 @@ Works like \[define], but these definitions are only used when building dynamic ### include_dirs Optional. A list of directories which should be specified as global include directories when compiling. This means that instead of using relative paths to header files, you can include the directory with headers and then you only have to specify the header name when using #include.\ You can use the `$out` variable to specify the build directory. +### libs +Optional. A list of additional external libraries which should be linked with the program. ### ignore_dirs Optional. A list of directories to ignore. This means that if the ignored directory contains source files, then they wont be included in the build. ### expose_include_dirs diff --git a/include/Conf.hpp b/include/Conf.hpp index 892b7b6..a854552 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -288,6 +288,11 @@ namespace sibs return exposeIncludeDirs; } + virtual const std::vector& getLibs() const + { + return libs; + } + virtual const std::vector& getPlatforms() const { return platforms; @@ -423,6 +428,7 @@ namespace sibs std::vector includeDirs; std::vector exposeIncludeDirs; std::vector ignoreDirs; + std::vector libs; protected: virtual void processObject(StringView name) override; virtual void processField(StringView name, const ConfigValue &value) override; diff --git a/src/Conf.cpp b/src/Conf.cpp index 27071a3..dc9c406 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -1081,6 +1081,18 @@ namespace sibs else throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".error_on_warning to be a single value, was a list"); } + else if(name.equals("libs")) + { + if(value.isList()) + { + for(const StringView &lib : value.asList()) + { + libs.emplace_back(string(lib.data, lib.size)); + } + } + else + throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".libs to be a list, was a single value"); + } else failInvalidFieldUnderObject(name); } @@ -1321,6 +1333,9 @@ namespace sibs string SibsConfig::parsePlatformConfigStatic(const StringView &fieldName, const ConfigValue &fieldValue) { // TODO: Verify the library is actually a static library + // TODO: Remove this and use "libs" config instead and support wildcard, then "libs" + // can be used to specify directories as well.. or just do if the path is a directory then + // use the files in the directory (recursively) if (fieldName.equals("lib")) { if (fieldValue.isSingle()) diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index 1a795bf..586ec2d 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -249,6 +249,14 @@ namespace sibs break; } } + + for(const std::string &lib : sibsConfig.getLibs()) + { + string staticLibCmd = "\""; + staticLibCmd += lib; + staticLibCmd += "\""; + staticLinkerFlagCallbackFunc(staticLibCmd); + } if(sibsConfig.shouldUseCmake()) { diff --git a/src/main.cpp b/src/main.cpp index af43892..47da4bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -421,6 +421,14 @@ static int buildProject(const FileString &projectPath, const FileString &project } } + for(const std::string &lib : sibsConfig.getLibs()) + { + string staticLibCmd = "\""; + staticLibCmd += lib; + staticLibCmd += "\""; + ninja.addDependency(staticLibCmd); + } + if(sibsConfig.shouldBuildTests() && sibsConfig.getTestPath().empty() && !sibsConfig.zigTestAllFiles && sibsConfig.zigTestFiles.empty()) { printf("Project is missing tests subdirectory. No tests to build\n"); -- cgit v1.2.3