diff --git a/CHANGELOG.md b/CHANGELOG.md index e3c8a18..1e81f6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,16 @@ # CHANGELOG +## 0.1.2 - 2020-11-20 +- Add support for target properties. +- Add installs. +- Require cmake >= 3.15. +- Support settings and caching settings. +- Support config when running cmkr build. + ## 0.1.1 - 2020-11-19 - Add support for globbing. - Add support for find_package components. - Add options. -- Add installs. - Support aliases. - Support interface libs (header-only libs). -- Support testing. -- Require cmake >= 3.15. \ No newline at end of file +- Support testing. \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 26a2cf9..06b626e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,8 @@ cmake_minimum_required(VERSION 3.15) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -project(cmkr VERSION 0.1.1) +set(cmkr_PROJECT_VERSION 0.1.2) +project(cmkr VERSION ${cmkr_PROJECT_VERSION}) include(FetchContent) @@ -15,7 +16,6 @@ FetchContent_Declare( FetchContent_MakeAvailable(toml11) - set(CMKRLIB_SOURCES "src/cmake.cpp" "src/gen.cpp" diff --git a/README.md b/README.md index 3bc483e..a3453f1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ cmkr requires a C++17 compiler, cmake >= 3.15. git clone https://github.com/moalyousef/cmkr cd cmkr cmake -Bbin -cmake --build bin +cmake --build bin --parallel ``` ## Usage @@ -35,7 +35,7 @@ minimum = "3.15" [project] name = "cmkr" -version = "0.1.0" +version = "0.1.2" [fetch-content] toml11 = { git = "https://github.com/ToruNiina/toml11" } @@ -68,8 +68,15 @@ bin-dir = "bin" # optional cpp-flags = [] # optional c-flags = [] # optional link-flags = [] # optional -generator = "Ninja" # optional -arguments = ["CMAKE_TOOLCHAIN_FILE=/path/to/toolchain"] # optional +generator = "Ninja" # optional, only valid when run using: cmkr build +config = "Release" # optional, only valid when run using: cmkr build +arguments = ["CMAKE_TOOLCHAIN_FILE=/path/to/toolchain"] # optional, valid when run using: cmkr build + +[settings] # optional +CMAKE_BUILD_TYPE = "Release" +TOML_BUILD_TESTS = false # optional +TOML_BUILD_DOCS = { value = false, comment = "builds dependency docs", cache = true, force = true } # optional +OLD_VERSION = "0.1.1" # optional [project] # required per project name = "app" # required @@ -95,6 +102,7 @@ alias = "" # optional features = [] # optional defines = [] # optional link-libs = [] # optional +properties = { PROPERTY1 = "property1", ... } # optional [[test]] # optional, can define several name = "test1" # required diff --git a/cmake.toml b/cmake.toml index f909195..d589dc0 100644 --- a/cmake.toml +++ b/cmake.toml @@ -3,7 +3,7 @@ minimum = "3.15" [project] name = "cmkr" -version = "0.1.1" +version = "0.1.2" [fetch-content] toml11 = { git = "https://github.com/ToruNiina/toml11" } diff --git a/src/build.cpp b/src/build.cpp index 11619b7..eedd407 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -32,12 +32,15 @@ int run(int argc, char **argv) { if (!cmake.generator.empty()) { ss << "-G \"" << cmake.generator << "\" "; } + if (!cmake.config.empty()) { + ss << "-DCMAKE_BUILD_TYPE=" << cmake.config << " "; + } if (!cmake.gen_args.empty()) { for (const auto &arg : cmake.gen_args) { ss << "-D" << arg << " "; } } - ss << "&& cmake --build " << cmake.bin_dir; + ss << "&& cmake --build " << cmake.bin_dir << " --parallel"; if (argc > 2) { for (const auto &arg : cmake.build_args) { ss << " " << arg; diff --git a/src/cmake.cpp b/src/cmake.cpp index fc51f45..990db9d 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -36,6 +36,10 @@ CMake::CMake(const std::string &path, bool build) { generator = toml::find(cmake, "generator").as_string(); } + if (cmake.contains("config")) { + config = toml::find(cmake, "config").as_string(); + } + if (cmake.contains("arguments")) { gen_args = detail::to_string_vec(toml::find(cmake, "arguments").as_array()); } @@ -68,6 +72,41 @@ CMake::CMake(const std::string &path, bool build) { proj_version = toml::find(project, "version").as_string(); } + if (toml.contains("settings")) { + using set_map = + std::map>; + const auto &sets = toml::find(toml, "settings"); + for (const auto set : sets) { + Setting s; + s.name = set.first; + if (set.second.is_boolean()) { + s.val = set.second.as_boolean(); + } else if (set.second.is_string()) { + s.val = set.second.as_string(); + } else { + if (set.second.contains("comment")) { + s.comment = toml::find(set.second, "comment").as_string(); + } + if (set.second.contains("value")) { + auto v = toml::find(set.second, "value"); + if (v.is_boolean()) { + s.val = v.as_boolean(); + } else { + s.val = v.as_string(); + } + } + if (set.second.contains("cache")) { + s.cache = toml::find(set.second, "cache").as_boolean(); + } + if (set.second.contains("force")) { + s.force = toml::find(set.second, "force").as_boolean(); + } + } + settings.push_back(s); + } + } + if (toml.contains("options")) { using opts_map = std::map; + b.properties = toml::find(bin, "properties"); + } + binaries.push_back(b); } } diff --git a/src/cmake.hpp b/src/cmake.hpp index e9939bf..ae79680 100644 --- a/src/cmake.hpp +++ b/src/cmake.hpp @@ -3,9 +3,19 @@ #include #include #include +#include namespace cmkr::cmake { + +struct Setting { + std::string name; + std::string comment; + std::variant val; + bool cache = false; + bool force = false; +}; + struct Option { std::string name; std::string comment; @@ -28,6 +38,7 @@ struct Bin { std::vector defines; std::vector link_libs; std::string alias; + std::map properties; }; struct Test { @@ -48,6 +59,7 @@ struct CMake { std::string cmake_version = "3.15"; std::string bin_dir = "bin"; std::string generator; + std::string config; std::vector subdirs; std::vector cppflags; std::vector cflags; @@ -56,6 +68,7 @@ struct CMake { std::vector build_args; std::string proj_name; std::string proj_version; + std::vector settings; std::vector