From bcaa60cabe0255adf7f5ba58ca2adfa8c086f398 Mon Sep 17 00:00:00 2001 From: Anthony Printup <92564080+anthonyprintup@users.noreply.github.com> Date: Mon, 12 Jun 2023 15:41:20 +0200 Subject: [PATCH] feat: Added SYSTEM flag support to fetch-content --- docs/cmake-toml.md | 1 + include/project_parser.hpp | 1 + src/cmake_generator.cpp | 6 +++++- src/project_parser.cpp | 9 +++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/cmake-toml.md b/docs/cmake-toml.md index 593f1ed..00661ce 100644 --- a/docs/cmake-toml.md +++ b/docs/cmake-toml.md @@ -151,6 +151,7 @@ condition = "mycondition" git = "https://github.com/myuser/gitcontent" tag = "v0.1" shallow = false +system = false [fetch-content.svncontent] condition = "mycondition" diff --git a/include/project_parser.hpp b/include/project_parser.hpp index 7b7a855..9c8842f 100644 --- a/include/project_parser.hpp +++ b/include/project_parser.hpp @@ -155,6 +155,7 @@ struct Content { Condition cmake_after; ConditionVector include_before; ConditionVector include_after; + bool system; }; enum MsvcRuntimeType { diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index 712a64a..a871d3d 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -917,7 +917,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) { version_info = " (" + content.arguments.at("SVN_REVISION") + ")"; } cmd("message")("STATUS", "Fetching " + content.name + version_info + "..."); - cmd("FetchContent_Declare")(content.name, content.arguments); + if (content.system) { + cmd("FetchContent_Declare")(content.name, "SYSTEM", content.arguments); + } else { + cmd("FetchContent_Declare")(content.name, content.arguments); + } cmd("FetchContent_MakeAvailable")(content.name).endl(); gen.conditional_includes(content.include_after); diff --git a/src/project_parser.cpp b/src/project_parser.cpp index 8c99b40..1fb571b 100644 --- a/src/project_parser.cpp +++ b/src/project_parser.cpp @@ -443,6 +443,15 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p c.optional("cmake-after", content.cmake_after); c.optional("include-before", content.include_before); c.optional("include-after", content.include_after); + c.optional("system", content.system); + + // Check if the minimum version requirement is satisfied (CMake 3.25) + if (c.contains("system") && !this->cmake_minimum_version(3, 25)) { + throw_key_error("The system argument is only supported on CMake version 3.25 and above.\nSet the CMake version in cmake.toml:\n" + "[cmake]\n" + "version = \"3.25\"\n", + "system", ""); + } for (const auto &argItr : itr.second.as_table()) { std::string value;