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