Skip to content

Commit c1d8ef5

Browse files
committed
[cmake] Use a Find module for xxhash
Port of FEX-Emu#5159 Find modules are preferred for pkgconfig/otherwise non-CMake libraries. Let's use that here for xxHash. Signed-off-by: crueter <[email protected]>
1 parent 0edf961 commit c1d8ef5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ set(CMAKE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_LINKER_FLAGS_RELWITHDEBINFO} -fno
303303
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer")
304304
set(CMAKE_LINKER_FLAGS_RELEASE "${CMAKE_LINKER_FLAGS_RELEASE} -fomit-frame-pointer")
305305

306+
## Modules ##
307+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules/)
308+
306309
include_directories(External/robin-map/include/)
307310

308311
include(CTest)
@@ -325,10 +328,8 @@ find_package(Python 3.9 REQUIRED COMPONENTS Interpreter)
325328

326329
set(BUILD_SHARED_LIBS OFF)
327330

328-
pkg_search_module(xxhash IMPORTED_TARGET xxhash libxxhash)
329-
if (TARGET PkgConfig::xxhash AND NOT CMAKE_CROSSCOMPILING)
330-
add_library(xxHash::xxhash ALIAS PkgConfig::xxhash)
331-
else()
331+
find_package(xxhash MODULE QUIET)
332+
if (NOT TARGET xxHash::xxhash)
332333
set(XXHASH_BUNDLED_MODE TRUE)
333334
set(XXHASH_BUILD_XXHSUM FALSE)
334335
add_subdirectory(External/xxhash/cmake_unofficial/)

CMakeModules/Findxxhash.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
include(FindPackageHandleStandardArgs)
4+
5+
find_package(PkgConfig QUIET)
6+
pkg_search_module(xxhash QUIET IMPORTED_TARGET xxhash libxxhash)
7+
find_package_handle_standard_args(xxhash
8+
REQUIRED_VARS xxhash_LINK_LIBRARIES
9+
VERSION_VAR xxhash_VERSION
10+
)
11+
12+
if (xxhash_FOUND AND NOT TARGET xxHash::xxhash)
13+
if (TARGET xxhash)
14+
add_library(xxHash::xxhash ALIAS xxhash)
15+
else()
16+
add_library(xxHash::xxhash ALIAS PkgConfig::xxhash)
17+
endif()
18+
endif()

0 commit comments

Comments
 (0)