143a63c18SDmitri Tikhonov# The following variable can be defined on the command line: 243a63c18SDmitri Tikhonov# 33674d7b4SDaan De Meyer# BUILD_SHARED_LIBS 43674d7b4SDaan De Meyer# 53674d7b4SDaan De Meyer# The following environment variables will be taken into account when running 63674d7b4SDaan De Meyer# cmake for the first time: 73674d7b4SDaan De Meyer# 83674d7b4SDaan De Meyer# CFLAGS 93674d7b4SDaan De Meyer# LDFLAGS 103674d7b4SDaan De Meyer 113674d7b4SDaan De Meyercmake_minimum_required(VERSION 3.1) 123674d7b4SDaan De Meyerproject(ls-qpack LANGUAGES C) 133674d7b4SDaan De Meyer 143674d7b4SDaan De Meyeroption(LSQPACK_TESTS "Build tests") 15d99dd855SDmitri Tikhonovoption(LSQPACK_BIN "Build binaries" ON) 16d99dd855SDmitri Tikhonovoption(LSQPACK_XXH "Include XXH" ON) 173674d7b4SDaan De Meyer 183674d7b4SDaan De Meyer# Use `cmake -DBUILD_SHARED_LIBS=OFF` to build a static library. 193674d7b4SDaan De Meyeradd_library(ls-qpack "") 200cdf1faaSDmitri Tikhonovtarget_include_directories(ls-qpack PUBLIC .) 210cdf1faaSDmitri Tikhonovtarget_sources(ls-qpack PRIVATE lsqpack.c) 223674d7b4SDaan De Meyer 233674d7b4SDaan De Meyertarget_include_directories(ls-qpack PRIVATE deps/xxhash/) 24d99dd855SDmitri Tikhonovif(LSQPACK_XXH) 25d99dd855SDmitri Tikhonov target_sources(ls-qpack PRIVATE deps/xxhash/xxhash.c) 26d99dd855SDmitri Tikhonovendif() 273674d7b4SDaan De Meyer 283674d7b4SDaan De Meyerif(MSVC) 299f5a9b88SDaan De Meyer target_include_directories(ls-qpack PUBLIC wincompat) 303674d7b4SDaan De Meyerendif() 313674d7b4SDaan De Meyer 323674d7b4SDaan De Meyerif(MSVC) 333674d7b4SDaan De Meyer target_compile_options(ls-qpack PRIVATE 343674d7b4SDaan De Meyer /Wall 353674d7b4SDaan De Meyer /wd4100 # unreffed parameter 363674d7b4SDaan De Meyer /wd4200 # zero-sized array 373674d7b4SDaan De Meyer # Apparently this C99 construct is not supported properly by VS: 383674d7b4SDaan De Meyer # https://stackoverflow.com/questions/1064930/struct-initializer-typedef-with-visual-studio 393674d7b4SDaan De Meyer /wd4204 # non-constant aggregate initializer 403674d7b4SDaan De Meyer /wd4255 # no function prototype (getopt) 413674d7b4SDaan De Meyer /wd4820 # padding 423674d7b4SDaan De Meyer /wd4668 # undefined macro 433674d7b4SDaan De Meyer /wd4710 # not inlined by default 443674d7b4SDaan De Meyer /wd4996 # unsafe function 453674d7b4SDaan De Meyer ) 463674d7b4SDaan De Meyerelse() 473674d7b4SDaan De Meyer target_compile_options(ls-qpack PRIVATE 483674d7b4SDaan De Meyer -Wall 493674d7b4SDaan De Meyer -Wextra 503674d7b4SDaan De Meyer -Wno-unused-parameter 513674d7b4SDaan De Meyer -fno-omit-frame-pointer 523674d7b4SDaan De Meyer ) 533674d7b4SDaan De Meyerendif() 543674d7b4SDaan De Meyer 55948d3c75STyler YoungIF (CMAKE_SYSTEM_NAME STREQUAL Windows) 56520d30ddSNick Banks IF (LSQPACK_TESTS OR LSQPACK_BIN) 57520d30ddSNick Banks FIND_PATH(GETOPT_INCLUDE_DIR NAMES getopt.h) 58520d30ddSNick Banks IF (GETOPT_INCLUDE_DIR) 59520d30ddSNick Banks INCLUDE_DIRECTORIES(${GETOPT_INCLUDE_DIR}) 60520d30ddSNick Banks ELSE() 61520d30ddSNick Banks MESSAGE(FATAL_ERROR "getopt.h was not found") 62520d30ddSNick Banks ENDIF() 63520d30ddSNick Banks FIND_LIBRARY(GETOPT_LIB getopt) 64520d30ddSNick Banks IF(GETOPT_LIB) 65520d30ddSNick Banks MESSAGE(STATUS "Found getopt: ${GETOPT_LIB}") 66520d30ddSNick Banks ELSE() 67520d30ddSNick Banks MESSAGE(STATUS "getopt not found") 68520d30ddSNick Banks ENDIF() 69948d3c75STyler Young ENDIF() 70948d3c75STyler YoungENDIF() 71948d3c75STyler Young 7260620859SDmitri TikhonovIF(DEFINED LSXPACK_MAX_STRLEN) 7360620859SDmitri Tikhonov SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLSXPACK_MAX_STRLEN=${LSXPACK_MAX_STRLEN}") 7460620859SDmitri TikhonovENDIF() 7560620859SDmitri Tikhonov 76467c7b1eSDmitri TikhonovIF (CMAKE_BUILD_TYPE STREQUAL MinSizeRel) 7760620859SDmitri Tikhonov SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLS_QPACK_USE_LARGE_TABLES=0") 7860620859SDmitri TikhonovENDIF() 7960620859SDmitri Tikhonov 8060620859SDmitri TikhonovIF(LSQPACK_TESTS) 8160620859SDmitri Tikhonov SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLSQPACK_DEVEL_MODE=1") 82467c7b1eSDmitri TikhonovENDIF() 83467c7b1eSDmitri Tikhonov 8460620859SDmitri TikhonovINCLUDE(CheckCCompilerFlag) 8560620859SDmitri TikhonovCHECK_C_COMPILER_FLAG(-Wno-implicit-fallthrough HAS_NO_IMPLICIT_FALLTHROUGH) 8660620859SDmitri TikhonovIF (HAS_NO_IMPLICIT_FALLTHROUGH) 8760620859SDmitri Tikhonov SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-implicit-fallthrough") 8860620859SDmitri TikhonovENDIF() 8960620859SDmitri Tikhonov 9060620859SDmitri TikhonovSET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{EXTRA_CFLAGS}") 9160620859SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 9260620859SDmitri Tikhonov 933674d7b4SDaan De Meyerif(LSQPACK_TESTS) 943674d7b4SDaan De Meyer enable_testing() 953674d7b4SDaan De Meyer add_subdirectory(test) 963674d7b4SDaan De Meyerendif() 973674d7b4SDaan De Meyer 98d99dd855SDmitri Tikhonovif(LSQPACK_BIN) 99d99dd855SDmitri Tikhonov add_subdirectory(bin) 100d99dd855SDmitri Tikhonovendif() 101