CMakeLists.txt revision 2d296031
1# Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE.
2cmake_minimum_required(VERSION 2.8)
3
4
5project(lsquic)
6
7IF (NOT MSVC)
8# We prefer clang
9IF(NOT ("${CMAKE_C_COMPILER}" MATCHES "ccc-analyzer" OR
10        "${CMAKE_C_COMPILER}" MATCHES "gcc"          OR
11        "${CMAKE_C_COMPILER}" MATCHES "afl-gcc"))
12    FIND_PROGRAM(CLANG "clang")
13    IF(CLANG)
14        SET(CMAKE_C_COMPILER "${CLANG}")
15    ENDIF()
16ENDIF()
17
18ENDIF()
19
20IF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
21    # If using older glibc, need to link with -lrt.  See clock_getres(2).
22    EXECUTE_PROCESS(
23        COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER}
24        OUTPUT_VARIABLE GLIBC_VERSION)
25    IF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17)
26        SET(LIBS ${LIBS} rt)
27    ENDIF()
28ENDIF()
29
30IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
31    SET(CMAKE_BUILD_TYPE Debug)
32ENDIF()
33
34
35MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
36
37
38IF (NOT MSVC)
39
40SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
41SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
42
43IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
44    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
45ENDIF()
46IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
47    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
48    IF(CMAKE_C_COMPILER MATCHES "clang" AND
49                        NOT "$ENV{TRAVIS}" MATCHES "^true$")
50        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
51    ENDIF()
52    # Uncomment to enable fault injection testing via libfiu:
53    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
54    #SET(LIBS ${LIBS} fiu)
55ELSE()
56    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
57    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
58    # Comment out the following line to compile out debug messages:
59    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
60ENDIF()
61
62IF(LSQUIC_PROFILE EQUAL 1)
63    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
64ENDIF()
65
66IF(LSQUIC_COVERAGE EQUAL 1)
67    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
68ENDIF()
69
70IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
71    MESSAGE(STATUS "AddressSanitizer is ON")
72ELSE()
73    MESSAGE(STATUS "AddressSanitizer is OFF")
74ENDIF()
75
76#MSVC
77ELSE()
78SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4214")	# nonstandard extension used: bit field types other than int
79SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -W4 -WX -Zi -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -I${CMAKE_CURRENT_SOURCE_DIR}/wincompat")
80IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
81    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
82    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
83    #SET(LIBS ${LIBS} fiu)
84ELSE()
85    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
86    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
87    # Comment out the following line to compile out debug messages:
88    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
89ENDIF()
90
91ENDIF() #MSVC
92
93set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
94
95MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
96
97IF(NOT DEFINED BORINGSSL_INCLUDE)
98    SET(BORINGSSL_INCLUDE /usr/local/include)
99ENDIF()
100IF(NOT DEFINED BORINGSSL_LIB)
101    SET(BORINGSSL_LIB /usr/local/lib)
102ENDIF()
103
104
105include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE})
106link_directories( ${BORINGSSL_LIB}  )
107
108SET(CMAKE_INCLUDE_CURRENT_DIR ON)
109include_directories( include src/lshpack)
110IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
111    # Find libevent on FreeBSD:
112    include_directories( /usr/local/include )
113    link_directories( /usr/local/lib )
114ENDIF()
115
116
117IF (NOT MSVC)
118add_executable(http_client
119    test/http_client.c
120    test/prog.c
121    test/test_common.c
122)
123target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
124
125#MSVC
126ELSE()
127add_executable(http_client
128    test/http_client.c
129    test/prog.c
130    test/test_common.c
131    wincompat/getopt.c
132    wincompat/getopt1.c
133)
134
135target_link_libraries(http_client
136        lsquic
137        ${VCPKG_LIB}/event.lib
138        ${VCPKG_LIB}/zlib.lib
139		${BORINGSSL_LIB}/ssl.lib
140		${BORINGSSL_LIB}/crypto.lib
141		ws2_32
142		${LIBS} )
143
144ENDIF()
145
146#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
147
148add_subdirectory(src)
149
150add_subdirectory(test)
151
152IF(NOT (CMAKE_C_FLAGS MATCHES "-DNDEBUG"))
153    # Our test framework relies on assertions, only compile if assertions are
154    # enabled.
155    #
156    enable_testing()
157ENDIF()
158
159
160ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
161