1868e25b9SDmitri Tikhonov# The following variable can be defined on the command line:
2868e25b9SDmitri Tikhonov#
3868e25b9SDmitri Tikhonov#   SHARED
4868e25b9SDmitri Tikhonov#   NDEBUG
5868e25b9SDmitri Tikhonov#   XXH_HEADER_NAME
6868e25b9SDmitri Tikhonov#   XXH_INCLUDE_DIR
7b2990426SAlex Pokotilo#   LSHPACK_XXH
8868e25b9SDmitri Tikhonov
9868e25b9SDmitri TikhonovCMAKE_MINIMUM_REQUIRED(VERSION 2.8)
10a8733eb5SDmitri TikhonovPROJECT(ls-hpack C)
11868e25b9SDmitri Tikhonov
12868e25b9SDmitri TikhonovIF (SHARED EQUAL 1)
1321fcb356SDmitri Tikhonov    ADD_LIBRARY(ls-hpack SHARED lshpack.c)
14868e25b9SDmitri TikhonovELSE()
1521fcb356SDmitri Tikhonov    ADD_LIBRARY(ls-hpack STATIC lshpack.c)
16868e25b9SDmitri TikhonovENDIF()
1721fcb356SDmitri TikhonovINCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
18868e25b9SDmitri Tikhonov
19868e25b9SDmitri TikhonovIF (NOT DEFINED XXH_HEADER_NAME)
20868e25b9SDmitri Tikhonov    SET(XXH_HEADER_NAME "xxhash.h")
21868e25b9SDmitri TikhonovENDIF()
22868e25b9SDmitri Tikhonov
23868e25b9SDmitri TikhonovIF (DEFINED XXH_INCLUDE_DIR)
24868e25b9SDmitri Tikhonov    INCLUDE_DIRECTORIES("${XXH_INCLUDE_DIR}")
25868e25b9SDmitri TikhonovELSE()
26868e25b9SDmitri Tikhonov    INCLUDE_DIRECTORIES(deps/xxhash)
27868e25b9SDmitri TikhonovENDIF()
28868e25b9SDmitri Tikhonov
29b2990426SAlex PokotiloIF (LSHPACK_XXH)
30b2990426SAlex Pokotilo    TARGET_SOURCES(ls-hpack PRIVATE deps/xxhash/xxhash.c)
31b2990426SAlex PokotiloENDIF()
32b2990426SAlex Pokotilo
3375ce1599SDmitri TikhonovIF (MSVC)
3475ce1599SDmitri Tikhonov    INCLUDE_DIRECTORIES(wincompat)
3575ce1599SDmitri TikhonovENDIF()
3675ce1599SDmitri Tikhonov
37a8733eb5SDmitri TikhonovIF (CMAKE_C_COMPILER_ID STREQUAL GNU
38a8733eb5SDmitri Tikhonov	OR CMAKE_C_COMPILER_ID STREQUAL Clang)
3975ce1599SDmitri Tikhonov	SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
4075ce1599SDmitri Tikhonov	SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
41e06228c4SDmitri Tikhonov        INCLUDE(CheckCCompilerFlag)
42e06228c4SDmitri Tikhonov        CHECK_C_COMPILER_FLAG(-Wno-implicit-fallthrough HAS_NO_IMPLICIT_FALLTHROUGH)
43e06228c4SDmitri Tikhonov        IF (HAS_NO_IMPLICIT_FALLTHROUGH)
44e06228c4SDmitri Tikhonov            SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-implicit-fallthrough")
45e06228c4SDmitri Tikhonov        ENDIF()
46a8733eb5SDmitri Tikhonov        IF (PROFILE EQUAL 1)
47a8733eb5SDmitri Tikhonov            SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
48a8733eb5SDmitri Tikhonov        ENDIF()
496019d837SDmitri Tikhonov        IF (CMAKE_BUILD_TYPE STREQUAL Release)
506019d837SDmitri Tikhonov            SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g0 -O3")
516019d837SDmitri Tikhonov        ELSE()
52c82c5dbeSAlex Pokotilo            SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g3 -O0 -fsanitize=address")
536019d837SDmitri Tikhonov        ENDIF()
5475ce1599SDmitri TikhonovENDIF()
5575ce1599SDmitri Tikhonov
56e6ab0506SDmitri TikhonovIF (NOT CMAKE_BUILD_TYPE STREQUAL Release)
5775ce1599SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLS_HPACK_EMIT_TEST_CODE=1")
58868e25b9SDmitri TikhonovENDIF()
59868e25b9SDmitri Tikhonov
602219c75eSDmitri TikhonovIF (CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
612219c75eSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLS_HPACK_USE_LARGE_TABLES=0")
622219c75eSDmitri TikhonovENDIF()
632219c75eSDmitri Tikhonov
64868e25b9SDmitri TikhonovIF (NDEBUG EQUAL 1)
65868e25b9SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
66868e25b9SDmitri TikhonovENDIF()
67868e25b9SDmitri Tikhonov
68868e25b9SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DXXH_HEADER_NAME=\\\"${XXH_HEADER_NAME}\\\"")
69868e25b9SDmitri Tikhonov
70a8733eb5SDmitri TikhonovSET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
71868e25b9SDmitri Tikhonov
72868e25b9SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
73acf4ec1bSDmitri Tikhonov
74e6ab0506SDmitri TikhonovIF (NOT CMAKE_BUILD_TYPE STREQUAL Release)
75acf4ec1bSDmitri Tikhonov    ENABLE_TESTING()
76acf4ec1bSDmitri Tikhonov    INCLUDE_DIRECTORIES("test")
77acf4ec1bSDmitri Tikhonov    ADD_SUBDIRECTORY("test")
78acf4ec1bSDmitri TikhonovENDIF()
79e1657cf2SDmitri Tikhonov
80e1657cf2SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL Linux)
81e1657cf2SDmitri Tikhonov    ADD_SUBDIRECTORY(bin)
82e1657cf2SDmitri TikhonovENDIF()
83