Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Use cmake for xxhash, fix export #70

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ environment:
matrix:
- job_name: "Internal xxhash"
LSQPACK_XXH: ON
- job_name: "External xxhash"
XXH_CMAKE: UNUSED
- job_name: "External xxhash (CMake)"
LSQPACK_XXH: OFF
XXH_CMAKE: REQUIRE
- job_name: "External xxhash (pkgconfig)"
LSQPACK_XXH: OFF
XXH_CMAKE: DISABLE

before_build:
- git -C c:\tools\vcpkg\ fetch
Expand All @@ -26,6 +31,7 @@ before_build:
-DCMAKE_GENERATOR_PLATFORM=x64
-DLSQPACK_TESTS=ON
-DLSQPACK_XXH=%LSQPACK_XXH%
-DCMAKE_%XXH_CMAKE%_FIND_PACKAGE_xxHash=ON
-DGETOPT_INCLUDE_DIR=c:/tools/vcpkg/installed/x64-windows/include
-DGETOPT_LIB=c:/tools/vcpkg/installed/x64-windows/lib/getopt.lib

Expand Down
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ if(LSQPACK_XXH)
target_sources(ls-qpack PRIVATE deps/xxhash/xxhash.c)
set(LSQPACK_DEPENDS "")
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(XXH REQUIRED IMPORTED_TARGET libxxhash)
target_link_libraries(ls-qpack PUBLIC PkgConfig::XXH)
set(LSQPACK_DEPENDS "libxxhash")
find_package(xxHash CONFIG)
if(NOT xxHash_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LS_QPACK_XXH REQUIRED IMPORTED_TARGET libxxhash GLOBAL)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the LS_QPACK_ prefix here because of the side effects of GLOBAL when ls-qpack is used as a subproject.

add_library(xxHash::xxhash ALIAS PkgConfig::LS_QPACK_XXH)
endif()
target_link_libraries(ls-qpack PRIVATE xxHash::xxhash)
set(LSQPACK_DEPENDS "libxxhash")
endif()

if(WIN32)
Expand Down Expand Up @@ -125,10 +129,14 @@ endif()
include(GNUInstallDirs)
configure_file(lsqpack.pc.in lsqpack.pc @ONLY)

configure_file(ls-qpack-config.cmake.in ls-qpack-config.cmake @ONLY)
install(TARGETS ls-qpack EXPORT ls-qpack-config
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ls-qpack-config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ls-qpack)
install(
EXPORT ls-qpack-config
FILE ls-qpack-targets.cmake
NAMESPACE ls-qpack::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ls-qpack
)
Expand Down
2 changes: 1 addition & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function(lsqpack_add_executable TARGET)
target_include_directories(${TARGET} PRIVATE ../deps/xxhash)
else()
target_sources(${TARGET} PRIVATE ${TARGET}.c)
target_link_libraries(${TARGET} PUBLIC PkgConfig::XXH)
target_link_libraries(${TARGET} PUBLIC xxHash::xxhash)
endif()

if(WIN32)
Expand Down
10 changes: 10 additions & 0 deletions ls-qpack-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(NOT "@BUILD_SHARED_LIBS@" AND NOT "@LSQPACK_XXH@")
include(CMakeFindDependencyMacro)
if("@xxHash_FOUND@")
find_dependency(xxHash CONFIG)
else()
find_dependency(PkgConfig)
pkg_check_modules(XXH REQUIRED IMPORTED_TARGET libxxhash)
endif()
endif()
include("${CMAKE_CURRENT_LIST_DIR}/ls-qpack-targets.cmake")
6 changes: 1 addition & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
function(lsqpack_add_test TARGET)
add_executable(test_${TARGET} "")
target_sources(test_${TARGET} PRIVATE test_${TARGET}.c)
if(LSQPACK_XXH)
target_link_libraries(test_${TARGET} ls-qpack)
else()
target_link_libraries(test_${TARGET} ls-qpack PkgConfig::XXH)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This usage requirement is handled by CMake when linking ls-qpack.

endif()
target_link_libraries(test_${TARGET} ls-qpack)

if(WIN32)
target_include_directories(test_${TARGET} PRIVATE ../wincompat)
Expand Down