From e862bb76a2f4c9c293fe2638c7fb034de2af709c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 3 Jan 2018 22:59:17 +0100 Subject: Add custom define option --- README.md | 7 ++++++- backend/ninja/Ninja.cpp | 3 --- src/Conf.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 08cd27a..cd06dc6 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,9 @@ ignore_dirs = ["examples"] catch2 = "0.1.0" xxhash = "0.1.0" +[define] +BOOST_ASIO_SEPERATE_COMPILATION = "1" + [config] expose_include_dirs = ["include"] @@ -74,11 +77,13 @@ Optional. A list of directories which should be specified as global include dire ### 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 ## dependencies -Optional. Dependencies are specified in name-value pairs where the name is the name of the dependency, which should match the dependency name under the packages name specified in its project.conf file. +Optional. A list of dependencies which are specified in name-value pairs where the name is the name of the dependency, which should match the dependency name under the packages name specified in its project.conf file. Currently, the value is the version and has to be an exact match for the package version, which is specified in the dependencies project.conf file. This will later change and you should be able to choose minimum version and range of versions. Dependencies are automatically choosen from system (linux, mac) or if no package manager exists, then it's download from github +## define +Optional. A list of definitions which are specified in name-value pairs where the name is the preprocessor to define (in c: #define name value) ## config ### expose_include_dirs Optional. A list of directories which contains (header) files which should be exposed to dependencies as directories to include globally. This means that dependencies can include (header) files from the dependency without specifying path to the dependency diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 04669f7..def62fa 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -463,9 +463,6 @@ namespace backend } #endif - if(!defines.empty()) - printf("Custom define: %s\n", defines.c_str()); - string compilerName; switch (config.getCompiler()) { diff --git a/src/Conf.cpp b/src/Conf.cpp index 0bbbf7b..75fdd02 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -398,6 +398,24 @@ namespace sibs } } + bool isValidCIdentifier(const StringView &identifier) + { + if(identifier.size == 0) + return false; + + char c = identifier.data[0]; + if(isalpha(c) || c == '_') + { + for(int i = 1; i < identifier.size; ++i) + { + c = identifier.data[i]; + if(!isalnum(c) && c != '_') + return false; + } + } + return true; + } + bool directoryToIgnore(const FileString &dir, const vector &ignoreDirList) { string dirUtf8 = toUtf8(dir); @@ -689,6 +707,22 @@ namespace sibs else throw ParserException("Expected field under dependencies to be a single value, was a list"); } + else if(currentObject.equals("define")) + { + if(value.isSingle()) + { + if(!isValidCIdentifier(name)) + { + string errMsg = "Definition \""; + errMsg.append(name.data, name.size); + errMsg += "\" is not in a valid format. The first character have to match [a-zA-Z_] and the next characters have to match [a-zA-Z0-9_]"; + throw ParserException(errMsg); + } + defines[string(name.data, name.size)] = string(value.asSingle().data, value.asSingle().size); + } + else + throw ParserException("Expected field under define to be a single value, was a list"); + } else if(currentObject.equals("cmake")) { parseCmake(name, value, cmakeDirGlobal, cmakeArgsGlobal); -- cgit v1.2.3