From 49bdda147527d24fb4b8bd8185060ddb17f78a38 Mon Sep 17 00:00:00 2001 From: stasoid Date: Sun, 1 Dec 2024 14:43:10 +0500 Subject: [PATCH] AK: Simplify usage of windows.h and winsock2.h Use instead of windows.h/winsock2.h to avoid timeval-related errors. Note: winsock2.h includes windows.h --- AK/Time.cpp | 4 +--- AK/Windows.h | 21 +++++++++++++++++++ Libraries/LibCore/CMakeLists.txt | 4 ---- .../EventLoopImplementationWindows.cpp | 4 ++-- 4 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 AK/Windows.h diff --git a/AK/Time.cpp b/AK/Time.cpp index 923f6404da..d10340e597 100644 --- a/AK/Time.cpp +++ b/AK/Time.cpp @@ -8,9 +8,7 @@ #include #ifdef AK_OS_WINDOWS -# define timeval dummy_timeval -# include -# undef timeval +# include #endif namespace AK { diff --git a/AK/Windows.h b/AK/Windows.h new file mode 100644 index 0000000000..bc5076b2a6 --- /dev/null +++ b/AK/Windows.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024, stasoid + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +// This header should be included only in cpp files. +// It should be included after all other files and should be separated from them by a non-#include line to prevent clang-format from changing header order. + +#pragma once + +#include + +#ifdef AK_OS_WINDOWS // needed for Swift +# define timeval dummy_timeval +# include +# undef timeval +# undef IN +# pragma comment(lib, "ws2_32.lib") +# include +#endif diff --git a/Libraries/LibCore/CMakeLists.txt b/Libraries/LibCore/CMakeLists.txt index c54c02166c..c4b90d12b6 100644 --- a/Libraries/LibCore/CMakeLists.txt +++ b/Libraries/LibCore/CMakeLists.txt @@ -110,7 +110,3 @@ endif() if (ANDROID) target_link_libraries(LibCore PRIVATE log) endif() - -if (WIN32) - target_link_libraries(LibCore PRIVATE ws2_32.lib) -endif() diff --git a/Libraries/LibCore/EventLoopImplementationWindows.cpp b/Libraries/LibCore/EventLoopImplementationWindows.cpp index d233347533..15d162a216 100644 --- a/Libraries/LibCore/EventLoopImplementationWindows.cpp +++ b/Libraries/LibCore/EventLoopImplementationWindows.cpp @@ -8,8 +8,8 @@ #include #include #include -#include -#include + +#include struct Handle { HANDLE handle = NULL;