Skip to content

Commit

Permalink
cmake: do not force Windows target versions
Browse files Browse the repository at this point in the history
The goal of this patch is to avoid CMake forcing specific Windows
versions and rely on toolchain defaults instead. This gives back
control to the user. Curl is able to adapt to what's available.
This also brings CMake closer to how autotools and `Makefile.m32`
behaves in this regard.

- CMake had a setting `ENABLE_INET_PTON` defaulting to `ON`, which
  did nothing else than fixing the Windows build target to Vista.
  This was done even when the toolchain did not have Vista support
  (e.g. original MinGW), breaking such builds.

  On other systems it did not make a user-facing difference, because
  libcurl has its own pton() implementation, so it works equally well
  with or without Vista's inet_pton().

  This patch drops this setting. inet_pton() is now used whenever
  building for Vista or newer, either when requested manually via or
  by default with modern toolchains (e.g. mingw-w64). Older envs will
  fall back to curl's pton().

  Ref: curl#9027 (comment)
  Ref: curl#8997 (comment)

- Deprecate `CURL_TARGET_WINDOWS_VERSION` in favour of the universal
  way of setting the Windows target version: `-D_WIN32_WINNT=0xnnnn`.
  This can be passed to CMake like this:
    `-DCMAKE_C_FLAGS=-D_WIN32_WINNT=0xnnnn`

  `CURL_TARGET_WINDOWS_VERSION` was introduced in early 2021, so it
  is also an option to delete it, if we have an agreement on that.

- When the user did no select a Windows target version manually, stop
  explicitly targeting Windows XP, and instead use whatever the
  toolchain default is.

  This may pose an issue with old toolchains defaulting to pre-XP
  targets. In such case you must manually target Windows XP via:
    `-DCMAKE_C_FLAGS=-D_WIN32_WINNT=0x0501`

Closes #xxxx
  • Loading branch information
vszakats committed Jun 24, 2022
1 parent 2b67a0a commit 644b784
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions CMakeLists.txt
Expand Up @@ -78,20 +78,11 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
if(WIN32)
option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
option(ENABLE_INET_PTON "Set to OFF to prevent usage of inet_pton when building against modern SDKs while still requiring compatibility with older Windows versions, such as Windows XP, Windows Server 2003 etc." ON)
option(ENABLE_UNICODE "Set to ON to use the Unicode version of the Windows API functions" OFF)
set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string")
set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string (deprecated)")
if(CURL_TARGET_WINDOWS_VERSION)
add_definitions(-D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION})
set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=${CURL_TARGET_WINDOWS_VERSION}")
elseif(ENABLE_INET_PTON)
# _WIN32_WINNT_VISTA (0x0600)
add_definitions(-D_WIN32_WINNT=0x0600)
set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0600")
else()
# _WIN32_WINNT_WINXP (0x0501)
add_definitions(-D_WIN32_WINNT=0x0501)
set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0501")
endif()
if(ENABLE_UNICODE)
add_definitions(-DUNICODE -D_UNICODE)
Expand Down

0 comments on commit 644b784

Please sign in to comment.