Skip to content

Commit 8ea5b77

Browse files
authored
Merge pull request #28 from build-cpp/conditional-properties
Implement conditional properties
2 parents 8d02455 + a12b3ae commit 8ea5b77

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

cmake/cmkr.cmake

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

33
# Change these defaults to point to your infrastructure if desired
44
set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE)
5-
set(CMKR_TAG "archive_af3807ca" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
5+
set(CMKR_TAG "archive_2450cfb2" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
66

77
# Set these from the command line to customize for development/debugging purposes
88
set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable")

include/cmake.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct Target {
8585
ConditionVector private_precompile_headers;
8686

8787
std::string alias;
88-
tsl::ordered_map<std::string, std::string> properties;
88+
Condition<tsl::ordered_map<std::string, std::string>> properties;
8989

9090
Condition<std::string> cmake_before;
9191
Condition<std::string> cmake_after;

src/cmake.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,33 @@ CMake::CMake(const std::string &path, bool build) {
219219
}
220220

221221
if (t.contains("properties")) {
222-
const auto &props = toml::find(t, "properties").as_table();
223-
for (const auto &propKv : props) {
224-
if (propKv.second.is_array()) {
222+
auto store_property = [&target](const toml::key &k, const TomlBasicValue &v, const std::string &condition) {
223+
if (v.is_array()) {
225224
std::string property_list;
226-
for (const auto &list_val : propKv.second.as_array()) {
225+
for (const auto &list_val : v.as_array()) {
227226
if (!property_list.empty()) {
228227
property_list += ';';
229228
}
230229
property_list += list_val.as_string();
231230
}
232-
target.properties[propKv.first] = property_list;
231+
target.properties[condition][k] = property_list;
232+
} else if (v.is_boolean()) {
233+
target.properties[condition][k] = v.as_boolean() ? "ON" : "OFF";
234+
} else {
235+
target.properties[condition][k] = v.as_string();
236+
}
237+
};
238+
239+
const auto &props = toml::find(t, "properties").as_table();
240+
for (const auto &propKv : props) {
241+
const auto &k = propKv.first;
242+
const auto &v = propKv.second;
243+
if (v.is_table()) {
244+
for (const auto &condKv : v.as_table()) {
245+
store_property(condKv.first, condKv.second, k);
246+
}
233247
} else {
234-
target.properties[propKv.first] = propKv.second.as_string();
248+
store_property(k, v, "");
235249
}
236250
}
237251
}

src/gen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,9 @@ int generate_cmake(const char *path, bool root) {
780780
target_cmd("target_precompile_headers", target.private_precompile_headers, "PRIVATE");
781781

782782
if (!target.properties.empty()) {
783-
cmd("set_target_properties")(target.name, "PROPERTIES", target.properties).endl();
783+
gen.handle_condition(target.properties, [&](const std::string &, const tsl::ordered_map<std::string, std::string> &properties) {
784+
cmd("set_target_properties")(target.name, "PROPERTIES", properties);
785+
});
784786
}
785787

786788
gen.handle_condition(target.include_after,

tests/conditions/cmake.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ windows.cmake-after = "message(STATUS win32-after)"
1414
macos.cmake-after = "message(STATUS macos-after)"
1515
linux.cmake-after = "message(STATUS linux-after)"
1616
unix.cmake-after = "message(STATUS unix-after)"
17-
custom.cmake-after = "message(STATUS custom-after)"
17+
custom.cmake-after = "message(STATUS custom-after)"
18+
19+
[target.example.properties]
20+
AUTOMOC = false
21+
custom.OUTPUT_NAME = "example2"
22+
custom.AUTORCC = true
23+
AUTOGEN = "ON"

0 commit comments

Comments
 (0)