Skip to content

Commit

Permalink
Fix downversioning of _WIN32_WINNT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robUx4 committed Jun 26, 2023
1 parent ec52c45 commit 55690b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions scripts/test_vista.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright © 2023 Steve Lhomme */
/* SPDX-License-Identifier: ISC */
#include <windows.h>
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 /* _WIN32_WINNT_VISTA */
#error NOPE
#endif
int main(void)
{
return 0;
}

0 comments on commit 55690b9

Please sign in to comment.