Skip to content

Commit cfee3bb

Browse files
authored
Merge pull request #111 from anthonyprintup/fetch-content-system
Fix #110
2 parents 7b1d333 + bcaa60c commit cfee3bb

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

docs/cmake-toml.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ condition = "mycondition"
151151
git = "https://github.com/myuser/gitcontent"
152152
tag = "v0.1"
153153
shallow = false
154+
system = false
154155

155156
[fetch-content.svncontent]
156157
condition = "mycondition"

include/project_parser.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct Content {
155155
Condition<std::string> cmake_after;
156156
ConditionVector include_before;
157157
ConditionVector include_after;
158+
bool system;
158159
};
159160

160161
enum MsvcRuntimeType {

src/cmake_generator.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
917917
version_info = " (" + content.arguments.at("SVN_REVISION") + ")";
918918
}
919919
cmd("message")("STATUS", "Fetching " + content.name + version_info + "...");
920-
cmd("FetchContent_Declare")(content.name, content.arguments);
920+
if (content.system) {
921+
cmd("FetchContent_Declare")(content.name, "SYSTEM", content.arguments);
922+
} else {
923+
cmd("FetchContent_Declare")(content.name, content.arguments);
924+
}
921925
cmd("FetchContent_MakeAvailable")(content.name).endl();
922926

923927
gen.conditional_includes(content.include_after);

src/project_parser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,15 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
443443
c.optional("cmake-after", content.cmake_after);
444444
c.optional("include-before", content.include_before);
445445
c.optional("include-after", content.include_after);
446+
c.optional("system", content.system);
447+
448+
// Check if the minimum version requirement is satisfied (CMake 3.25)
449+
if (c.contains("system") && !this->cmake_minimum_version(3, 25)) {
450+
throw_key_error("The system argument is only supported on CMake version 3.25 and above.\nSet the CMake version in cmake.toml:\n"
451+
"[cmake]\n"
452+
"version = \"3.25\"\n",
453+
"system", "");
454+
}
446455

447456
for (const auto &argItr : itr.second.as_table()) {
448457
std::string value;

0 commit comments

Comments
 (0)