Skip to content

Commit

Permalink
Enable use of external libxxhash (#55)
Browse files Browse the repository at this point in the history
Also add soname to shared library
Add pkgconfig file for non Windows builds

Co-authored-by: LiteSpeed Tech <[email protected]>
  • Loading branch information
bkmgit and litespeedtech authored Aug 6, 2024
1 parent b37001b commit 4677c98
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cache:
before_build:
- vcpkg install getopt:x64-windows
- vcpkg integrate install
- cmake -DLSQPACK_TESTS=ON -DCMAKE_GENERATOR_PLATFORM=x64 -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CONFIGURATION_TYPES=Debug -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DGETOPT_INCLUDE_DIR=c:/tools/vcpkg/installed/x64-windows/include -DGETOPT_LIB=c:/tools/vcpkg/installed/x64-windows/lib/getopt.lib .
- cmake -DLSQPACK_TESTS=ON -DLSQPACK_XXH=ON -DCMAKE_GENERATOR_PLATFORM=x64 -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CONFIGURATION_TYPES=Debug -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DGETOPT_INCLUDE_DIR=c:/tools/vcpkg/installed/x64-windows/include -DGETOPT_LIB=c:/tools/vcpkg/installed/x64-windows/lib/getopt.lib .

build_script:
- cmake --build .
Expand Down
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ freebsd_instance:
image: freebsd-13-3-release-amd64

task:
install_script: pkg install -y cmake bash perl5
script: cmake -DLSQPACK_TESTS=ON . && make && make test
install_script: pkg install -y cmake bash perl5 p5-PkgConfig-LibPkgConf devel/xxhash
script: cmake -DLSQPACK_TESTS=ON -DLSQPACK_XXH=OFF . && make && make test
39 changes: 34 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,34 @@
# LDFLAGS

cmake_minimum_required(VERSION 3.1)
project(ls-qpack LANGUAGES C)
project(ls-qpack
LANGUAGES C
HOMEPAGE_URL "https://github.com/litespeedtech/ls-qpack"
DESCRIPTION "QPACK compression library for use with HTTP/3"
VERSION 2.5.3)

option(LSQPACK_TESTS "Build tests")
option(LSQPACK_BIN "Build binaries" ON)
option(LSQPACK_XXH "Include XXH" ON)
option(BUILD_SHARED_LIBS OFF)

# Use `cmake -DBUILD_SHARED_LIBS=OFF` to build a static library.
add_library(ls-qpack "")
set_target_properties(ls-qpack PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
target_include_directories(ls-qpack PUBLIC .)
target_sources(ls-qpack PRIVATE lsqpack.c)

target_include_directories(ls-qpack PRIVATE deps/xxhash/)
if(LSQPACK_XXH)
if(LSQPACK_XXH OR MSVC)
target_include_directories(ls-qpack PRIVATE deps/xxhash/)
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")
endif()

if(WIN32)
Expand Down Expand Up @@ -102,8 +116,23 @@ if(LSQPACK_BIN)
add_subdirectory(bin)
endif()

install(TARGETS ls-qpack)
install(FILES lsqpack.h lsxpack_header.h DESTINATION include)
include(GNUInstallDirs)
configure_file(lsqpack.pc.in lsqpack.pc @ONLY)

install(TARGETS ls-qpack
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES lsqpack.h lsxpack_header.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/bin/encode-int
${CMAKE_CURRENT_BINARY_DIR}/bin/fuzz-decode
${CMAKE_CURRENT_BINARY_DIR}/bin/interop-decode
${CMAKE_CURRENT_BINARY_DIR}/bin/interop-encode
DESTINATION ${CMAKE_INSTALL_BINDIR})

if(WIN32)
install(DIRECTORY wincompat/sys DESTINATION include)
else()
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lsqpack.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
9 changes: 7 additions & 2 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ function(lsqpack_add_executable TARGET)
add_executable(${TARGET} "")
target_link_libraries(${TARGET} PRIVATE ls-qpack)

target_sources(${TARGET} PRIVATE ${TARGET}.c ../deps/xxhash/xxhash.c)
target_include_directories(${TARGET} PRIVATE ../deps/xxhash)
if(LSQPACK_XXH OR MSVC)
target_sources(${TARGET} PRIVATE ${TARGET}.c ../deps/xxhash/xxhash.c)
target_include_directories(${TARGET} PRIVATE ../deps/xxhash)
else()
target_sources(${TARGET} PRIVATE ${TARGET}.c)
target_link_libraries(${TARGET} PUBLIC PkgConfig::XXH)
endif()

if(WIN32)
target_include_directories(${TARGET} PRIVATE ../wincompat)
Expand Down
12 changes: 12 additions & 0 deletions lsqpack.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
libdir="${prefix}/@CMAKE_INSTALL_LIBDIR@"
includedir="${prefix}/@CMAKE_INSTALL_INCLUDEDIR@"

Name: @PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
URL: @CMAKE_PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Requires: @LSQPACK_DEPENDS@
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -llsqpack
8 changes: 6 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
function(lsqpack_add_test TARGET)
add_executable(test_${TARGET} "")
target_sources(test_${TARGET} PRIVATE test_${TARGET}.c)
target_link_libraries(test_${TARGET} ls-qpack)

if(LSQPACK_XXH OR MSVC)
target_link_libraries(test_${TARGET} ls-qpack)
else()
target_link_libraries(test_${TARGET} ls-qpack PkgConfig::XXH)
endif()
if(WIN32)

target_include_directories(test_${TARGET} PRIVATE ../wincompat)
target_link_libraries(test_${TARGET} ${GETOPT_LIB})
else()
Expand Down

0 comments on commit 4677c98

Please sign in to comment.