CMakeLists.txt revision db8ac9ee
1# Copyright (c) 2017 - 2018 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
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 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" AND
45                        NOT "$ENV{TRAVIS}" MATCHES "^true$")
46        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
47    ENDIF()
48    # Uncomment to enable fault injection testing via libfiu:
49    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
50    #SET (FIULIB "fiu")
51ELSE()
52    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
53    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
54    # Comment out the following line to compile out debug messages:
55    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
56ENDIF()
57
58IF(LSQUIC_PROFILE EQUAL 1)
59    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
60ENDIF()
61
62IF(LSQUIC_COVERAGE EQUAL 1)
63    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
64ENDIF()
65
66IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
67    MESSAGE(STATUS "AddressSanitizer is ON")
68ELSE()
69    MESSAGE(STATUS "AddressSanitizer is OFF")
70ENDIF()
71
72#MSVC
73ELSE()
74SET(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")
75IF(DEVEL_MODE EQUAL 1)
76    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
77    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
78    #SET (FIULIB "fiu")
79ELSE()
80    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
81    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
82    # Comment out the following line to compile out debug messages:
83    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
84ENDIF()
85
86SET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include)
87SET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include )
88set (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl)
89
90SET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static)
91
92ENDIF() #MSVC
93
94set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
95
96MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
97
98IF(NOT DEFINED BORINGSSL_INCLUDE)
99    SET(BORINGSSL_INCLUDE /usr/local/include)
100ENDIF()
101IF(NOT DEFINED BORINGSSL_LIB)
102    SET(BORINGSSL_LIB /usr/local/lib)
103ENDIF()
104
105
106include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} )
107link_directories( ${BORINGSSL_LIB}  )
108
109SET(CMAKE_INCLUDE_CURRENT_DIR ON)
110include_directories( include )
111
112IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
113    # Find libevent on FreeBSD:
114    include_directories( /usr/local/include )
115    link_directories( /usr/local/lib )
116ENDIF()
117
118
119IF (NOT MSVC)
120add_executable(http_client
121    test/http_client.c
122    test/prog.c
123    test/test_common.c
124)
125target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
126
127#MSVC
128ELSE()
129add_executable(http_client
130    test/http_client.c
131    test/prog.c
132    wincompat/test_common_win.c
133    wincompat/getopt.c
134    wincompat/getopt1.c
135)
136
137target_link_libraries(http_client
138		debug  $(SolutionDir)src/liblsquic/debug/lsquic.lib
139		debug  ${VCPKG_BASE_DIR}/debug/lib/event.lib
140		debug  ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib
141		debug  ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib
142		debug  ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib
143		ws2_32
144		optimized  $(SolutionDir)src/liblsquic/release/lsquic.lib
145		optimized  ${VCPKG_BASE_DIR}/lib/event.lib
146		optimized  ${VCPKG_BASE_DIR}/lib/zlib.lib
147		optimized  ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib
148		optimized  ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib
149		${FIULIB} )
150
151ENDIF()
152
153#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
154
155add_subdirectory(src)
156
157add_subdirectory(test)
158
159IF(DEVEL_MODE EQUAL 1)
160    # Our test framework relies on assertions, only compile if assertions are
161    # enabled.
162    #
163    enable_testing()
164ENDIF()
165
166
167ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
168