CMakeLists.txt revision df992bce
1# Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc. See LICENSE. 2cmake_minimum_required(VERSION 2.8) 3 4 5PROJECT(lsquic C) 6 7IF (CMAKE_SYSTEM_NAME STREQUAL "Linux") 8 # If using older glibc, need to link with -lrt. See clock_getres(2). 9 EXECUTE_PROCESS( 10 COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER} 11 OUTPUT_VARIABLE GLIBC_VERSION) 12 IF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17) 13 SET(LIBS ${LIBS} rt) 14 ENDIF() 15ENDIF() 16 17IF("${CMAKE_BUILD_TYPE}" STREQUAL "") 18 SET(CMAKE_BUILD_TYPE Debug) 19ENDIF() 20 21MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 22 23OPTION(LSQUIC_FIU "Use Fault Injection in Userspace (FIU)" OFF) 24 25SET(MY_CMAKE_FLAGS "-DLSQUIC_DEBUG_NEXT_ADV_TICK=1") 26 27IF (NOT MSVC) 28 29SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 30SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 31INCLUDE(CheckCCompilerFlag) 32CHECK_C_COMPILER_FLAG(-Wno-implicit-fallthrough HAS_NO_IMPLICIT_FALLTHROUGH) 33IF (HAS_NO_IMPLICIT_FALLTHROUGH) 34 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-implicit-fallthrough") 35ENDIF() 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() 40 41IF(LSQUIC_FIU) 42 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 43 SET(LIBS ${LIBS} fiu) 44ENDIF() 45 46IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 47 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 48 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror") 49 IF(CMAKE_C_COMPILER MATCHES "clang" AND 50 NOT "$ENV{TRAVIS}" MATCHES "^true$") 51 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 52 ENDIF() 53 # Uncomment to enable cleartext protocol mode (no crypto): 54 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1") 55ELSE() 56 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 57 # Comment out the following line to compile out debug messages: 58 #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 59ENDIF() 60 61IF(LSQUIC_PROFILE EQUAL 1) 62 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 63ENDIF() 64 65IF(LSQUIC_COVERAGE EQUAL 1) 66 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 67ENDIF() 68 69IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 70 MESSAGE(STATUS "AddressSanitizer is ON") 71ELSE() 72 MESSAGE(STATUS "AddressSanitizer is OFF") 73ENDIF() 74 75#MSVC 76ELSE() 77SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4214") # nonstandard extension used: bit field types other than int 78SET(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") 79IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 80 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 81 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 82 #SET(LIBS ${LIBS} fiu) 83ELSE() 84 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 85 # Comment out the following line to compile out debug messages: 86 #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 87ENDIF() 88 89ENDIF() #MSVC 90 91set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 92 93MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 94 95IF (NOT DEFINED BORINGSSL_INCLUDE AND DEFINED BORINGSSL_DIR) 96 FIND_PATH(BORINGSSL_INCLUDE NAMES openssl/ssl.h 97 PATHS ${BORINGSSL_DIR}/include 98 NO_DEFAULT_PATH) 99ENDIF() 100# This must be done before adding other include directories to take 101# precedence over header files from other SSL installs. 102 103IF (BORINGSSL_INCLUDE) 104 MESSAGE(STATUS "BoringSSL include directory ${BORINGSSL_INCLUDE}") 105 INCLUDE_DIRECTORIES(${BORINGSSL_INCLUDE}) 106ELSE() 107 MESSAGE(FATAL_ERROR "BoringSSL headers not found") 108ENDIF() 109 110IF (NOT DEFINED BORINGSSL_LIB AND DEFINED BORINGSSL_DIR) 111 FOREACH(LIB_NAME ssl crypto decrepit) 112 IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 113 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 114 NAMES ${LIB_NAME} 115 PATHS ${BORINGSSL_DIR}/${LIB_NAME} 116 PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo 117 NO_DEFAULT_PATH) 118 ELSE() 119 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 120 NAMES lib${LIB_NAME}.a 121 PATHS ${BORINGSSL_DIR}/${LIB_NAME} 122 NO_DEFAULT_PATH) 123 ENDIF() 124 IF(BORINGSSL_LIB_${LIB_NAME}) 125 MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}") 126 ELSE() 127 MESSAGE(STATUS "${LIB_NAME} library not found") 128 ENDIF() 129 ENDFOREACH() 130 131ELSE() 132 133 134 FOREACH(LIB_NAME ssl crypto decrepit) 135 IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 136 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 137 NAMES ${LIB_NAME} 138 PATHS ${BORINGSSL_LIB} 139 PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo 140 NO_DEFAULT_PATH) 141 ELSE() 142 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 143 NAMES lib${LIB_NAME}.a 144 PATHS ${BORINGSSL_LIB} 145 NO_DEFAULT_PATH) 146 ENDIF() 147 IF(BORINGSSL_LIB_${LIB_NAME}) 148 MESSAGE(STATUS "Found ${BORINGSSL_LIB} library: ${BORINGSSL_LIB_${LIB_NAME}}") 149 ELSE() 150 MESSAGE(STATUS "${BORINGSSL_LIB} library not found") 151 ENDIF() 152 ENDFOREACH() 153#endif 154 155ENDIF() 156 157SET(CMAKE_INCLUDE_CURRENT_DIR ON) 158INCLUDE_DIRECTORIES(include src/lshpack) 159IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") 160 # Find libevent on FreeBSD: 161 include_directories( /usr/local/include ) 162 link_directories( /usr/local/lib ) 163ENDIF() 164 165# Find zlib and libevent header files and library files 166# TODO: libevent is not strictly necessary to build the library. 167FIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h) 168IF (ZLIB_INCLUDE_DIR) 169 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) 170ELSE() 171 MESSAGE(FATAL_ERROR "zlib.h was not found") 172ENDIF() 173IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 174 FIND_LIBRARY(ZLIB_LIB zlib) 175ELSEIF(CMAKE_SYSTEM_NAME STREQUAL Darwin) 176 # XXX somehow FIND_LIBRARY() does not find zlib on Travis? 177 SET(ZLIB_LIB z) 178ELSE() 179 FIND_LIBRARY(ZLIB_LIB libz.a) 180ENDIF() 181IF(ZLIB_LIB) 182 MESSAGE(STATUS "Found zlib: ${ZLIB_LIB}") 183ELSE() 184 MESSAGE(STATUS "zlib not found") 185ENDIF() 186FIND_PATH(EVENT_INCLUDE_DIR NAMES event2/event.h) 187IF (EVENT_INCLUDE_DIR) 188 INCLUDE_DIRECTORIES(${EVENT_INCLUDE_DIR}) 189ELSE() 190 MESSAGE(FATAL_ERROR "event2/event.h was not found") 191ENDIF() 192IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 193 FIND_LIBRARY(EVENT_LIB event) 194ELSE() 195 FIND_LIBRARY(EVENT_LIB libevent.a libevent.so) 196ENDIF() 197IF(EVENT_LIB) 198 MESSAGE(STATUS "Found event: ${EVENT_LIB}") 199ELSE() 200 MESSAGE(STATUS "libevent not found") 201ENDIF() 202 203add_executable(http_server test/http_server.c test/prog.c test/test_common.c test/test_cert.c) 204add_executable(md5_server test/md5_server.c test/prog.c test/test_common.c test/test_cert.c) 205add_executable(md5_client test/md5_client.c test/prog.c test/test_common.c test/test_cert.c) 206add_executable(echo_server test/echo_server.c test/prog.c test/test_common.c test/test_cert.c) 207add_executable(echo_client test/echo_client.c test/prog.c test/test_common.c test/test_cert.c) 208 209 210SET(LIBS lsquic ${EVENT_LIB} ${BORINGSSL_LIB_ssl} ${BORINGSSL_LIB_crypto} ${ZLIB_LIB} ${LIBS}) 211 212IF (NOT MSVC) 213 214add_executable(http_client 215 test/http_client.c 216 test/prog.c 217 test/test_common.c 218 test/test_cert.c 219) 220LIST(APPEND LIBS pthread m) 221 222#MSVC 223ELSE() 224 225add_executable(http_client 226 test/http_client.c 227 test/prog.c 228 test/test_common.c 229 wincompat/getopt.c 230 wincompat/getopt1.c 231) 232LIST(APPEND LIBS ws2_32) 233 234ENDIF() 235 236TARGET_LINK_LIBRARIES(http_client ${LIBS}) 237TARGET_LINK_LIBRARIES(http_server ${LIBS}) 238TARGET_LINK_LIBRARIES(md5_server ${LIBS}) 239TARGET_LINK_LIBRARIES(md5_client ${LIBS}) 240TARGET_LINK_LIBRARIES(echo_server ${LIBS}) 241TARGET_LINK_LIBRARIES(echo_client ${LIBS}) 242 243add_subdirectory(src) 244 245add_subdirectory(test) 246 247IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 248 # Our test framework relies on assertions, only compile if assertions are 249 # enabled. 250 # 251 enable_testing() 252ENDIF() 253 254 255ADD_CUSTOM_TARGET(docs doxygen dox.cfg) 256