Skip to content

Commit 13255c6

Browse files
committed
Use FetchContent_MakeAvailable for vcpkg in case they add CMakeLists.txt
1 parent 5768460 commit 13255c6

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

docs/cmake-toml.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ The vcpkg `version` will automatically generate the `url` from the [official rep
105105

106106
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`.
107107

108+
The `crt-linkage` specifies the MSVC runtime library variant to use while compiling packages. `library-linkage` is whether libraries built are dynamic (default) or static.
109+
108110
## Packages
109111

110112
```toml
@@ -116,8 +118,6 @@ config = true
116118
components = ["mycomponent"]
117119
```
118120

119-
The `crt-linkage` specifies the MSVC runtime library variant to use while compiling packages. `library-linkage` is whether libraries built are dynamic (default) or static.
120-
121121
## FetchContent
122122

123123
**Note**: The `[fetch-content]` feature is unpolished and will likely change in a future release.

src/cmake_generator.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,18 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
634634
cmd("include")("FetchContent");
635635
cmd("message")("STATUS", "Fetching vcpkg (" + version_name + ")...");
636636
cmd("FetchContent_Declare")("vcpkg", "URL", url);
637-
cmd("FetchContent_MakeAvailable")("vcpkg");
638-
if (!project.vcpkg.crt_linkage.empty()) {
639-
cmd("set")("VCPKG_CRT_LINKAGE", project.vcpkg.crt_linkage);
640-
}
641-
if (!project.vcpkg.library_linkage.empty()) {
642-
cmd("set")("VCPKG_LIBRARY_LINKAGE", project.vcpkg.library_linkage);
643-
}
644-
cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake");
637+
// Not using FetchContent_MakeAvailable here in case vcpkg adds CMakeLists.txt
638+
cmd("FetchContent_GetProperties")("vcpkg");
639+
cmd("if")("NOT", "vcpkg_POPULATED");
640+
cmd("FetchContent_Populate")("vcpkg");
641+
if (!project.vcpkg.crt_linkage.empty()) {
642+
cmd("set")("VCPKG_CRT_LINKAGE", project.vcpkg.crt_linkage);
643+
}
644+
if (!project.vcpkg.library_linkage.empty()) {
645+
cmd("set")("VCPKG_LIBRARY_LINKAGE", project.vcpkg.library_linkage);
646+
}
647+
cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake");
648+
cmd("endif")();
645649
cmd("endif")();
646650
endl();
647651
// clang-format on

0 commit comments

Comments
 (0)