CMakeLists.txt revision 12693a01
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} -W4 -WX -Zi -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -I${CMAKE_CURRENT_SOURCE_DIR}/wincompat")
79IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
80    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
81    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
82    #SET(LIBS ${LIBS} fiu)
83ELSE()
84    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
85    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
86    # Comment out the following line to compile out debug messages:
87    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
88ENDIF()
89
90SET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include)
91SET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include )
92set (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl)
93
94SET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static)
95
96ENDIF() #MSVC
97
98set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
99
100MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
101
102IF(NOT DEFINED BORINGSSL_INCLUDE)
103    SET(BORINGSSL_INCLUDE /usr/local/include)
104ENDIF()
105IF(NOT DEFINED BORINGSSL_LIB)
106    SET(BORINGSSL_LIB /usr/local/lib)
107ENDIF()
108
109
110include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} )
111link_directories( ${BORINGSSL_LIB}  )
112
113SET(CMAKE_INCLUDE_CURRENT_DIR ON)
114include_directories( include src/lshpack)
115IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
116    # Find libevent on FreeBSD:
117    include_directories( /usr/local/include )
118    link_directories( /usr/local/lib )
119ENDIF()
120
121
122IF (NOT MSVC)
123add_executable(http_client
124    test/http_client.c
125    test/prog.c
126    test/test_common.c
127)
128target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
129
130#MSVC
131ELSE()
132add_executable(http_client
133    test/http_client.c
134    test/prog.c
135    test/test_common.c
136    wincompat/getopt.c
137    wincompat/getopt1.c
138)
139
140target_link_libraries(http_client
141		debug  $(SolutionDir)src/liblsquic/debug/lsquic.lib
142		debug  ${VCPKG_BASE_DIR}/debug/lib/event.lib
143		debug  ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib
144		debug  ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib
145		debug  ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib
146		ws2_32
147		optimized  $(SolutionDir)src/liblsquic/release/lsquic.lib
148		optimized  ${VCPKG_BASE_DIR}/lib/event.lib
149		optimized  ${VCPKG_BASE_DIR}/lib/zlib.lib
150		optimized  ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib
151		optimized  ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib
152		${LIBS} )
153
154ENDIF()
155
156#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
157
158add_subdirectory(src)
159
160add_subdirectory(test)
161
162IF(NOT (CMAKE_C_FLAGS MATCHES "-DNDEBUG"))
163    # Our test framework relies on assertions, only compile if assertions are
164    # enabled.
165    #
166    enable_testing()
167ENDIF()
168
169
170ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
171