Define WIN32_LEAN_AND_MEAN globally

In modern Windows code WIN32_LEAN_AND_MEAN should be defined.

Without this define windows.h pulls in some legacy headers, notably
winsocks.h. Modern code that cares about winsocks includes winsocks2.h
which conflicts with winsocks.h. Other code that does not care about
winsocks (OpenGL, fontconfig, ...) includes windows.h pulling in legacy
winsocks.h, causing definition conflicts and build errors.

At worst defining WIN32_LEAN_AND_MEAN requires explicitly including some
additional headers on Windows.
This commit is contained in:
Michal Suchanek 2025-04-28 21:23:03 +02:00 committed by Mark Roszko
parent ca54db2db4
commit 81bbb5e67b
5 changed files with 10 additions and 3 deletions

View File

@ -42,7 +42,6 @@
#ifdef _WIN32
// required for the windows gl.h to work
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

View File

@ -62,6 +62,15 @@ set( CMAKE_MODULE_PATH "${KICAD_CMAKE_MODULE_PATH}" )
include( ConfigurePlatform )
if( WIN32 )
# Without WIN32_LEAN_AND_MEAN defined including windows.h pulls in legacy
# winsocks.h which conflicts with winsocks2.h used by modern libraries such
# as curl.
# There is no harm in defining this globally, at worst some additional
# headers have to be included explicitly.
add_compile_definitions( WIN32_LEAN_AND_MEAN )
endif()
# Create a flag to identify the non-Apple unix systems
if( UNIX AND NOT APPLE )
set( UNIX_NOT_APPLE ON )

View File

@ -29,6 +29,7 @@
#ifdef __WXMSW__
#include <windows.h>
#include <winspool.h>
#elif defined( CUPS_LIST_PRINTERS )
#include <cups/cups.h>
#endif

View File

@ -30,7 +30,6 @@
#include <embedded_files.h>
#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

View File

@ -28,7 +28,6 @@
#if defined( _WIN32 )
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
int64_t GetRunningMicroSecs()