Merge pull request #8028 from Robyt3/Windows-Defines-CMakeLists

Define Windows header macros only once in `CMakeLists.txt`
This commit is contained in:
heinrich5991 2024-02-28 22:28:43 +00:00 committed by GitHub
commit ffc7ad0924
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 6 additions and 17 deletions

View file

@ -3346,7 +3346,13 @@ foreach(target ${TARGETS_OWN})
target_compile_options(${target} PRIVATE /wd4800) # Implicit conversion of int to bool. target_compile_options(${target} PRIVATE /wd4800) # Implicit conversion of int to bool.
endif() endif()
if(TARGET_OS STREQUAL "windows") if(TARGET_OS STREQUAL "windows")
# See https://learn.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers
target_compile_definitions(${target} PRIVATE NOMINMAX) # windows.h shouldn't define min/max macros target_compile_definitions(${target} PRIVATE NOMINMAX) # windows.h shouldn't define min/max macros
target_compile_definitions(${target} PRIVATE WIN32_LEAN_AND_MEAN) # windows.h shouldn't define the name IStorage
# 0x0501 (Windows XP) is required for mingw to get getaddrinfo to work
# 0x0600 (Windows Vista) is required to use RegGetValueW and RegDeleteTreeW
target_compile_definitions(${target} PRIVATE NTDDI_VERSION=0x06000000) # Minimum OS version (new macro, since Vista)
target_compile_definitions(${target} PRIVATE _WIN32_WINNT=0x0600) # Minimum OS version (old macro, both must be defined)
target_compile_definitions(${target} PRIVATE UNICODE) # Windows headers target_compile_definitions(${target} PRIVATE UNICODE) # Windows headers
target_compile_definitions(${target} PRIVATE _UNICODE) # C-runtime target_compile_definitions(${target} PRIVATE _UNICODE) # C-runtime
endif() endif()

View file

@ -8,9 +8,6 @@
#include <memory> #include <memory>
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 /* required for mingw to get getaddrinfo to work */
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>

View file

@ -62,11 +62,6 @@
#endif #endif
#elif defined(CONF_FAMILY_WINDOWS) #elif defined(CONF_FAMILY_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#undef _WIN32_WINNT
// 0x0501 (Windows XP) is required for mingw to get getaddrinfo to work
// 0x0600 (Windows Vista) is required to use RegGetValueW and RegDeleteTreeW
#define _WIN32_WINNT 0x0600
#include <windows.h> #include <windows.h>
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>

View file

@ -1,8 +1,6 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#define _WIN32_WINNT 0x0501
#include <base/hash.h> #include <base/hash.h>
#include <base/hash_ctxt.h> #include <base/hash_ctxt.h>
#include <base/logger.h> #include <base/logger.h>

View file

@ -25,7 +25,6 @@
#endif #endif
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
// windows.h must be included before imm.h, but clang-format requires includes to be sorted alphabetically, hence this comment. // windows.h must be included before imm.h, but clang-format requires includes to be sorted alphabetically, hence this comment.
#include <imm.h> #include <imm.h>

View file

@ -1,6 +1,3 @@
#define _WIN32_WINNT 0x0501
#include <base/logger.h> #include <base/logger.h>
#include <base/system.h> #include <base/system.h>
@ -23,7 +20,6 @@
#include <vector> #include <vector>
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#endif #endif

View file

@ -79,7 +79,6 @@ void CFifo::Update()
#elif defined(CONF_FAMILY_WINDOWS) #elif defined(CONF_FAMILY_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
void CFifo::Init(IConsole *pConsole, char *pFifoFile, int Flag) void CFifo::Init(IConsole *pConsole, char *pFifoFile, int Flag)

View file

@ -15,7 +15,6 @@
#include <csignal> #include <csignal>
#endif #endif
#define WIN32_LEAN_AND_MEAN
#include <curl/curl.h> #include <curl/curl.h>
// There is a stray constant on Windows/MSVC... // There is a stray constant on Windows/MSVC...