-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.txt
160 lines (142 loc) · 4.96 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# The following variable can be defined on the command line:
#
# BUILD_SHARED_LIBS
#
# The following environment variables will be taken into account when running
# cmake for the first time:
#
# CFLAGS
# LDFLAGS
cmake_minimum_required(VERSION 3.1)
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 "")
add_library(ls-qpack::ls-qpack ALIAS ls-qpack)
set_target_properties(ls-qpack PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
target_include_directories(ls-qpack PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_sources(ls-qpack PRIVATE lsqpack.c)
if(LSQPACK_XXH)
target_include_directories(ls-qpack PRIVATE deps/xxhash/)
target_sources(ls-qpack PRIVATE deps/xxhash/xxhash.c)
set(LSQPACK_DEPENDS "")
else()
find_package(xxHash CONFIG)
if(NOT xxHash_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LS_QPACK_XXH REQUIRED IMPORTED_TARGET libxxhash GLOBAL)
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 OR EMSCRIPTEN)
target_include_directories(ls-qpack PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/wincompat>
$<INSTALL_INTERFACE:include>
)
endif()
if(MSVC)
target_compile_options(ls-qpack PRIVATE
/Wall
/wd4100 # unreffed parameter
/wd4200 # zero-sized array
# Apparently this C99 construct is not supported properly by VS:
# https://stackoverflow.com/questions/1064930/struct-initializer-typedef-with-visual-studio
/wd4204 # non-constant aggregate initializer
/wd4255 # no function prototype (getopt)
/wd4334 # result of 32-bit shift implicitly converted to 64 bits
/wd4820 # padding
/wd4668 # undefined macro
/wd4710 # not inlined by default
/wd4996 # unsafe function
/wd4061 # enum is not explicitly handled by a case
/wd5045 # Compiler will insert Spectre mitigation for memory load
)
else()
target_compile_options(ls-qpack PRIVATE
-Wall
-Wextra
-Wno-unused-parameter
-fno-omit-frame-pointer
)
endif()
IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
IF (LSQPACK_TESTS OR LSQPACK_BIN)
FIND_PATH(GETOPT_INCLUDE_DIR NAMES getopt.h)
IF (GETOPT_INCLUDE_DIR)
INCLUDE_DIRECTORIES(${GETOPT_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "getopt.h was not found")
ENDIF()
FIND_LIBRARY(GETOPT_LIB getopt)
IF(GETOPT_LIB)
MESSAGE(STATUS "Found getopt: ${GETOPT_LIB}")
ELSE()
MESSAGE(STATUS "getopt not found")
ENDIF()
ENDIF()
ENDIF()
IF(DEFINED LSXPACK_MAX_STRLEN)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLSXPACK_MAX_STRLEN=${LSXPACK_MAX_STRLEN}")
ENDIF()
IF (CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLS_QPACK_USE_LARGE_TABLES=0")
ENDIF()
IF(LSQPACK_TESTS)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLSQPACK_DEVEL_MODE=1")
ENDIF()
INCLUDE(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG(-Wno-implicit-fallthrough HAS_NO_IMPLICIT_FALLTHROUGH)
IF (HAS_NO_IMPLICIT_FALLTHROUGH)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-implicit-fallthrough")
ENDIF()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{EXTRA_CFLAGS}")
MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
if(LSQPACK_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(LSQPACK_BIN)
add_subdirectory(bin)
endif()
include(GNUInstallDirs)
configure_file(lsqpack.pc.in lsqpack.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lsqpack.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
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
)
install(FILES lsqpack.h lsxpack_header.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(LSQPACK_BIN)
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})
endif()
if(WIN32 OR EMSCRIPTEN)
install(DIRECTORY wincompat/sys DESTINATION include)
endif()