From e6219d657182db7a66e2b4c41d0e73cf03020dfa Mon Sep 17 00:00:00 2001 From: MoAlyousef Date: Mon, 14 Sep 2020 16:39:57 +0300 Subject: [PATCH] add option comments --- README.md | 5 +++-- include/cmake.hpp | 1 + include/literals.h | 2 +- src/cmake.cpp | 17 ++++++++++++++--- src/gen.cpp | 2 +- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 514c2b8..598356b 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ Currently supported fields: ```toml [cmake] # required for top-level project minimum = "3.14" # required +subdirs = [] # optional +bin-dir = "bin" # optional cpp-flags = [] # optional c-flags = [] # optional link-flags = [] # optional -subdirs = [] # optional -bin-dir = "bin" # optional generator = "Ninja" # optional arguments = ["CMAKE_TOOLCHAIN_FILE=/path/to/toolchain"] # optional @@ -76,6 +76,7 @@ toml11 = { GIT_REPOSITORY = "https://github.com/ToruNiina/toml11", GIT_TAG = "v3 [options] # optional APP_BUILD_STUFF = false # optional +APP_OTHER_STUFF = { comment = "does other stuff", value = false } # optional [[bin]] # required, can define several binaries name = "app" # required diff --git a/include/cmake.hpp b/include/cmake.hpp index c784b6a..ada7381 100644 --- a/include/cmake.hpp +++ b/include/cmake.hpp @@ -8,6 +8,7 @@ namespace cmkr::cmake { struct Option { std::string name; + std::string comment; bool val; }; diff --git a/include/literals.h b/include/literals.h index 16abf74..162779a 100644 --- a/include/literals.h +++ b/include/literals.h @@ -12,11 +12,11 @@ int %s() { const char *cmake_toml = R"lit( [cmake] minimum = "3.14" +# subdirs = [] # bin-dir = "" # cpp-flags = [] # c-flags = [] # link-flags = [] -# subdirs = [] # generator = "" # arguments = [] diff --git a/src/cmake.cpp b/src/cmake.cpp index bfbd366..b1b6ca3 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -69,12 +69,23 @@ CMake::CMake(const std::string &path, bool build) { } if (toml.contains("options")) { - using opts_map = std::map; + using opts_map = + std::map>; const auto &opts = toml::find(toml, "options"); - for (const auto opt: opts) { + for (const auto opt : opts) { Option o; o.name = opt.first; - o.val = opt.second; + if (opt.second.is_boolean()) { + o.val = opt.second.as_boolean(); + } else { + if (opt.second.contains("comment")) { + o.comment = toml::find(opt.second, "comment").as_string(); + } + if (opt.second.contains("value")) { + o.val = toml::find(opt.second, "value").as_boolean(); + } + } options.push_back(o); } } diff --git a/src/gen.cpp b/src/gen.cpp index 4cdfbbd..ad8764d 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -152,7 +152,7 @@ int generate_cmake(const char *path) { if (!cmake.options.empty()) { for (const auto &opt: cmake.options) { - ss << "option(" << opt.name << " \"" << opt.name << "\" " << (opt.val ? "ON" : "OFF") << ")\n"; + ss << "option(" << opt.name << " \"" << opt.comment << "\" " << (opt.val ? "ON" : "OFF") << ")\n"; } }