From 5b8da4751237d2efbb96a3e7dbbacb21f0965db5 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 27 Mar 2024 21:00:06 +0100 Subject: [PATCH] build: Extract win32-compatibility stuff to a separate library --- LICENSE.adoc | 6 +++--- src/ccache/CMakeLists.txt | 4 ++++ src/third_party/CMakeLists.txt | 17 +---------------- src/third_party/win32-compat/CMakeLists.txt | 13 +++++++++++++ .../{ => win32-compat}/win32/getopt.c | 0 .../{ => win32-compat}/win32/getopt.h | 0 .../{ => win32-compat}/win32/mktemp.c | 0 .../{ => win32-compat}/win32/mktemp.h | 0 .../win32/winerror_to_errno.h | 0 9 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 src/third_party/win32-compat/CMakeLists.txt rename src/third_party/{ => win32-compat}/win32/getopt.c (100%) rename src/third_party/{ => win32-compat}/win32/getopt.h (100%) rename src/third_party/{ => win32-compat}/win32/mktemp.c (100%) rename src/third_party/{ => win32-compat}/win32/mktemp.h (100%) rename src/third_party/{ => win32-compat}/win32/winerror_to_errno.h (100%) diff --git a/LICENSE.adoc b/LICENSE.adoc index 901bd7e7d..8c8210829 100644 --- a/LICENSE.adoc +++ b/LICENSE.adoc @@ -613,7 +613,7 @@ express Statement of Purpose. ---- -=== src/third_party/win32/getopt.* +=== src/third_party/win32-compat/win32/getopt.* This implementation of `getopt_long()` for Win32 was taken from https://www.codeproject.com/Articles/157001/Full-getopt-Port-for-Unicode-and-Multibyte-Microso @@ -623,7 +623,7 @@ The full license text can be found in LGPL-3.0.txt and at https://www.gnu.org/licenses/lgpl-3.0.html. -=== src/third_party/win32/mktemp.* +=== src/third_party/win32-compat/win32/mktemp.* This implementation of `mkstemp()` for Win32 was adapted from @@ -647,7 +647,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ---- -=== src/third_party/win32/winerror_to_errno.h +=== src/third_party/win32-compat/win32/winerror_to_errno.h The implementation of `winerror_to_errno()` was adapted from diff --git a/src/ccache/CMakeLists.txt b/src/ccache/CMakeLists.txt index 629a36173..ec5d10533 100644 --- a/src/ccache/CMakeLists.txt +++ b/src/ccache/CMakeLists.txt @@ -59,6 +59,10 @@ target_link_libraries( Threads::Threads ) +if(WIN32) + target_link_libraries(ccache_framework PUBLIC win32_compat) +endif() + get_filename_component(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) target_include_directories(ccache_framework PUBLIC ${CMAKE_BINARY_DIR} ${SRC_DIR}) diff --git a/src/third_party/CMakeLists.txt b/src/third_party/CMakeLists.txt index a3071d24e..afebb64fe 100644 --- a/src/third_party/CMakeLists.txt +++ b/src/third_party/CMakeLists.txt @@ -1,18 +1,6 @@ add_library(third_party STATIC xxhash.c) target_include_directories(third_party INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) -if(MSVC) - target_sources(third_party PRIVATE win32/getopt.c) - target_compile_definitions(third_party PUBLIC -DSTATIC_GETOPT) -endif() - -if(WIN32) - target_sources(third_party PRIVATE win32/mktemp.c) -endif () - -file(GLOB headers *.h nonstd/*.hpp win32/*.h) -target_sources(third_party PRIVATE ${headers}) - set(xxhdispatchtest [=[ #include "xxh_x86dispatch.c" @@ -44,10 +32,6 @@ target_include_directories( target_link_libraries(third_party PRIVATE standard_settings) -if(WIN32) - target_link_libraries(third_party PRIVATE ws2_32) -endif() - # Silence warning from winbase.h due to /Zc:preprocessor. if(MSVC) target_compile_options(third_party PRIVATE /wd5105) @@ -55,6 +39,7 @@ endif() add_subdirectory(blake3) add_subdirectory(cxxurl) +add_subdirectory(win32-compat) if(NOT TARGET dep_cpphttplib) add_subdirectory(cpp-httplib) diff --git a/src/third_party/win32-compat/CMakeLists.txt b/src/third_party/win32-compat/CMakeLists.txt new file mode 100644 index 000000000..c0455c26f --- /dev/null +++ b/src/third_party/win32-compat/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(win32_compat STATIC EXCLUDE_FROM_ALL win32/mktemp.c) + +if(MSVC) + target_sources(win32_compat PRIVATE win32/getopt.c) + target_compile_definitions(win32_compat PUBLIC STATIC_GETOPT) +endif() + +# Silence warning from winbase.h due to /Zc:preprocessor. +if(MSVC) + target_compile_options(win32_compat PRIVATE /wd5105) +endif() + +target_include_directories(win32_compat INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/src/third_party/win32/getopt.c b/src/third_party/win32-compat/win32/getopt.c similarity index 100% rename from src/third_party/win32/getopt.c rename to src/third_party/win32-compat/win32/getopt.c diff --git a/src/third_party/win32/getopt.h b/src/third_party/win32-compat/win32/getopt.h similarity index 100% rename from src/third_party/win32/getopt.h rename to src/third_party/win32-compat/win32/getopt.h diff --git a/src/third_party/win32/mktemp.c b/src/third_party/win32-compat/win32/mktemp.c similarity index 100% rename from src/third_party/win32/mktemp.c rename to src/third_party/win32-compat/win32/mktemp.c diff --git a/src/third_party/win32/mktemp.h b/src/third_party/win32-compat/win32/mktemp.h similarity index 100% rename from src/third_party/win32/mktemp.h rename to src/third_party/win32-compat/win32/mktemp.h diff --git a/src/third_party/win32/winerror_to_errno.h b/src/third_party/win32-compat/win32/winerror_to_errno.h similarity index 100% rename from src/third_party/win32/winerror_to_errno.h rename to src/third_party/win32-compat/win32/winerror_to_errno.h -- 2.47.2