mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fa510bb00e | |||
| 31bf4e3e96 |
+8
-3
@@ -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.
|
||||
- Support testing.
|
||||
+2
-2
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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" }
|
||||
|
||||
+4
-1
@@ -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;
|
||||
|
||||
@@ -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<std::string, toml::basic_value<toml::discard_comments, std::unordered_map,
|
||||
std::vector>>;
|
||||
const auto &sets = toml::find<set_map>(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<std::string, toml::basic_value<toml::discard_comments, std::unordered_map,
|
||||
@@ -152,6 +191,11 @@ CMake::CMake(const std::string &path, bool build) {
|
||||
b.alias = toml::find(bin, "alias").as_string();
|
||||
}
|
||||
|
||||
if (bin.contains("properties")) {
|
||||
using prop_map = std::map<std::string, std::string>;
|
||||
b.properties = toml::find<prop_map>(bin, "properties");
|
||||
}
|
||||
|
||||
binaries.push_back(b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,19 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
namespace cmkr::cmake {
|
||||
|
||||
|
||||
struct Setting {
|
||||
std::string name;
|
||||
std::string comment;
|
||||
std::variant<bool, std::string> val;
|
||||
bool cache = false;
|
||||
bool force = false;
|
||||
};
|
||||
|
||||
struct Option {
|
||||
std::string name;
|
||||
std::string comment;
|
||||
@@ -28,6 +38,7 @@ struct Bin {
|
||||
std::vector<std::string> defines;
|
||||
std::vector<std::string> link_libs;
|
||||
std::string alias;
|
||||
std::map<std::string, std::string> 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<std::string> subdirs;
|
||||
std::vector<std::string> cppflags;
|
||||
std::vector<std::string> cflags;
|
||||
@@ -56,6 +68,7 @@ struct CMake {
|
||||
std::vector<std::string> build_args;
|
||||
std::string proj_name;
|
||||
std::string proj_version;
|
||||
std::vector<Setting> settings;
|
||||
std::vector<Option> options;
|
||||
std::vector<Package> packages;
|
||||
std::map<std::string, std::map<std::string, std::string>> contents;
|
||||
|
||||
+33
-5
@@ -149,7 +149,10 @@ int generate_cmake(const char *path) {
|
||||
}
|
||||
|
||||
if (!cmake.proj_name.empty() && !cmake.proj_version.empty()) {
|
||||
ss << "project(" << cmake.proj_name << " VERSION " << cmake.proj_version << ")\n\n";
|
||||
ss << "set(" << cmake.proj_name << "_PROJECT_VERSION " << cmake.proj_version << ")\n"
|
||||
<< "project(" << cmake.proj_name << " VERSION "
|
||||
<< "${" << cmake.proj_name << "_PROJECT_VERSION}"
|
||||
<< ")\n\n";
|
||||
}
|
||||
|
||||
if (!cmake.packages.empty()) {
|
||||
@@ -182,9 +185,9 @@ int generate_cmake(const char *path) {
|
||||
} else if (first_arg == "tag") {
|
||||
first_arg = "GIT_TAG";
|
||||
} else if (first_arg == "svn") {
|
||||
first_arg == "SVN_REPOSITORY";
|
||||
first_arg = "SVN_REPOSITORY";
|
||||
} else if (first_arg == "rev") {
|
||||
first_arg == "SVN_REVISION";
|
||||
first_arg = "SVN_REVISION";
|
||||
} else if (first_arg == "url") {
|
||||
first_arg = "URL";
|
||||
} else if (first_arg == "hash") {
|
||||
@@ -202,11 +205,28 @@ int generate_cmake(const char *path) {
|
||||
if (!cmake.options.empty()) {
|
||||
for (const auto &opt : cmake.options) {
|
||||
ss << "option(" << opt.name << " \"" << opt.comment << "\" "
|
||||
<< (opt.val ? "ON" : "OFF") << ")\n";
|
||||
<< (opt.val ? "ON" : "OFF") << ")\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
ss << "\n";
|
||||
if (!cmake.settings.empty()) {
|
||||
for (const auto &set : cmake.settings) {
|
||||
std::string set_val;
|
||||
if (set.val.index() == 1) {
|
||||
set_val = std::get<std::string>(set.val);
|
||||
} else {
|
||||
set_val = std::get<bool>(set.val) ? "ON" : "OFF";
|
||||
}
|
||||
ss << "set(" << set.name << " " << set_val;;
|
||||
if (set.cache) {
|
||||
std::string typ;
|
||||
if (set.val.index() == 1) typ = "STRING"; else typ = "BOOL";
|
||||
ss << " CACHE " << typ << " \"" << set.comment << "\"";
|
||||
if (set.force) ss << " FORCE";
|
||||
}
|
||||
ss << ")\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!cmake.binaries.empty()) {
|
||||
for (const auto &bin : cmake.binaries) {
|
||||
@@ -282,6 +302,14 @@ int generate_cmake(const char *path) {
|
||||
}
|
||||
ss << ")\n\n";
|
||||
}
|
||||
|
||||
if (!bin.properties.empty()) {
|
||||
ss << "set_target_properties(" << bin.name << " PROPERTIES\n";
|
||||
for (const auto &prop : bin.properties) {
|
||||
ss << "\t" << prop.first << " " << prop.second << "\n";
|
||||
}
|
||||
ss << "\t)\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace cmkr::help {
|
||||
|
||||
const char *version() noexcept { return "cmkr version 0.1.0"; }
|
||||
const char *version() noexcept { return "cmkr version 0.1.2"; }
|
||||
|
||||
const char *message() noexcept {
|
||||
return R"lit(
|
||||
|
||||
Reference in New Issue
Block a user