CMakeLists.txt revision 03e6b668
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$" AND 53 NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize") 54 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 55 ENDIF() 56 # Uncomment to enable cleartext protocol mode (no crypto): 57 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1") 58ELSE() 59 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 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} /wd4214") # nonstandard extension used: bit field types other than int 81SET(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") 82IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 83 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 84 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 85 #SET(LIBS ${LIBS} fiu) 86ELSE() 87 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 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 92ENDIF() #MSVC 93 94set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 95 96MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 97 98IF (NOT DEFINED BORINGSSL_INCLUDE AND DEFINED BORINGSSL_DIR) 99 FIND_PATH(BORINGSSL_INCLUDE NAMES openssl/ssl.h 100 PATHS ${BORINGSSL_DIR}/include 101 NO_DEFAULT_PATH) 102ENDIF() 103# This must be done before adding other include directories to take 104# precedence over header files from other SSL installs. 105 106IF (BORINGSSL_INCLUDE) 107 MESSAGE(STATUS "BoringSSL include directory ${BORINGSSL_INCLUDE}") 108 INCLUDE_DIRECTORIES(${BORINGSSL_INCLUDE}) 109ELSE() 110 MESSAGE(FATAL_ERROR "BoringSSL headers not found") 111ENDIF() 112 113IF (NOT DEFINED BORINGSSL_LIB AND DEFINED BORINGSSL_DIR) 114 FOREACH(LIB_NAME ssl crypto decrepit) 115 IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 116 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 117 NAMES ${LIB_NAME} 118 PATHS ${BORINGSSL_DIR}/${LIB_NAME} 119 PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo 120 NO_DEFAULT_PATH) 121 ELSE() 122 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 123 NAMES lib${LIB_NAME}.a 124 PATHS ${BORINGSSL_DIR}/${LIB_NAME} 125 NO_DEFAULT_PATH) 126 ENDIF() 127 IF(BORINGSSL_LIB_${LIB_NAME}) 128 MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}") 129 ELSE() 130 MESSAGE(STATUS "${LIB_NAME} library not found") 131 ENDIF() 132 ENDFOREACH() 133 134ELSE() 135 136 137 FOREACH(LIB_NAME ssl crypto decrepit) 138 IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 139 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 140 NAMES ${LIB_NAME} 141 PATHS ${BORINGSSL_LIB} 142 PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo 143 NO_DEFAULT_PATH) 144 ELSE() 145 FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 146 NAMES lib${LIB_NAME}.a 147 PATHS ${BORINGSSL_LIB} 148 NO_DEFAULT_PATH) 149 ENDIF() 150 IF(BORINGSSL_LIB_${LIB_NAME}) 151 MESSAGE(STATUS "Found ${BORINGSSL_LIB} library: ${BORINGSSL_LIB_${LIB_NAME}}") 152 ELSE() 153 MESSAGE(STATUS "${BORINGSSL_LIB} library not found") 154 ENDIF() 155 ENDFOREACH() 156#endif 157 158ENDIF() 159 160SET(CMAKE_INCLUDE_CURRENT_DIR ON) 161INCLUDE_DIRECTORIES(include src/lshpack) 162IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") 163 # Find libevent on FreeBSD: 164 include_directories( /usr/local/include ) 165 link_directories( /usr/local/lib ) 166ENDIF() 167 168# Find zlib and libevent header files and library files 169# TODO: libevent is not strictly necessary to build the library. 170FIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h) 171IF (ZLIB_INCLUDE_DIR) 172 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) 173ELSE() 174 MESSAGE(FATAL_ERROR "zlib.h was not found") 175ENDIF() 176IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 177 FIND_LIBRARY(ZLIB_LIB zlib) 178ELSEIF(CMAKE_SYSTEM_NAME STREQUAL Darwin) 179 # XXX somehow FIND_LIBRARY() does not find zlib on Travis? 180 SET(ZLIB_LIB z) 181ELSE() 182 FIND_LIBRARY(ZLIB_LIB libz.a) 183ENDIF() 184IF(ZLIB_LIB) 185 MESSAGE(STATUS "Found zlib: ${ZLIB_LIB}") 186ELSE() 187 MESSAGE(STATUS "zlib not found") 188ENDIF() 189FIND_PATH(EVENT_INCLUDE_DIR NAMES event2/event.h) 190IF (EVENT_INCLUDE_DIR) 191 INCLUDE_DIRECTORIES(${EVENT_INCLUDE_DIR}) 192ELSE() 193 MESSAGE(FATAL_ERROR "event2/event.h was not found") 194ENDIF() 195IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 196 FIND_LIBRARY(EVENT_LIB event) 197ELSE() 198 FIND_LIBRARY(EVENT_LIB libevent.a libevent.so) 199ENDIF() 200IF(EVENT_LIB) 201 MESSAGE(STATUS "Found event: ${EVENT_LIB}") 202ELSE() 203 MESSAGE(STATUS "libevent not found") 204ENDIF() 205 206add_executable(http_server test/http_server.c test/prog.c test/test_common.c test/test_cert.c) 207add_executable(md5_server test/md5_server.c test/prog.c test/test_common.c test/test_cert.c) 208add_executable(md5_client test/md5_client.c test/prog.c test/test_common.c test/test_cert.c) 209add_executable(echo_server test/echo_server.c test/prog.c test/test_common.c test/test_cert.c) 210add_executable(echo_client test/echo_client.c test/prog.c test/test_common.c test/test_cert.c) 211 212 213SET(LIBS lsquic ${EVENT_LIB} ${BORINGSSL_LIB_ssl} ${BORINGSSL_LIB_crypto} ${ZLIB_LIB} ${LIBS}) 214 215IF (NOT MSVC) 216 217add_executable(http_client 218 test/http_client.c 219 test/prog.c 220 test/test_common.c 221 test/test_cert.c 222) 223LIST(APPEND LIBS pthread m) 224 225#MSVC 226ELSE() 227 228add_executable(http_client 229 test/http_client.c 230 test/prog.c 231 test/test_common.c 232 wincompat/getopt.c 233 wincompat/getopt1.c 234) 235LIST(APPEND LIBS ws2_32) 236 237ENDIF() 238 239TARGET_LINK_LIBRARIES(http_client ${LIBS}) 240TARGET_LINK_LIBRARIES(http_server ${LIBS}) 241TARGET_LINK_LIBRARIES(md5_server ${LIBS}) 242TARGET_LINK_LIBRARIES(md5_client ${LIBS}) 243TARGET_LINK_LIBRARIES(echo_server ${LIBS}) 244TARGET_LINK_LIBRARIES(echo_client ${LIBS}) 245 246add_subdirectory(src) 247 248add_subdirectory(test) 249 250IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 251 # Our test framework relies on assertions, only compile if assertions are 252 # enabled. 253 # 254 enable_testing() 255ENDIF() 256 257 258ADD_CUSTOM_TARGET(docs doxygen dox.cfg) 259