CMakeLists.txt revision 461e84d8
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(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
61    MESSAGE(STATUS "AddressSanitizer is ON")
62ELSE()
63    MESSAGE(STATUS "AddressSanitizer is OFF")
64ENDIF()
65
66#MSVC
67ELSE()
68SET(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")
69IF(DEVEL_MODE EQUAL 1)
70    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od ")
71    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
72    #SET (FIULIB "fiu")
73ELSE()
74    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -OX")
75    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
76    # Comment out the following line to compile out debug messages:
77    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
78ENDIF()
79
80SET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include)
81SET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include )
82
83IF(CMAKE_BUILD_TYPE MATCHES "Debug")
84SET (BORINGSSL_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/ssl ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/x64/debug)
85SET (VCPKG_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/lib)
86SET (ZLIB_NAME "zlibd")
87ELSE()
88SET (BORINGSSL_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/ssl ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/x64)
89SET (VCPKG_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/debug/lib)
90SET (ZLIB_NAME zlibd)
91ENDIF()
92
93
94ENDIF() #MSVC
95
96set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
97
98MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
99
100IF(NOT DEFINED BORINGSSL_INCLUDE)
101    SET(BORINGSSL_INCLUDE /usr/local/include)
102ENDIF()
103IF(NOT DEFINED BORINGSSL_LIB)
104    SET(BORINGSSL_LIB /usr/local/lib)
105ENDIF()
106
107
108include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} )
109link_directories( ${BORINGSSL_LIB} ${VCPKG_LIB} )
110
111SET(CMAKE_INCLUDE_CURRENT_DIR ON)
112include_directories( include )
113
114IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
115    # Find libevent on FreeBSD:
116    include_directories( /usr/local/include )
117    link_directories( /usr/local/lib )
118ENDIF()
119
120IF (NOT (CMAKE_C_COMPILER MATCHES "MSVC"))
121add_executable(http_client
122    test/http_client.c
123    test/prog.c
124    test/test_common.c
125)
126target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
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 lsquic event ssl crypto ${FIULIB} ${ZLIB_NAME} ws2_32)
137
138ENDIF()
139
140
141
142add_subdirectory(src)
143
144add_subdirectory(test)
145
146IF(DEVEL_MODE EQUAL 1)
147    # Our test framework relies on assertions, only compile if assertions are
148    # enabled.
149    #
150    enable_testing()
151ENDIF()
152
153
154ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
155