From 55690b9dabd5c9f73be97802cf02831c292e8b64 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Wed, 14 Jun 2023 08:50:50 +0200 Subject: [PATCH] Fix downversioning of _WIN32_WINNT Forcing the _WIN32_WINNT when the environment is already forcing a value results in a lot of warning. If the user compiles for a higher version of Windows, we don't need to force compilation for Vista. --- CMakeLists.txt | 8 +++++++- scripts/test_vista.c | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 scripts/test_vista.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e211f2e2..d99ccf039 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,7 +291,13 @@ if(WIN32) if(ENABLE_INET_PTON) set(CMAKE_REQUIRED_LIBRARIES ws2_32) check_function_exists(inet_pton HAVE_INET_PTON) - add_definitions(-D_WIN32_WINNT=0x0600) + try_compile(AT_LEAST_VISTA + ${CMAKE_BINARY_DIR} + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/test_vista.c") + if(NOT AT_LEAST_VISTA) + # force targeting Vista + add_definitions(-D_WIN32_WINNT=0x0600) + endif() else() add_definitions(-D_WIN32_WINNT=0x0501) endif() diff --git a/scripts/test_vista.c b/scripts/test_vista.c new file mode 100644 index 000000000..833a4d373 --- /dev/null +++ b/scripts/test_vista.c @@ -0,0 +1,10 @@ +/* Copyright © 2023 Steve Lhomme */ +/* SPDX-License-Identifier: ISC */ +#include +#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 /* _WIN32_WINNT_VISTA */ +#error NOPE +#endif +int main(void) +{ + return 0; +}