1# The following variable can be defined on the command line: 2# 3# SHARED 4# NDEBUG 5# XXH_HEADER_NAME 6# XXH_INCLUDE_DIR 7# LSHPACK_XXH 8 9CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 10PROJECT(ls-hpack C) 11 12IF (SHARED EQUAL 1) 13 ADD_LIBRARY(ls-hpack SHARED lshpack.c) 14ELSE() 15 ADD_LIBRARY(ls-hpack STATIC lshpack.c) 16ENDIF() 17INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) 18 19IF (NOT DEFINED XXH_HEADER_NAME) 20 SET(XXH_HEADER_NAME "xxhash.h") 21ENDIF() 22 23IF (DEFINED XXH_INCLUDE_DIR) 24 INCLUDE_DIRECTORIES("${XXH_INCLUDE_DIR}") 25ELSE() 26 INCLUDE_DIRECTORIES(deps/xxhash) 27ENDIF() 28 29IF (LSHPACK_XXH) 30 TARGET_SOURCES(ls-hpack PRIVATE deps/xxhash/xxhash.c) 31ENDIF() 32 33IF (MSVC) 34 INCLUDE_DIRECTORIES(wincompat) 35ENDIF() 36 37IF (CMAKE_C_COMPILER_ID STREQUAL GNU 38 OR CMAKE_C_COMPILER_ID STREQUAL Clang) 39 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 40 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 41 INCLUDE(CheckCCompilerFlag) 42 CHECK_C_COMPILER_FLAG(-Wno-implicit-fallthrough HAS_NO_IMPLICIT_FALLTHROUGH) 43 IF (HAS_NO_IMPLICIT_FALLTHROUGH) 44 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-implicit-fallthrough") 45 ENDIF() 46 IF (PROFILE EQUAL 1) 47 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 48 ENDIF() 49 IF (CMAKE_BUILD_TYPE STREQUAL Release) 50 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g0 -O3") 51 ELSE() 52 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g3 -O0 -fsanitize=address") 53 ENDIF() 54ENDIF() 55 56IF (NOT CMAKE_BUILD_TYPE STREQUAL Release) 57 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLS_HPACK_EMIT_TEST_CODE=1") 58ENDIF() 59 60IF (CMAKE_BUILD_TYPE STREQUAL MinSizeRel) 61 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLS_HPACK_USE_LARGE_TABLES=0") 62ENDIF() 63 64IF (NDEBUG EQUAL 1) 65 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 66ENDIF() 67 68SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DXXH_HEADER_NAME=\\\"${XXH_HEADER_NAME}\\\"") 69 70SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 71 72MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 73 74IF (NOT CMAKE_BUILD_TYPE STREQUAL Release) 75 ENABLE_TESTING() 76 INCLUDE_DIRECTORIES("test") 77 ADD_SUBDIRECTORY("test") 78ENDIF() 79 80IF (CMAKE_SYSTEM_NAME STREQUAL Linux) 81 ADD_SUBDIRECTORY(bin) 82ENDIF() 83