Skip to content

Commit fe77c94

Browse files
authored
CMake: Use cmake for xxhash, fix export (litespeedtech#70)
* CMake: Prefer xxHash CMake, fix exported config * CI: Test both CMake and pkgconfig
1 parent 273195e commit fe77c94

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

.appveyor.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ environment:
99
matrix:
1010
- job_name: "Internal xxhash"
1111
LSQPACK_XXH: ON
12-
- job_name: "External xxhash"
12+
XXH_CMAKE: UNUSED
13+
- job_name: "External xxhash (CMake)"
1314
LSQPACK_XXH: OFF
15+
XXH_CMAKE: REQUIRE
16+
- job_name: "External xxhash (pkgconfig)"
17+
LSQPACK_XXH: OFF
18+
XXH_CMAKE: DISABLE
1419

1520
before_build:
1621
- git -C c:\tools\vcpkg\ fetch
@@ -26,6 +31,7 @@ before_build:
2631
-DCMAKE_GENERATOR_PLATFORM=x64
2732
-DLSQPACK_TESTS=ON
2833
-DLSQPACK_XXH=%LSQPACK_XXH%
34+
-DCMAKE_%XXH_CMAKE%_FIND_PACKAGE_xxHash=ON
2935
-DGETOPT_INCLUDE_DIR=c:/tools/vcpkg/installed/x64-windows/include
3036
-DGETOPT_LIB=c:/tools/vcpkg/installed/x64-windows/lib/getopt.lib
3137

CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ if(LSQPACK_XXH)
3737
target_sources(ls-qpack PRIVATE deps/xxhash/xxhash.c)
3838
set(LSQPACK_DEPENDS "")
3939
else()
40-
find_package(PkgConfig REQUIRED)
41-
pkg_check_modules(XXH REQUIRED IMPORTED_TARGET libxxhash)
42-
target_link_libraries(ls-qpack PUBLIC PkgConfig::XXH)
43-
set(LSQPACK_DEPENDS "libxxhash")
40+
find_package(xxHash CONFIG)
41+
if(NOT xxHash_FOUND)
42+
find_package(PkgConfig REQUIRED)
43+
pkg_check_modules(LS_QPACK_XXH REQUIRED IMPORTED_TARGET libxxhash GLOBAL)
44+
add_library(xxHash::xxhash ALIAS PkgConfig::LS_QPACK_XXH)
45+
endif()
46+
target_link_libraries(ls-qpack PRIVATE xxHash::xxhash)
47+
set(LSQPACK_DEPENDS "libxxhash")
4448
endif()
4549

4650
if(WIN32 OR EMSCRIPTEN)
@@ -128,10 +132,14 @@ configure_file(lsqpack.pc.in lsqpack.pc @ONLY)
128132
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lsqpack.pc"
129133
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
130134

135+
configure_file(ls-qpack-config.cmake.in ls-qpack-config.cmake @ONLY)
131136
install(TARGETS ls-qpack EXPORT ls-qpack-config
132137
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
138+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ls-qpack-config.cmake"
139+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ls-qpack)
133140
install(
134141
EXPORT ls-qpack-config
142+
FILE ls-qpack-targets.cmake
135143
NAMESPACE ls-qpack::
136144
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ls-qpack
137145
)

bin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function(lsqpack_add_executable TARGET)
77
target_include_directories(${TARGET} PRIVATE ../deps/xxhash)
88
else()
99
target_sources(${TARGET} PRIVATE ${TARGET}.c)
10-
target_link_libraries(${TARGET} PUBLIC PkgConfig::XXH)
10+
target_link_libraries(${TARGET} PUBLIC xxHash::xxhash)
1111
endif()
1212

1313
if(WIN32)

ls-qpack-config.cmake.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if(NOT "@BUILD_SHARED_LIBS@" AND NOT "@LSQPACK_XXH@")
2+
include(CMakeFindDependencyMacro)
3+
if("@xxHash_FOUND@")
4+
find_dependency(xxHash CONFIG)
5+
else()
6+
find_dependency(PkgConfig)
7+
pkg_check_modules(XXH REQUIRED IMPORTED_TARGET libxxhash)
8+
endif()
9+
endif()
10+
include("${CMAKE_CURRENT_LIST_DIR}/ls-qpack-targets.cmake")

test/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
function(lsqpack_add_test TARGET)
22
add_executable(test_${TARGET} "")
33
target_sources(test_${TARGET} PRIVATE test_${TARGET}.c)
4-
if(LSQPACK_XXH)
5-
target_link_libraries(test_${TARGET} ls-qpack)
6-
else()
7-
target_link_libraries(test_${TARGET} ls-qpack PkgConfig::XXH)
8-
endif()
4+
target_link_libraries(test_${TARGET} ls-qpack)
95

106
if(WIN32)
117
target_include_directories(test_${TARGET} PRIVATE ../wincompat)

0 commit comments

Comments
 (0)