From 00121c261f7425b32b98292a919487636fc0272c Mon Sep 17 00:00:00 2001 From: MoAlyousef Date: Sun, 11 Apr 2021 04:52:44 +0300 Subject: [PATCH] 0.1.4 --- CHANGELOG.md | 5 +++++ CMakeLists.txt | 9 +++++++-- README.md | 6 ++++-- cmake.toml | 3 ++- include/literals.h | 2 +- src/cmake.cpp | 8 ++++++-- src/cmake.hpp | 1 + src/gen.cpp | 19 +++++++++++++------ 8 files changed, 39 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96eeb44..582c5f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 0.1.4 - 2021-04-11 +- Use `GIT_SHALLOW ON` by default when getting git dependencies. +- Add cmake.description field. +- Change bin.defines to bin.definitions. + ## 0.1.3 - 2020-11-27 - Support building with C++11. - @mrexodia implemented CMake integration and bootstrapping. diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d7f5ca..17108a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,14 +11,18 @@ cmake_minimum_required(VERSION 3.15) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(cmkr_PROJECT_VERSION 0.1.3) -project(cmkr VERSION ${cmkr_PROJECT_VERSION}) +project(cmkr + VERSION 0.1.4 + LANGUAGES C CXX + DESCRIPTION "CMakeLists generator from TOML" + ) include(FetchContent) FetchContent_Declare( filesystem GIT_REPOSITORY https://github.com/gulrak/filesystem + GIT_SHALLOW ON ) FetchContent_MakeAvailable(filesystem) @@ -33,6 +37,7 @@ FetchContent_MakeAvailable(mpark_variant) FetchContent_Declare( toml11 GIT_REPOSITORY https://github.com/ToruNiina/toml11 + GIT_SHALLOW ON ) FetchContent_MakeAvailable(toml11) diff --git a/README.md b/README.md index a30239f..492aa19 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ minimum = "3.15" [project] name = "cmkr" -version = "0.1.3" +version = "0.1.4" +description = "CMakeLists generator from TOML" [fetch-content] toml11 = { git = "https://github.com/ToruNiina/toml11" } @@ -65,6 +66,7 @@ Currently supported fields: ```toml [cmake] # required for top-level project minimum = "3.15" # required +description = "" # optional subdirs = [] # optional bin-dir = "bin" # optional cpp-flags = [] # optional @@ -102,7 +104,7 @@ sources = ["src/*.cpp"] # required, supports globbing include-dirs = ["include"] # optional alias = "" # optional features = [] # optional -defines = [] # optional +definitions = [] # optional link-libs = [] # optional properties = { PROPERTY1 = "property1", ... } # optional diff --git a/cmake.toml b/cmake.toml index bf63a7a..d0b6437 100644 --- a/cmake.toml +++ b/cmake.toml @@ -1,9 +1,10 @@ [cmake] minimum = "3.15" +description = "CMakeLists generator from TOML" [project] name = "cmkr" -version = "0.1.3" +version = "0.1.4" [fetch-content] toml11 = { git = "https://github.com/ToruNiina/toml11" } diff --git a/include/literals.h b/include/literals.h index 9af61d0..1ef6bae 100644 --- a/include/literals.h +++ b/include/literals.h @@ -38,7 +38,7 @@ sources = ["src/*.cpp"] include-dirs = ["include"] # alias = "" # features = [] -# defines = [] +# definitions = [] # link-libs = [] [[install]] diff --git a/src/cmake.cpp b/src/cmake.cpp index 29343ac..f84305d 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -48,6 +48,10 @@ CMake::CMake(const std::string &path, bool build) { const auto &cmake = toml::find(toml, "cmake"); cmake_version = toml::find(cmake, "minimum").as_string(); + if (cmake.contains("description")) { + desc = toml::find(cmake, "description").as_string(); + } + if (cmake.contains("cpp-flags")) { cppflags = detail::to_string_vec(toml::find(cmake, "cpp-flags").as_array()); } @@ -182,8 +186,8 @@ CMake::CMake(const std::string &path, bool build) { b.features = detail::to_string_vec(toml::find(bin, "features").as_array()); } - if (bin.contains("defines")) { - b.defines = detail::to_string_vec(toml::find(bin, "defines").as_array()); + if (bin.contains("definitions")) { + b.defines = detail::to_string_vec(toml::find(bin, "definitions").as_array()); } if (bin.contains("alias")) { diff --git a/src/cmake.hpp b/src/cmake.hpp index 215b873..12ff3a5 100644 --- a/src/cmake.hpp +++ b/src/cmake.hpp @@ -58,6 +58,7 @@ struct Install { struct CMake { std::string cmake_version = "3.15"; + std::string desc; std::string bin_dir = "bin"; std::string generator; std::string config; diff --git a/src/gen.cpp b/src/gen.cpp index 827e12f..40270c2 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -51,7 +51,7 @@ static std::vector expand_cmake_path(const fs::path &p) { temp.push_back(p.string()); } // Normalize all paths to work with CMake (it needs a / on Windows as well) - for(auto& path : temp) { + for (auto &path : temp) { std::replace(path.begin(), path.end(), '\\', '/'); } return temp; @@ -159,11 +159,13 @@ int generate_cmake(const char *path) { ss << "\n\n"; } + std::string desc = ""; + if (!cmake.desc.empty()) + desc = "\n\tLANGUAGES C CXX\n\tDESCRIPTION \"" + cmake.desc + "\""; + if (!cmake.proj_name.empty() && !cmake.proj_version.empty()) { - ss << "set(" << cmake.proj_name << "_PROJECT_VERSION " << cmake.proj_version << ")\n" - << "project(" << cmake.proj_name << " VERSION " - << "${" << cmake.proj_name << "_PROJECT_VERSION}" - << ")\n\n"; + ss << "project(" << cmake.proj_name << "\n\tVERSION " << cmake.proj_version << desc + << "\n\t)\n\n"; } if (!cmake.packages.empty()) { @@ -206,7 +208,12 @@ int generate_cmake(const char *path) { } else { // don't change arg } - ss << "\t" << first_arg << " " << arg.second << "\n"; + if (first_arg != "GIT_REPOSITORY") + ss << "\t" << first_arg << " " << arg.second << "\n"; + else + ss << "\t" << first_arg << " " << arg.second << "\n\t" + << "GIT_SHALLOW " + << "ON\n"; } ss << "\t)\n\n" << "FetchContent_MakeAvailable(" << dep.first << ")\n\n";