CMakeLists.txt revision b5d685fc
1# Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE.
2cmake_minimum_required(VERSION 2.8)
3
4
5project(lsquic)
6
7IF (NOT (CMAKE_C_COMPILER MATCHES "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
20# By default, we compile in development mode.  To compile production code,
21# pass -DDEVEL_MODE=0 to cmake (before that, `make clean' and remove any
22# cmake cache files).
23#
24IF(NOT DEFINED DEVEL_MODE)
25    SET(DEVEL_MODE 1)
26ENDIF()
27
28
29MESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}")
30
31
32IF (NOT (CMAKE_C_COMPILER MATCHES "MSVC"))
33
34SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
35SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
36
37IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
38    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
39ENDIF()
40IF(DEVEL_MODE EQUAL 1)
41    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
42    # -Werror is used to force us to fix warnings early.
43    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror")
44    IF(CMAKE_C_COMPILER MATCHES "clang")
45        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
46    ENDIF()
47    # Uncomment to enable fault injection testing via libfiu:
48    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
49    #SET (FIULIB "fiu")
50ELSE()
51    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
52    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
53    # Comment out the following line to compile out debug messages:
54    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
55ENDIF()
56
57IF(LSQUIC_PROFILE EQUAL 1)
58    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
59ENDIF()
60
61IF(LSQUIC_COVERAGE EQUAL 1)
62    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
63ENDIF()
64
65IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
66    MESSAGE(STATUS "AddressSanitizer is ON")
67ELSE()
68    MESSAGE(STATUS "AddressSanitizer is OFF")
69ENDIF()
70
71#MSVC
72ELSE()
73SET(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")
74IF(DEVEL_MODE EQUAL 1)
75    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
76    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
77    #SET (FIULIB "fiu")
78ELSE()
79    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
80    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
81    # Comment out the following line to compile out debug messages:
82    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
83ENDIF()
84
85SET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include)
86SET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include )
87set (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl)
88
89SET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static)
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 )
110
111IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
112    # Find libevent on FreeBSD:
113    include_directories( /usr/local/include )
114    link_directories( /usr/local/lib )
115ENDIF()
116
117
118IF (NOT (CMAKE_C_COMPILER MATCHES "MSVC"))
119add_executable(http_client
120    test/http_client.c
121    test/prog.c
122    test/test_common.c
123)
124target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
125
126#MSVC
127ELSE()
128add_executable(http_client
129    test/http_client.c
130    test/prog.c
131    wincompat/test_common_win.c
132    wincompat/getopt.c
133    wincompat/getopt1.c
134)
135
136target_link_libraries(http_client
137		debug  $(SolutionDir)src/liblsquic/debug/lsquic.lib
138		debug  ${VCPKG_BASE_DIR}/debug/lib/event.lib
139		debug  ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib
140		debug  ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib
141		debug  ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib
142		ws2_32
143		optimized  $(SolutionDir)src/liblsquic/release/lsquic.lib
144		optimized  ${VCPKG_BASE_DIR}/lib/event.lib
145		optimized  ${VCPKG_BASE_DIR}/lib/zlib.lib
146		optimized  ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib
147		optimized  ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib
148		${FIULIB} )
149
150ENDIF()
151
152#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
153
154add_subdirectory(src)
155
156add_subdirectory(test)
157
158IF(DEVEL_MODE EQUAL 1)
159    # Our test framework relies on assertions, only compile if assertions are
160    # enabled.
161    #
162    enable_testing()
163ENDIF()
164
165
166ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
167