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