From 61407464bf049ec013879e236e7f0bfae343ae16 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 28 Feb 2025 13:17:39 +0100 Subject: [PATCH] cmake: allow `CURL_STATIC_CRT` with UCRT VS2015+ builds After this patch, we're back to 8.12.1, but disallowing `CURL_STATIC_CRT=ON` with shared curl exe built with VS2013 or older. Because those may crash. A stable reprducer is with `ENABLE_DEBUG=ON` and calling `curl.exe -V`. You can pass the necessary CMake and MSVC linker options manually, to get around this condition. Shared build with static UCRT may be crashing too, depending on conditions. Consult the documentation about limitations of static CRT: https://learn.microsoft.com/cpp/c-runtime-library/crt-library-features Follow-up to 049352dd80e1ab73945c49a3bac2e4a08db32f98 #16516 Follow-up to edfa537100d6b5d2ac1b829c66757880afe59407 #16456 Ref: #16394 Closes #16522 --- .github/scripts/spellcheck.words | 1 + CMakeLists.txt | 4 ++-- docs/INSTALL-CMAKE.md | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/scripts/spellcheck.words b/.github/scripts/spellcheck.words index 6838545cc7..7d2efbc547 100644 --- a/.github/scripts/spellcheck.words +++ b/.github/scripts/spellcheck.words @@ -868,6 +868,7 @@ typedef typedefed Ubuntu ucLinux +UCRT UDP UI UID diff --git a/CMakeLists.txt b/CMakeLists.txt index a7962d710a..3bfea86fe5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,12 +352,12 @@ endif() if(WIN32) option(CURL_STATIC_CRT "Build libcurl with static CRT with MSVC (/MT)" OFF) if(CURL_STATIC_CRT AND MSVC) - if(BUILD_STATIC_CURL OR NOT BUILD_CURL_EXE) + if(MSVC_VERSION GREATER_EQUAL 1900 OR BUILD_STATIC_CURL OR NOT BUILD_CURL_EXE) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") string(APPEND CMAKE_C_FLAGS_RELEASE " -MT") string(APPEND CMAKE_C_FLAGS_DEBUG " -MTd") else() - message(WARNING "Static CRT requires static or no curl executable.") + message(WARNING "Static CRT requires UCRT, static libcurl or no curl executable.") endif() endif() endif() diff --git a/docs/INSTALL-CMAKE.md b/docs/INSTALL-CMAKE.md index d3439662e4..629118fdf6 100644 --- a/docs/INSTALL-CMAKE.md +++ b/docs/INSTALL-CMAKE.md @@ -238,7 +238,7 @@ target_link_libraries(my_target PRIVATE CURL::libcurl) - `CURL_LIBCURL_VERSIONED_SYMBOLS`: Enable libcurl versioned symbols. Default: `OFF` - `CURL_LIBCURL_VERSIONED_SYMBOLS_PREFIX`: Override default versioned symbol prefix. Default: `_` or `MULTISSL_` - `CURL_LTO`: Enable compiler Link Time Optimizations. Default: `OFF` -- `CURL_STATIC_CRT`: Build libcurl with static CRT with MSVC (`/MT`) (requires static or no curl executable). Default: `OFF` +- `CURL_STATIC_CRT`: Build libcurl with static CRT with MSVC (`/MT`) (requires UCRT, static libcurl or no curl executable). Default: `OFF` - `CURL_TARGET_WINDOWS_VERSION`: Minimum target Windows version as hex string. - `CURL_TEST_BUNDLES`: Bundle `libtest` and `unittest` tests into single binaries. Default: `OFF` - `CURL_WERROR`: Turn compiler warnings into errors. Default: `OFF`