From c76b7bfe8d6753d548f2b4390a8f31c089aa3856 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 6 Sep 2024 09:32:23 +0200 Subject: [PATCH 1/3] CMake: Compile with system libraries for xxhash, Catch2, and fmt, if available --- CMakeLists.txt | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e400f66382..3d516c631d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,25 +284,38 @@ endif() find_package(PkgConfig REQUIRED) find_package(Python 3.0 REQUIRED COMPONENTS Interpreter) -set(XXHASH_BUNDLED_MODE TRUE) -set(XXHASH_BUILD_XXHSUM FALSE) set(BUILD_SHARED_LIBS OFF) -add_subdirectory(External/xxhash/cmake_unofficial/) + +pkg_search_module(xxhash IMPORTED_TARGET xxhash libxxhash) +if (TARGET PkgConfig::xxhash) + add_library(xxHash::xxhash ALIAS PkgConfig::xxhash) +else() + set(XXHASH_BUNDLED_MODE TRUE) + set(XXHASH_BUILD_XXHSUM FALSE) + add_subdirectory(External/xxhash/cmake_unofficial/) +endif() add_definitions(-Wno-trigraphs) add_definitions(-DGLOBAL_DATA_DIRECTORY="${DATA_DIRECTORY}/") if (BUILD_TESTS) - add_subdirectory(External/Catch2/) + find_package(Catch2 QUIET) + if (NOT Catch2_FOUND) + add_subdirectory(External/Catch2/) + + # Pull in catch_discover_tests definition + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/External/Catch2/contrib/") + endif() - # Pull in catch_discover_tests definition - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/External/Catch2/contrib/") include(Catch) endif() -# Disable fmt install -set(FMT_INSTALL OFF) -add_subdirectory(External/fmt/) +find_package(fmt QUIET) +if (NOT fmt_FOUND) + # Disable fmt install + set(FMT_INSTALL OFF) + add_subdirectory(External/fmt/) +endif() if (USE_FEXCONFIG_TOOLKIT STREQUAL "imgui") add_subdirectory(External/imgui/) From 355c3428c0f13b3c7d49f7c2ebcb01385e6bd4e3 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 6 Sep 2024 10:17:01 +0200 Subject: [PATCH 2/3] CMake: Don't use system libraries when compiling with mingw --- toolchain_mingw.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/toolchain_mingw.cmake b/toolchain_mingw.cmake index be36119501..8cdb8cb957 100644 --- a/toolchain_mingw.cmake +++ b/toolchain_mingw.cmake @@ -15,3 +15,5 @@ set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE) set(CMAKE_STANDARD_LIBRARIES "" CACHE STRING "" FORCE) set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR ${MINGW_TRIPLE}) + +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) From ab5d3ab22be87aa280e5af1e5618966be51f4086 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 6 Sep 2024 10:22:33 +0200 Subject: [PATCH 3/3] CMake: Don't use pkgconfig when cross-compiling --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d516c631d..bff21d4507 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,7 +287,7 @@ find_package(Python 3.0 REQUIRED COMPONENTS Interpreter) set(BUILD_SHARED_LIBS OFF) pkg_search_module(xxhash IMPORTED_TARGET xxhash libxxhash) -if (TARGET PkgConfig::xxhash) +if (TARGET PkgConfig::xxhash AND NOT CMAKE_CROSSCOMPILING) add_library(xxHash::xxhash ALIAS PkgConfig::xxhash) else() set(XXHASH_BUNDLED_MODE TRUE)