diff --git a/docs/cmake-toml.md b/docs/cmake-toml.md index ea335fa..d91d484 100644 --- a/docs/cmake-toml.md +++ b/docs/cmake-toml.md @@ -105,6 +105,8 @@ The vcpkg `version` will automatically generate the `url` from the [official rep To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`. +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. + ## Packages ```toml @@ -116,8 +118,6 @@ config = true components = ["mycomponent"] ``` -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. - ## FetchContent **Note**: The `[fetch-content]` feature is unpolished and will likely change in a future release. diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index 7e01d98..687a7aa 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -634,14 +634,18 @@ void generate_cmake(const char *path, const parser::Project *parent_project) { cmd("include")("FetchContent"); cmd("message")("STATUS", "Fetching vcpkg (" + version_name + ")..."); cmd("FetchContent_Declare")("vcpkg", "URL", url); - cmd("FetchContent_MakeAvailable")("vcpkg"); - if (!project.vcpkg.crt_linkage.empty()) { - cmd("set")("VCPKG_CRT_LINKAGE", project.vcpkg.crt_linkage); - } - if (!project.vcpkg.library_linkage.empty()) { - cmd("set")("VCPKG_LIBRARY_LINKAGE", project.vcpkg.library_linkage); - } - cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake"); + // Not using FetchContent_MakeAvailable here in case vcpkg adds CMakeLists.txt + cmd("FetchContent_GetProperties")("vcpkg"); + cmd("if")("NOT", "vcpkg_POPULATED"); + cmd("FetchContent_Populate")("vcpkg"); + if (!project.vcpkg.crt_linkage.empty()) { + cmd("set")("VCPKG_CRT_LINKAGE", project.vcpkg.crt_linkage); + } + if (!project.vcpkg.library_linkage.empty()) { + cmd("set")("VCPKG_LIBRARY_LINKAGE", project.vcpkg.library_linkage); + } + cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake"); + cmd("endif")(); cmd("endif")(); endl(); // clang-format on