Skip to content

Commit fa510bb

Browse files
committed
bump 0.1.2
1 parent 31bf4e3 commit fa510bb

File tree

9 files changed

+116
-15
lines changed

9 files changed

+116
-15
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# CHANGELOG
22

3+
## 0.1.2 - 2020-11-20
4+
- Add support for target properties.
5+
- Add installs.
6+
- Require cmake >= 3.15.
7+
- Support settings and caching settings.
8+
- Support config when running cmkr build.
9+
310
## 0.1.1 - 2020-11-19
411
- Add support for globbing.
512
- Add support for find_package components.
613
- Add options.
7-
- Add installs.
814
- Support aliases.
915
- Support interface libs (header-only libs).
10-
- Support testing.
11-
- Require cmake >= 3.15.
16+
- Support testing.

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ cmake_minimum_required(VERSION 3.15)
44

55
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
66

7-
project(cmkr VERSION 0.1.1)
7+
set(cmkr_PROJECT_VERSION 0.1.2)
8+
project(cmkr VERSION ${cmkr_PROJECT_VERSION})
89

910
include(FetchContent)
1011

@@ -15,7 +16,6 @@ FetchContent_Declare(
1516

1617
FetchContent_MakeAvailable(toml11)
1718

18-
1919
set(CMKRLIB_SOURCES
2020
"src/cmake.cpp"
2121
"src/gen.cpp"

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cmkr requires a C++17 compiler, cmake >= 3.15.
99
git clone https://github.com/moalyousef/cmkr
1010
cd cmkr
1111
cmake -Bbin
12-
cmake --build bin
12+
cmake --build bin --parallel
1313
```
1414

1515
## Usage
@@ -35,7 +35,7 @@ minimum = "3.15"
3535

3636
[project]
3737
name = "cmkr"
38-
version = "0.1.0"
38+
version = "0.1.2"
3939

4040
[fetch-content]
4141
toml11 = { git = "https://github.com/ToruNiina/toml11" }
@@ -68,8 +68,15 @@ bin-dir = "bin" # optional
6868
cpp-flags = [] # optional
6969
c-flags = [] # optional
7070
link-flags = [] # optional
71-
generator = "Ninja" # optional
72-
arguments = ["CMAKE_TOOLCHAIN_FILE=/path/to/toolchain"] # optional
71+
generator = "Ninja" # optional, only valid when run using: cmkr build
72+
config = "Release" # optional, only valid when run using: cmkr build
73+
arguments = ["CMAKE_TOOLCHAIN_FILE=/path/to/toolchain"] # optional, valid when run using: cmkr build
74+
75+
[settings] # optional
76+
CMAKE_BUILD_TYPE = "Release"
77+
TOML_BUILD_TESTS = false # optional
78+
TOML_BUILD_DOCS = { value = false, comment = "builds dependency docs", cache = true, force = true } # optional
79+
OLD_VERSION = "0.1.1" # optional
7380

7481
[project] # required per project
7582
name = "app" # required
@@ -95,6 +102,7 @@ alias = "" # optional
95102
features = [] # optional
96103
defines = [] # optional
97104
link-libs = [] # optional
105+
properties = { PROPERTY1 = "property1", ... } # optional
98106

99107
[[test]] # optional, can define several
100108
name = "test1" # required

cmake.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ minimum = "3.15"
33

44
[project]
55
name = "cmkr"
6-
version = "0.1.1"
6+
version = "0.1.2"
77

88
[fetch-content]
99
toml11 = { git = "https://github.com/ToruNiina/toml11" }

src/build.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ int run(int argc, char **argv) {
3232
if (!cmake.generator.empty()) {
3333
ss << "-G \"" << cmake.generator << "\" ";
3434
}
35+
if (!cmake.config.empty()) {
36+
ss << "-DCMAKE_BUILD_TYPE=" << cmake.config << " ";
37+
}
3538
if (!cmake.gen_args.empty()) {
3639
for (const auto &arg : cmake.gen_args) {
3740
ss << "-D" << arg << " ";
3841
}
3942
}
40-
ss << "&& cmake --build " << cmake.bin_dir;
43+
ss << "&& cmake --build " << cmake.bin_dir << " --parallel";
4144
if (argc > 2) {
4245
for (const auto &arg : cmake.build_args) {
4346
ss << " " << arg;

src/cmake.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ CMake::CMake(const std::string &path, bool build) {
3636
generator = toml::find(cmake, "generator").as_string();
3737
}
3838

39+
if (cmake.contains("config")) {
40+
config = toml::find(cmake, "config").as_string();
41+
}
42+
3943
if (cmake.contains("arguments")) {
4044
gen_args = detail::to_string_vec(toml::find(cmake, "arguments").as_array());
4145
}
@@ -68,6 +72,41 @@ CMake::CMake(const std::string &path, bool build) {
6872
proj_version = toml::find(project, "version").as_string();
6973
}
7074

75+
if (toml.contains("settings")) {
76+
using set_map =
77+
std::map<std::string, toml::basic_value<toml::discard_comments, std::unordered_map,
78+
std::vector>>;
79+
const auto &sets = toml::find<set_map>(toml, "settings");
80+
for (const auto set : sets) {
81+
Setting s;
82+
s.name = set.first;
83+
if (set.second.is_boolean()) {
84+
s.val = set.second.as_boolean();
85+
} else if (set.second.is_string()) {
86+
s.val = set.second.as_string();
87+
} else {
88+
if (set.second.contains("comment")) {
89+
s.comment = toml::find(set.second, "comment").as_string();
90+
}
91+
if (set.second.contains("value")) {
92+
auto v = toml::find(set.second, "value");
93+
if (v.is_boolean()) {
94+
s.val = v.as_boolean();
95+
} else {
96+
s.val = v.as_string();
97+
}
98+
}
99+
if (set.second.contains("cache")) {
100+
s.cache = toml::find(set.second, "cache").as_boolean();
101+
}
102+
if (set.second.contains("force")) {
103+
s.force = toml::find(set.second, "force").as_boolean();
104+
}
105+
}
106+
settings.push_back(s);
107+
}
108+
}
109+
71110
if (toml.contains("options")) {
72111
using opts_map =
73112
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) {
152191
b.alias = toml::find(bin, "alias").as_string();
153192
}
154193

194+
if (bin.contains("properties")) {
195+
using prop_map = std::map<std::string, std::string>;
196+
b.properties = toml::find<prop_map>(bin, "properties");
197+
}
198+
155199
binaries.push_back(b);
156200
}
157201
}

src/cmake.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
#include <map>
44
#include <string>
55
#include <vector>
6+
#include <variant>
67

78
namespace cmkr::cmake {
89

10+
11+
struct Setting {
12+
std::string name;
13+
std::string comment;
14+
std::variant<bool, std::string> val;
15+
bool cache = false;
16+
bool force = false;
17+
};
18+
919
struct Option {
1020
std::string name;
1121
std::string comment;
@@ -28,6 +38,7 @@ struct Bin {
2838
std::vector<std::string> defines;
2939
std::vector<std::string> link_libs;
3040
std::string alias;
41+
std::map<std::string, std::string> properties;
3142
};
3243

3344
struct Test {
@@ -48,6 +59,7 @@ struct CMake {
4859
std::string cmake_version = "3.15";
4960
std::string bin_dir = "bin";
5061
std::string generator;
62+
std::string config;
5163
std::vector<std::string> subdirs;
5264
std::vector<std::string> cppflags;
5365
std::vector<std::string> cflags;
@@ -56,6 +68,7 @@ struct CMake {
5668
std::vector<std::string> build_args;
5769
std::string proj_name;
5870
std::string proj_version;
71+
std::vector<Setting> settings;
5972
std::vector<Option> options;
6073
std::vector<Package> packages;
6174
std::map<std::string, std::map<std::string, std::string>> contents;

src/gen.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ int generate_cmake(const char *path) {
149149
}
150150

151151
if (!cmake.proj_name.empty() && !cmake.proj_version.empty()) {
152-
ss << "project(" << cmake.proj_name << " VERSION " << cmake.proj_version << ")\n\n";
152+
ss << "set(" << cmake.proj_name << "_PROJECT_VERSION " << cmake.proj_version << ")\n"
153+
<< "project(" << cmake.proj_name << " VERSION "
154+
<< "${" << cmake.proj_name << "_PROJECT_VERSION}"
155+
<< ")\n\n";
153156
}
154157

155158
if (!cmake.packages.empty()) {
@@ -202,11 +205,28 @@ int generate_cmake(const char *path) {
202205
if (!cmake.options.empty()) {
203206
for (const auto &opt : cmake.options) {
204207
ss << "option(" << opt.name << " \"" << opt.comment << "\" "
205-
<< (opt.val ? "ON" : "OFF") << ")\n";
208+
<< (opt.val ? "ON" : "OFF") << ")\n\n";
206209
}
207210
}
208211

209-
ss << "\n";
212+
if (!cmake.settings.empty()) {
213+
for (const auto &set : cmake.settings) {
214+
std::string set_val;
215+
if (set.val.index() == 1) {
216+
set_val = std::get<std::string>(set.val);
217+
} else {
218+
set_val = std::get<bool>(set.val) ? "ON" : "OFF";
219+
}
220+
ss << "set(" << set.name << " " << set_val;;
221+
if (set.cache) {
222+
std::string typ;
223+
if (set.val.index() == 1) typ = "STRING"; else typ = "BOOL";
224+
ss << " CACHE " << typ << " \"" << set.comment << "\"";
225+
if (set.force) ss << " FORCE";
226+
}
227+
ss << ")\n\n";
228+
}
229+
}
210230

211231
if (!cmake.binaries.empty()) {
212232
for (const auto &bin : cmake.binaries) {
@@ -282,6 +302,14 @@ int generate_cmake(const char *path) {
282302
}
283303
ss << ")\n\n";
284304
}
305+
306+
if (!bin.properties.empty()) {
307+
ss << "set_target_properties(" << bin.name << " PROPERTIES\n";
308+
for (const auto &prop : bin.properties) {
309+
ss << "\t" << prop.first << " " << prop.second << "\n";
310+
}
311+
ss << "\t)\n\n";
312+
}
285313
}
286314
}
287315

src/help.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace cmkr::help {
44

5-
const char *version() noexcept { return "cmkr version 0.1.0"; }
5+
const char *version() noexcept { return "cmkr version 0.1.2"; }
66

77
const char *message() noexcept {
88
return R"lit(

0 commit comments

Comments
 (0)