CMakeLists.txt revision 083b5939
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# If using older glibc, need to link with -lrt.  See clock_getres(2).
21EXECUTE_PROCESS(
22    COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER}
23    OUTPUT_VARIABLE GLIBC_VERSION)
24IF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17)
25    SET(LIBS ${LIBS} rt)
26ENDIF()
27
28# By default, we compile in development mode.  To compile production code,
29# pass -DDEVEL_MODE=0 to cmake (before that, `make clean' and remove any
30# cmake cache files).
31#
32IF(NOT DEFINED DEVEL_MODE)
33    SET(DEVEL_MODE 1)
34ENDIF()
35
36
37MESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}")
38
39
40IF (NOT MSVC)
41
42SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
43SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
44
45IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
46    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
47ENDIF()
48IF(DEVEL_MODE EQUAL 1)
49    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
50    IF(CMAKE_C_COMPILER MATCHES "clang" AND
51                        NOT "$ENV{TRAVIS}" MATCHES "^true$")
52        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
53    ENDIF()
54    # Uncomment to enable fault injection testing via libfiu:
55    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
56    #SET(LIBS ${LIBS} fiu)
57ELSE()
58    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
59    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
60    # Comment out the following line to compile out debug messages:
61    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
62ENDIF()
63
64IF(LSQUIC_PROFILE EQUAL 1)
65    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
66ENDIF()
67
68IF(LSQUIC_COVERAGE EQUAL 1)
69    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
70ENDIF()
71
72IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
73    MESSAGE(STATUS "AddressSanitizer is ON")
74ELSE()
75    MESSAGE(STATUS "AddressSanitizer is OFF")
76ENDIF()
77
78#MSVC
79ELSE()
80SET(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")
81IF(DEVEL_MODE EQUAL 1)
82    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
83    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
84    #SET(LIBS ${LIBS} fiu)
85ELSE()
86    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
87    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
88    # Comment out the following line to compile out debug messages:
89    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
90ENDIF()
91
92SET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include)
93SET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include )
94set (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl)
95
96SET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static)
97
98ENDIF() #MSVC
99
100set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
101
102MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
103
104IF(NOT DEFINED BORINGSSL_INCLUDE)
105    SET(BORINGSSL_INCLUDE /usr/local/include)
106ENDIF()
107IF(NOT DEFINED BORINGSSL_LIB)
108    SET(BORINGSSL_LIB /usr/local/lib)
109ENDIF()
110
111
112include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} )
113link_directories( ${BORINGSSL_LIB}  )
114
115SET(CMAKE_INCLUDE_CURRENT_DIR ON)
116include_directories( include )
117IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
118    # Find libevent on FreeBSD:
119    include_directories( /usr/local/include )
120    link_directories( /usr/local/lib )
121ENDIF()
122
123
124IF (NOT MSVC)
125add_executable(http_client
126    test/http_client.c
127    test/prog.c
128    test/test_common.c
129)
130target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
131
132#MSVC
133ELSE()
134add_executable(http_client
135    test/http_client.c
136    test/prog.c
137    test/test_common.c
138    wincompat/getopt.c
139    wincompat/getopt1.c
140)
141
142target_link_libraries(http_client
143		debug  $(SolutionDir)src/liblsquic/debug/lsquic.lib
144		debug  ${VCPKG_BASE_DIR}/debug/lib/event.lib
145		debug  ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib
146		debug  ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib
147		debug  ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib
148		ws2_32
149		optimized  $(SolutionDir)src/liblsquic/release/lsquic.lib
150		optimized  ${VCPKG_BASE_DIR}/lib/event.lib
151		optimized  ${VCPKG_BASE_DIR}/lib/zlib.lib
152		optimized  ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib
153		optimized  ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib
154		${LIBS} )
155
156ENDIF()
157
158#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m)
159
160add_subdirectory(src)
161
162add_subdirectory(test)
163
164IF(DEVEL_MODE EQUAL 1)
165    # Our test framework relies on assertions, only compile if assertions are
166    # enabled.
167    #
168    enable_testing()
169ENDIF()
170
171
172ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
173