From 4922d526feb41bae0353994e907e343972acd4ef Mon Sep 17 00:00:00 2001 From: oltolm Date: Sat, 22 Nov 2025 09:32:29 +0100 Subject: [PATCH] msys2: fix build (#3818) * cmake: fix mingw-w64 build * time.cpp: fix build with Clang on Windows * tls.h: include malloc.h for alloca --- CMakeLists.txt | 18 +++++++++++------- externals/CMakeLists.txt | 2 +- src/core/libraries/kernel/time.cpp | 23 ++++++++++++++++++++--- src/core/tls.h | 3 +++ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ddaf2422c..7c1ebca79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -228,8 +228,10 @@ find_package(half 1.12.0 MODULE) find_package(magic_enum 0.9.7 CONFIG) find_package(PNG 1.6 MODULE) find_package(RenderDoc 1.6.0 MODULE) -find_package(SDL3 3.1.2 CONFIG) find_package(SDL3_mixer 2.8.1 CONFIG) +if (SDL3_mixer_FOUND) + find_package(SDL3 3.1.2 CONFIG) +endif() find_package(stb MODULE) find_package(toml11 4.2.0 CONFIG) find_package(tsl-robin-map 1.3.0 CONFIG) @@ -554,6 +556,8 @@ set(FIBER_LIB src/core/libraries/fiber/fiber_context.s src/core/libraries/fiber/fiber_error.h ) +set_source_files_properties(src/core/libraries/fiber/fiber_context.s PROPERTIES COMPILE_OPTIONS -Wno-unused-command-line-argument) + set(VDEC_LIB src/core/libraries/videodec/videodec2_impl.cpp src/core/libraries/videodec/videodec2_impl.h src/core/libraries/videodec/videodec2.cpp @@ -1122,22 +1126,22 @@ if (APPLE) endif() if (WIN32) - target_link_libraries(shadps4 PRIVATE mincore wepoll) + target_link_libraries(shadps4 PRIVATE mincore wepoll wbemuuid) if (MSVC) # MSVC likes putting opinions on what people can use, disable: - add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE _SCL_SECURE_NO_WARNINGS) endif() - add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN) + add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN) if (MSVC) # Needed for conflicts with time.h of windows.h - add_definitions(-D_TIMESPEC_DEFINED) + add_compile_definitions(_TIMESPEC_DEFINED) endif() # Target Windows 10 RS5 - add_definitions(-DNTDDI_VERSION=0x0A000006 -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00) + add_compile_definitions(NTDDI_VERSION=0x0A000006 _WIN32_WINNT=0x0A00 WINVER=0x0A00) if (MSVC) target_link_libraries(shadps4 PRIVATE clang_rt.builtins-x86_64.lib) @@ -1169,7 +1173,7 @@ if (WIN32) target_sources(shadps4 PRIVATE src/shadps4.rc) endif() -add_definitions(-DBOOST_ASIO_STANDALONE) +add_compile_definitions(BOOST_ASIO_STANDALONE) target_include_directories(shadps4 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 5f7ae94c4..b6c7c746e 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -152,7 +152,7 @@ endif() # sirit add_subdirectory(sirit) if (WIN32) - target_compile_options(sirit PUBLIC "-Wno-error=unused-command-line-argument") + target_compile_options(sirit PRIVATE "-Wno-error=unused-command-line-argument") endif() # half diff --git a/src/core/libraries/kernel/time.cpp b/src/core/libraries/kernel/time.cpp index ad07678b2..51f86e2c7 100644 --- a/src/core/libraries/kernel/time.cpp +++ b/src/core/libraries/kernel/time.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include "common/assert.h" @@ -485,25 +486,41 @@ Common::NativeClock* GetClock() { s32 PS4_SYSV_ABI sceKernelConvertUtcToLocaltime(time_t time, time_t* local_time, struct OrbisTimesec* st, u64* dst_sec) { LOG_TRACE(Kernel, "Called"); +#ifdef _WIN32 + TIME_ZONE_INFORMATION tz{}; + DWORD res = GetTimeZoneInformation(&tz); + *local_time = time - tz.Bias; + + if (st != nullptr) { + st->t = time; + st->west_sec = -tz.Bias * 60; + st->dst_sec = res == TIME_ZONE_ID_DAYLIGHT ? -_dstbias : 0; + } + + if (dst_sec != nullptr) { + *dst_sec = res == TIME_ZONE_ID_DAYLIGHT ? -_dstbias : 0; + } +#else #ifdef __APPLE__ // std::chrono::current_zone() not available yet. const auto* time_zone = date::current_zone(); #else const auto* time_zone = std::chrono::current_zone(); -#endif +#endif // __APPLE__ auto info = time_zone->get_info(std::chrono::system_clock::now()); *local_time = info.offset.count() + info.save.count() * 60 + time; if (st != nullptr) { st->t = time; - st->west_sec = info.offset.count() * 60; + st->west_sec = info.offset.count(); st->dst_sec = info.save.count() * 60; } if (dst_sec != nullptr) { *dst_sec = info.save.count() * 60; } +#endif // _WIN32 return ORBIS_OK; } @@ -565,4 +582,4 @@ void RegisterTime(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("-o5uEDpN+oY", "libkernel", 1, "libkernel", sceKernelConvertUtcToLocaltime); } -} // namespace Libraries::Kernel \ No newline at end of file +} // namespace Libraries::Kernel diff --git a/src/core/tls.h b/src/core/tls.h index 6be9752b0..0ae512a04 100644 --- a/src/core/tls.h +++ b/src/core/tls.h @@ -5,6 +5,9 @@ #include #include "common/types.h" +#ifdef _WIN32 +#include +#endif namespace Xbyak { class CodeGenerator;