1# The following variable can be defined on the command line: 2# 3# BUILD_SHARED_LIBS 4# 5# The following environment variables will be taken into account when running 6# cmake for the first time: 7# 8# CFLAGS 9# LDFLAGS 10 11cmake_minimum_required(VERSION 3.1) 12project(ls-qpack LANGUAGES C) 13 14option(LSQPACK_TESTS "Build tests") 15option(LSQPACK_BIN "Build binaries" ON) 16option(LSQPACK_XXH "Include XXH" ON) 17 18# Use `cmake -DBUILD_SHARED_LIBS=OFF` to build a static library. 19add_library(ls-qpack "") 20target_include_directories(ls-qpack PUBLIC .) 21target_sources(ls-qpack PRIVATE lsqpack.c) 22 23target_include_directories(ls-qpack PRIVATE deps/xxhash/) 24if(LSQPACK_XXH) 25 target_sources(ls-qpack PRIVATE deps/xxhash/xxhash.c) 26endif() 27 28if(MSVC) 29 target_include_directories(ls-qpack PUBLIC wincompat) 30endif() 31 32if(MSVC) 33 target_compile_options(ls-qpack PRIVATE 34 /Wall 35 /wd4100 # unreffed parameter 36 /wd4200 # zero-sized array 37 # Apparently this C99 construct is not supported properly by VS: 38 # https://stackoverflow.com/questions/1064930/struct-initializer-typedef-with-visual-studio 39 /wd4204 # non-constant aggregate initializer 40 /wd4255 # no function prototype (getopt) 41 /wd4820 # padding 42 /wd4668 # undefined macro 43 /wd4710 # not inlined by default 44 /wd4996 # unsafe function 45 ) 46else() 47 target_compile_options(ls-qpack PRIVATE 48 -Wall 49 -Wextra 50 -Wno-unused-parameter 51 -fno-omit-frame-pointer 52 ) 53endif() 54 55IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 56 IF (LSQPACK_TESTS OR LSQPACK_BIN) 57 FIND_PATH(GETOPT_INCLUDE_DIR NAMES getopt.h) 58 IF (GETOPT_INCLUDE_DIR) 59 INCLUDE_DIRECTORIES(${GETOPT_INCLUDE_DIR}) 60 ELSE() 61 MESSAGE(FATAL_ERROR "getopt.h was not found") 62 ENDIF() 63 FIND_LIBRARY(GETOPT_LIB getopt) 64 IF(GETOPT_LIB) 65 MESSAGE(STATUS "Found getopt: ${GETOPT_LIB}") 66 ELSE() 67 MESSAGE(STATUS "getopt not found") 68 ENDIF() 69 ENDIF() 70ENDIF() 71 72IF(DEFINED LSXPACK_MAX_STRLEN) 73 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLSXPACK_MAX_STRLEN=${LSXPACK_MAX_STRLEN}") 74ENDIF() 75 76IF (CMAKE_BUILD_TYPE STREQUAL MinSizeRel) 77 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLS_QPACK_USE_LARGE_TABLES=0") 78ENDIF() 79 80IF(LSQPACK_TESTS) 81 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLSQPACK_DEVEL_MODE=1") 82ENDIF() 83 84INCLUDE(CheckCCompilerFlag) 85CHECK_C_COMPILER_FLAG(-Wno-implicit-fallthrough HAS_NO_IMPLICIT_FALLTHROUGH) 86IF (HAS_NO_IMPLICIT_FALLTHROUGH) 87 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-implicit-fallthrough") 88ENDIF() 89 90SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{EXTRA_CFLAGS}") 91MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 92 93if(LSQPACK_TESTS) 94 enable_testing() 95 add_subdirectory(test) 96endif() 97 98if(LSQPACK_BIN) 99 add_subdirectory(bin) 100endif() 101