Implement conditional properties

Closes #8
toml-checker archive_2450cfb2
Duncan Ogilvie 4 years ago
parent 8d024556e3
commit 2450cfb2c9

@ -85,7 +85,7 @@ struct Target {
ConditionVector private_precompile_headers;
std::string alias;
tsl::ordered_map<std::string, std::string> properties;
Condition<tsl::ordered_map<std::string, std::string>> properties;
Condition<std::string> cmake_before;
Condition<std::string> cmake_after;

@ -219,19 +219,33 @@ CMake::CMake(const std::string &path, bool build) {
}
if (t.contains("properties")) {
const auto &props = toml::find(t, "properties").as_table();
for (const auto &propKv : props) {
if (propKv.second.is_array()) {
auto store_property = [&target](const toml::key &k, const TomlBasicValue &v, const std::string &condition) {
if (v.is_array()) {
std::string property_list;
for (const auto &list_val : propKv.second.as_array()) {
for (const auto &list_val : v.as_array()) {
if (!property_list.empty()) {
property_list += ';';
}
property_list += list_val.as_string();
}
target.properties[propKv.first] = property_list;
target.properties[condition][k] = property_list;
} else if (v.is_boolean()) {
target.properties[condition][k] = v.as_boolean() ? "ON" : "OFF";
} else {
target.properties[condition][k] = v.as_string();
}
};
const auto &props = toml::find(t, "properties").as_table();
for (const auto &propKv : props) {
const auto &k = propKv.first;
const auto &v = propKv.second;
if (v.is_table()) {
for (const auto &condKv : v.as_table()) {
store_property(condKv.first, condKv.second, k);
}
} else {
target.properties[propKv.first] = propKv.second.as_string();
store_property(k, v, "");
}
}
}

@ -780,7 +780,9 @@ int generate_cmake(const char *path, bool root) {
target_cmd("target_precompile_headers", target.private_precompile_headers, "PRIVATE");
if (!target.properties.empty()) {
cmd("set_target_properties")(target.name, "PROPERTIES", target.properties).endl();
gen.handle_condition(target.properties, [&](const std::string &, const tsl::ordered_map<std::string, std::string> &properties) {
cmd("set_target_properties")(target.name, "PROPERTIES", properties);
});
}
gen.handle_condition(target.include_after,

@ -14,4 +14,10 @@ windows.cmake-after = "message(STATUS win32-after)"
macos.cmake-after = "message(STATUS macos-after)"
linux.cmake-after = "message(STATUS linux-after)"
unix.cmake-after = "message(STATUS unix-after)"
custom.cmake-after = "message(STATUS custom-after)"
custom.cmake-after = "message(STATUS custom-after)"
[target.example.properties]
AUTOMOC = false
custom.OUTPUT_NAME = "example2"
custom.AUTORCC = true
AUTOGEN = "ON"
Loading…
Cancel
Save