CMakeLists.txt revision b1af35d6
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 21 22MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 23 24 25IF (NOT MSVC) 26 27SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 28SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 29 30IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 31 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 32ENDIF() 33IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 34 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 35 IF(CMAKE_C_COMPILER MATCHES "clang" AND 36 NOT "$ENV{TRAVIS}" MATCHES "^true$") 37 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 38 ENDIF() 39 # Uncomment to enable fault injection testing via libfiu: 40 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 41 #SET(LIBS ${LIBS} fiu) 42ELSE() 43 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 44 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 45 # Comment out the following line to compile out debug messages: 46 #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 47ENDIF() 48 49IF(LSQUIC_PROFILE EQUAL 1) 50 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 51ENDIF() 52 53IF(LSQUIC_COVERAGE EQUAL 1) 54 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 55ENDIF() 56 57IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 58 MESSAGE(STATUS "AddressSanitizer is ON") 59ELSE() 60 MESSAGE(STATUS "AddressSanitizer is OFF") 61ENDIF() 62 63#MSVC 64ELSE() 65SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4214") # nonstandard extension used: bit field types other than int 66SET(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") 67IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 68 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 69 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 70 #SET(LIBS ${LIBS} fiu) 71ELSE() 72 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 73 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 74 # Comment out the following line to compile out debug messages: 75 #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 76ENDIF() 77 78ENDIF() #MSVC 79 80set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 81 82MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 83 84# This must be done before adding other include directories to take 85# precedence over header files from other SSL installs. 86FIND_PATH(BORINGSSL_INCLUDE_DIR NAMES openssl/ssl.h 87 PATHS ${BORINGSSL_DIR}/include 88 NO_DEFAULT_PATH) 89IF (BORINGSSL_INCLUDE_DIR) 90 MESSAGE(STATUS "BoringSSL include directory ${BORINGSSL_INCLUDE_DIR}") 91 INCLUDE_DIRECTORIES(${BORINGSSL_INCLUDE_DIR}) 92ELSE() 93 MESSAGE(FATAL_ERROR "BoringSSL headers not found") 94ENDIF() 95 96FOREACH(BORINGSSL_LIB ssl crypto decrepit) 97 IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 98 FIND_LIBRARY(BORINGSSL_LIB_${BORINGSSL_LIB} 99 NAMES ${BORINGSSL_LIB} 100 PATHS ${BORINGSSL_DIR}/${BORINGSSL_LIB} 101 PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo 102 NO_DEFAULT_PATH) 103 ELSE() 104 FIND_LIBRARY(BORINGSSL_LIB_${BORINGSSL_LIB} 105 NAMES lib${BORINGSSL_LIB}.a 106 PATHS ${BORINGSSL_DIR}/${BORINGSSL_LIB} 107 NO_DEFAULT_PATH) 108 ENDIF() 109 IF(BORINGSSL_LIB_${BORINGSSL_LIB}) 110 MESSAGE(STATUS "Found ${BORINGSSL_LIB} library: ${BORINGSSL_LIB_${BORINGSSL_LIB}}") 111 ELSE() 112 MESSAGE(STATUS "${BORINGSSL_LIB} library not found") 113 ENDIF() 114ENDFOREACH() 115 116IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") 117 # Find libevent on FreeBSD: 118 INCLUDE_DIRECTORIES( /usr/local/include ) 119 LINK_DIRECTORIES( /usr/local/lib ) 120ENDIF() 121 122# Find zlib and libevent header files and library files 123# TODO: libevent is not strictly necessary to build the library. 124FIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h) 125IF (ZLIB_INCLUDE_DIR) 126 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) 127ELSE() 128 MESSAGE(FATAL_ERROR "zlib.h was not found") 129ENDIF() 130IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 131 FIND_LIBRARY(ZLIB_LIB zlib) 132ELSEIF(CMAKE_SYSTEM_NAME STREQUAL Darwin) 133 # XXX somehow FIND_LIBRARY() does not find zlib on Travis? 134 SET(ZLIB_LIB z) 135ELSE() 136 FIND_LIBRARY(ZLIB_LIB libz.a) 137ENDIF() 138IF(ZLIB_LIB) 139 MESSAGE(STATUS "Found zlib: ${ZLIB_LIB}") 140ELSE() 141 MESSAGE(STATUS "zlib not found") 142ENDIF() 143FIND_PATH(EVENT_INCLUDE_DIR NAMES event2/event.h) 144IF (EVENT_INCLUDE_DIR) 145 INCLUDE_DIRECTORIES(${EVENT_INCLUDE_DIR}) 146ELSE() 147 MESSAGE(FATAL_ERROR "event2/event.h was not found") 148ENDIF() 149IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 150 FIND_LIBRARY(EVENT_LIB event) 151ELSE() 152 FIND_LIBRARY(EVENT_LIB libevent.a) 153ENDIF() 154IF(EVENT_LIB) 155 MESSAGE(STATUS "Found event: ${EVENT_LIB}") 156ELSE() 157 MESSAGE(STATUS "libevent not found") 158ENDIF() 159 160SET(CMAKE_INCLUDE_CURRENT_DIR ON) 161include_directories( include src/lshpack) 162 163IF (NOT MSVC) 164add_executable(http_client 165 test/http_client.c 166 test/prog.c 167 test/test_common.c 168) 169TARGET_LINK_LIBRARIES(http_client lsquic ${EVENT_LIB} pthread 170 ${BORINGSSL_LIB_ssl} ${BORINGSSL_LIB_crypto} ${LIBS} ${ZLIB_LIB} m) 171 172#MSVC 173ELSE() 174add_executable(http_client 175 test/http_client.c 176 test/prog.c 177 test/test_common.c 178 wincompat/getopt.c 179 wincompat/getopt1.c 180) 181 182target_link_libraries(http_client 183 lsquic 184 ${EVENT_LIB} 185 ${ZLIB_LIB} 186 ${BORINGSSL_LIB_ssl} 187 ${BORINGSSL_LIB_crypto} 188 ws2_32 189 ${LIBS} ) 190 191ENDIF() 192 193#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 194 195add_subdirectory(src) 196 197add_subdirectory(test) 198 199IF(NOT (CMAKE_C_FLAGS MATCHES "-DNDEBUG")) 200 # Our test framework relies on assertions, only compile if assertions are 201 # enabled. 202 # 203 enable_testing() 204ENDIF() 205 206 207ADD_CUSTOM_TARGET(docs doxygen dox.cfg) 208