From f4ef95eabc43fa958d5eb257895ca5609e5b77f8 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Tue, 16 Mar 2021 17:49:19 +0100 Subject: [PATCH] Add inject-before and inject-after --- src/cmkrlib/cmake.cpp | 6 ++++++ src/cmkrlib/cmake.hpp | 2 ++ src/cmkrlib/gen.cpp | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/src/cmkrlib/cmake.cpp b/src/cmkrlib/cmake.cpp index 420bb68..193ff0d 100644 --- a/src/cmkrlib/cmake.cpp +++ b/src/cmkrlib/cmake.cpp @@ -73,6 +73,12 @@ CMake::CMake(const std::string &path, bool build) { const auto &project = toml::find(toml, "project"); project_name = toml::find(project, "name").as_string(); project_version = toml::find(project, "version").as_string(); + if (project.contains("inject-before")) { + inject_before = toml::find(project, "inject-before").as_string(); + } + if (project.contains("inject-after")) { + inject_after = toml::find(project, "inject-after").as_string(); + } if (project.contains("include-before")) { include_before = detail::to_string_vec(toml::find(project, "include-before").as_array()); } diff --git a/src/cmkrlib/cmake.hpp b/src/cmkrlib/cmake.hpp index 294b5b4..48d4434 100644 --- a/src/cmkrlib/cmake.hpp +++ b/src/cmkrlib/cmake.hpp @@ -69,6 +69,8 @@ struct CMake { std::vector build_args; std::string project_name; std::string project_version; + std::string inject_before; + std::string inject_after; std::vector include_before; std::vector include_after; std::vector settings; diff --git a/src/cmkrlib/gen.cpp b/src/cmkrlib/gen.cpp index 6a826c8..a52596e 100644 --- a/src/cmkrlib/gen.cpp +++ b/src/cmkrlib/gen.cpp @@ -230,6 +230,10 @@ int generate_cmake(const char *path) { comment("This file was generated automatically by cmkr.").endl(); + if (!cmake.inject_before.empty()) { + ss << cmake.inject_before << "\n\n"; + } + if (!cmake.include_before.empty()) { for (const auto &file : cmake.include_before) { // TODO: warn/error if file doesn't exist? @@ -292,6 +296,10 @@ int generate_cmake(const char *path) { cmd("project")(name, "VERSION", "${" + name + "_PROJECT_VERSION}").endl(); } + if (!cmake.inject_after.empty()) { + ss << cmake.inject_after << "\n\n"; + } + if (!cmake.include_after.empty()) { for (const auto &file : cmake.include_after) { // TODO: warn/error if file doesn't exist?