From 3193d2cf5d1b02e103c1a01b24adc3999c5f3a58 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 2 Apr 2025 14:20:33 +0200 Subject: [PATCH] quick'n'dirty cmake 4.0 support --- .gitmodules | 2 +- CMakeLists.txt | 34 ++++++++-------- core/deps/glm/CMakeLists.txt | 4 +- core/deps/libchdr | 2 +- core/deps/libzip/CMakeLists.txt | 27 ++++++++----- core/deps/libzip/lib/CMakeLists.txt | 6 ++- core/deps/xbyak/CMakeLists.txt | 60 ++++++++++++++--------------- core/network/dcnet.cpp | 2 +- 8 files changed, 73 insertions(+), 64 deletions(-) diff --git a/.gitmodules b/.gitmodules index ef8c708d7..dcd56ae31 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,7 +3,7 @@ url = https://github.com/libsdl-org/SDL.git [submodule "core/deps/libchdr"] path = core/deps/libchdr - url = https://github.com/rtissera/libchdr.git + url = https://github.com/flyinghead/libchdr.git ignore = dirty [submodule "core/deps/luabridge"] path = core/deps/luabridge diff --git a/CMakeLists.txt b/CMakeLists.txt index d22f39a5f..01551e6a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -512,27 +512,33 @@ if(NOT LIBRETRO) endif() find_package(PkgConfig) + +if(NOT WITH_SYSTEM_ZLIB) + option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF) + add_subdirectory("core/deps/libchdr/deps/zlib-1.3.1" EXCLUDE_FROM_ALL) + set_target_properties(zlibstatic PROPERTIES POSITION_INDEPENDENT_CODE ON) + target_link_libraries(${PROJECT_NAME} PRIVATE zlibstatic) + # help libzip find the package + set(ZLIB_RELATIVE_PATH "core/deps/libchdr/deps/zlib-1.3.1") + set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${ZLIB_RELATIVE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/${ZLIB_RELATIVE_PATH}") +endif() + if(PKG_CONFIG_FOUND AND USE_HOST_LIBCHDR) pkg_check_modules(LIBCHDR IMPORTED_TARGET libchdr) target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::LIBCHDR) else() + option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF) + option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF) + option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF) + add_subdirectory(core/deps/libchdr/deps/zstd-1.5.6/build/cmake EXCLUDE_FROM_ALL) + target_link_libraries(${PROJECT_NAME} PRIVATE libzstd_static) + + option(WITH_SYSTEM_ZSTD "Use system provided zstd library" ON) add_subdirectory(core/deps/libchdr EXCLUDE_FROM_ALL) target_link_libraries(${PROJECT_NAME} PRIVATE chdr-static) target_include_directories(${PROJECT_NAME} PRIVATE core/deps/libchdr/include) endif() -if(NOT WITH_SYSTEM_ZLIB) - set(ZLIB_RELATIVE_PATH "core/deps/libchdr/deps/zlib-1.3.1") - target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/${ZLIB_RELATIVE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/${ZLIB_RELATIVE_PATH}") - # help libzip find the package - set(ZLIB_FOUND TRUE) - set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${ZLIB_RELATIVE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/${ZLIB_RELATIVE_PATH}") - - cmake_policy(SET CMP0026 OLD) - get_target_property(ZLIB_LIBRARY_RELEASE zlibstatic LOCATION) - get_target_property(ZLIB_LIBRARY_DEBUG zlibstatic LOCATION_Debug) -endif() - if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND NOT LIBRETRO) if(USE_LIBAO) pkg_check_modules(AO IMPORTED_TARGET ao) @@ -676,10 +682,6 @@ if(NOT MINIUPNP_FOUND) endif() if(NOT LIBZIP_FOUND OR NINTENDO_SWITCH) - cmake_policy(SET CMP0026 OLD) - set(zstd_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/core/deps/libchdr/deps/zstd-1.5.6/lib") - get_target_property(zstd_STATIC_LIBRARY libzstd_static LOCATION) - option(ENABLE_COMMONCRYPTO "Enable use of CommonCrypto" OFF) option(ENABLE_GNUTLS "Enable use of GnuTLS" OFF) option(ENABLE_MBEDTLS "Enable use of mbed TLS" OFF) diff --git a/core/deps/glm/CMakeLists.txt b/core/deps/glm/CMakeLists.txt index 843e75465..c413ffdd0 100644 --- a/core/deps/glm/CMakeLists.txt +++ b/core/deps/glm/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.2 FATAL_ERROR) -cmake_policy(VERSION 3.2) +cmake_minimum_required(VERSION 3.6 FATAL_ERROR) +cmake_policy(VERSION 3.6) set(GLM_VERSION "0.9.9") project(glm VERSION ${GLM_VERSION} LANGUAGES CXX) diff --git a/core/deps/libchdr b/core/deps/libchdr index 9b6ff6c3c..5f82799f2 160000 --- a/core/deps/libchdr +++ b/core/deps/libchdr @@ -1 +1 @@ -Subproject commit 9b6ff6c3c24311750096232a05ee9c5b4963e66c +Subproject commit 5f82799f2c8cad1e9cd26d39a0f8d36369a5534b diff --git a/core/deps/libzip/CMakeLists.txt b/core/deps/libzip/CMakeLists.txt index b2e77241a..cc8cc61f2 100644 --- a/core/deps/libzip/CMakeLists.txt +++ b/core/deps/libzip/CMakeLists.txt @@ -190,7 +190,9 @@ int main(int argc, char *argv[]) { }" HAVE_NULLABLE) test_big_endian(WORDS_BIGENDIAN) -find_package(ZLIB 1.1.2 REQUIRED) +if(NOT TARGET zlibstatic) + find_package(ZLIB 1.1.2 REQUIRED) +endif() # so developers on systems where zlib is named differently (Windows, sometimes) # can override the name used in the pkg-config file if (NOT ZLIB_LINK_LIBRARY_NAME) @@ -239,17 +241,22 @@ if(ENABLE_LZMA) endif(ENABLE_LZMA) if(ENABLE_ZSTD) - find_package(zstd 1.3.6) - if(zstd_FOUND) + if(TARGET libzstd_static) + set(zstd_TARGET libzstd_static) set(HAVE_LIBZSTD 1) - if(TARGET zstd::libzstd_shared) - set(zstd_TARGET zstd::libzstd_shared) - else() - set(zstd_TARGET zstd::libzstd_static) - endif() else() - message(WARNING "-- zstd library not found; zstandard support disabled") - endif(zstd_FOUND) + find_package(zstd 1.3.6) + if(zstd_FOUND) + set(HAVE_LIBZSTD 1) + if(TARGET zstd::libzstd_shared) + set(zstd_TARGET zstd::libzstd_shared) + else() + set(zstd_TARGET zstd::libzstd_static) + endif() + else() + message(WARNING "-- zstd library not found; zstandard support disabled") + endif() + endif() endif(ENABLE_ZSTD) if (COMMONCRYPTO_FOUND) diff --git a/core/deps/libzip/lib/CMakeLists.txt b/core/deps/libzip/lib/CMakeLists.txt index 1afefae00..5a7cc216f 100644 --- a/core/deps/libzip/lib/CMakeLists.txt +++ b/core/deps/libzip/lib/CMakeLists.txt @@ -175,7 +175,11 @@ if(SHARED_LIB_VERSIONNING) set_target_properties(zip PROPERTIES VERSION 5.5 SOVERSION 5) endif() -target_link_libraries(zip PRIVATE ZLIB::ZLIB) +if (TARGET zlibstatic) + target_link_libraries(zip PRIVATE zlibstatic) +else() + target_link_libraries(zip PRIVATE ZLIB::ZLIB) +endif() target_include_directories(zip PUBLIC $ diff --git a/core/deps/xbyak/CMakeLists.txt b/core/deps/xbyak/CMakeLists.txt index f2c54f141..1747fd3ce 100644 --- a/core/deps/xbyak/CMakeLists.txt +++ b/core/deps/xbyak/CMakeLists.txt @@ -1,44 +1,40 @@ -cmake_minimum_required(VERSION 2.6...3.0.2) +cmake_minimum_required(VERSION 3.5...4.0.0) project(xbyak CXX) file(GLOB headers xbyak/*.h) -if (DEFINED CMAKE_VERSION AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.2) - include(GNUInstallDirs) - add_library(${PROJECT_NAME} INTERFACE) - add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - - target_include_directories( - ${PROJECT_NAME} INTERFACE - "$" - "$" - ) +include(GNUInstallDirs) +add_library(${PROJECT_NAME} INTERFACE) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - install( - TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}-targets - ) +target_include_directories( + ${PROJECT_NAME} INTERFACE + "$" + "$" +) - configure_file( - cmake/config.cmake.in - ${PROJECT_NAME}Config.cmake - @ONLY - ) +install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets +) - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - ) +configure_file( + cmake/config.cmake.in + ${PROJECT_NAME}Config.cmake + @ONLY +) - install( - EXPORT ${PROJECT_NAME}-targets - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - ) -elseif(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR) - set(CMAKE_INSTALL_INCLUDEDIR "include") -endif() +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +install( + EXPORT ${PROJECT_NAME}-targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) install( FILES ${headers} diff --git a/core/network/dcnet.cpp b/core/network/dcnet.cpp index 6630121d8..9922393d1 100644 --- a/core/network/dcnet.cpp +++ b/core/network/dcnet.cpp @@ -425,7 +425,7 @@ private: return; } const uint8_t *p = &recvbuf[5]; - while (p - &recvbuf[0] < (ssize_t)len) + while (p - &recvbuf[0] < (int)len) { accessPoints.emplace_back(); uint32_t addr;