From f32ea490fed966d888fa439bb0368d3eab4677a6 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 30 Mar 2021 13:39:56 +0200 Subject: [PATCH] Support inject and include for targets --- src/cmkrlib/cmake.cpp | 13 +++++++++++++ src/cmkrlib/cmake.hpp | 5 +++++ src/cmkrlib/gen.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/cmkrlib/cmake.cpp b/src/cmkrlib/cmake.cpp index 95d2f7d..4b3ecfd 100644 --- a/src/cmkrlib/cmake.cpp +++ b/src/cmkrlib/cmake.cpp @@ -222,6 +222,19 @@ CMake::CMake(const std::string &path, bool build) { target.properties = toml::find(t, "properties"); } + if (t.contains("inject-before")) { + target.inject_before = toml::find(t, "inject-before").as_string(); + } + if (t.contains("inject-after")) { + target.inject_after = toml::find(t, "inject-after").as_string(); + } + if (t.contains("include-before")) { + target.include_before = detail::to_string_vec(toml::find(t, "include-before").as_array()); + } + if (t.contains("include-after")) { + target.include_after = detail::to_string_vec(toml::find(t, "include-after").as_array()); + } + targets.push_back(target); } } diff --git a/src/cmkrlib/cmake.hpp b/src/cmkrlib/cmake.hpp index a3f14a1..ceef2a6 100644 --- a/src/cmkrlib/cmake.hpp +++ b/src/cmkrlib/cmake.hpp @@ -48,6 +48,11 @@ struct Target { std::string alias; tsl::ordered_map properties; + + std::string inject_before; + std::string inject_after; + std::vector include_before; + std::vector include_after; }; struct Test { diff --git a/src/cmkrlib/gen.cpp b/src/cmkrlib/gen.cpp index 72a4377..3e1eaa4 100644 --- a/src/cmkrlib/gen.cpp +++ b/src/cmkrlib/gen.cpp @@ -428,6 +428,18 @@ int generate_cmake(const char *path, bool root) { cmd("set")(target.name + "_SOURCES", sources).endl(); } + if (!target.inject_before.empty()) { + ss << target.inject_before << "\n\n"; + } + + if (!target.include_before.empty()) { + for (const auto &file : target.include_before) { + // TODO: warn/error if file doesn't exist? + cmd("include")(file); + } + endl(); + } + cmd(add_command)(target.name, target_type, "${" + target.name + "_SOURCES}").endl(); if (!target.sources.empty()) { @@ -455,6 +467,18 @@ int generate_cmake(const char *path, bool root) { if (!target.properties.empty()) { cmd("set_target_properties")(target.name, "PROPERTIES", target.properties).endl(); } + + if (!target.inject_after.empty()) { + ss << target.inject_after << "\n\n"; + } + + if (!target.include_after.empty()) { + for (const auto &file : target.include_after) { + // TODO: warn/error if file doesn't exist? + cmd("include")(file); + } + endl(); + } } }