From 2450cfb2c9e0cd7dbb6da077af8a2cab68734f30 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Mon, 14 Jun 2021 23:29:51 +0200 Subject: [PATCH 1/2] Implement conditional properties Closes #8 --- include/cmake.hpp | 2 +- src/cmake.cpp | 26 ++++++++++++++++++++------ src/gen.cpp | 4 +++- tests/conditions/cmake.toml | 8 +++++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/cmake.hpp b/include/cmake.hpp index 54ec38c..025488f 100644 --- a/include/cmake.hpp +++ b/include/cmake.hpp @@ -85,7 +85,7 @@ struct Target { ConditionVector private_precompile_headers; std::string alias; - tsl::ordered_map properties; + Condition> properties; Condition cmake_before; Condition cmake_after; diff --git a/src/cmake.cpp b/src/cmake.cpp index cf6bb71..afbe9fd 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -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, ""); } } } diff --git a/src/gen.cpp b/src/gen.cpp index 99d17e0..01e25b8 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -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 &properties) { + cmd("set_target_properties")(target.name, "PROPERTIES", properties); + }); } gen.handle_condition(target.include_after, diff --git a/tests/conditions/cmake.toml b/tests/conditions/cmake.toml index ceed98b..007c7b8 100644 --- a/tests/conditions/cmake.toml +++ b/tests/conditions/cmake.toml @@ -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)" \ No newline at end of file +custom.cmake-after = "message(STATUS custom-after)" + +[target.example.properties] +AUTOMOC = false +custom.OUTPUT_NAME = "example2" +custom.AUTORCC = true +AUTOGEN = "ON" \ No newline at end of file From a12b3ae021ba337b9f03e8baa033d4fe112c503f Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Mon, 14 Jun 2021 23:36:39 +0200 Subject: [PATCH 2/2] Bump CMKR_TAG --- cmake/cmkr.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cmkr.cmake b/cmake/cmkr.cmake index 993265e..adfb569 100644 --- a/cmake/cmkr.cmake +++ b/cmake/cmkr.cmake @@ -2,7 +2,7 @@ include_guard() # Change these defaults to point to your infrastructure if desired set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE) -set(CMKR_TAG "archive_af3807ca" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) +set(CMKR_TAG "archive_2450cfb2" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) # Set these from the command line to customize for development/debugging purposes set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable")