CMakeLists.txt revision ccd74161
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 ) 117 118IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 119 # Find libevent on FreeBSD: 120 include_directories( /usr/local/include ) 121 link_directories( /usr/local/lib ) 122ENDIF() 123 124 125IF (NOT MSVC) 126add_executable(http_client 127 test/http_client.c 128 test/prog.c 129 test/test_common.c 130) 131target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 132 133#MSVC 134ELSE() 135add_executable(http_client 136 test/http_client.c 137 test/prog.c 138 test/test_common.c 139 wincompat/getopt.c 140 wincompat/getopt1.c 141) 142 143target_link_libraries(http_client 144 debug $(SolutionDir)src/liblsquic/debug/lsquic.lib 145 debug ${VCPKG_BASE_DIR}/debug/lib/event.lib 146 debug ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib 147 debug ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib 148 debug ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib 149 ws2_32 150 optimized $(SolutionDir)src/liblsquic/release/lsquic.lib 151 optimized ${VCPKG_BASE_DIR}/lib/event.lib 152 optimized ${VCPKG_BASE_DIR}/lib/zlib.lib 153 optimized ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib 154 optimized ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib 155 ${LIBS} ) 156 157ENDIF() 158 159#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 160 161add_subdirectory(src) 162 163add_subdirectory(test) 164 165IF(DEVEL_MODE EQUAL 1) 166 # Our test framework relies on assertions, only compile if assertions are 167 # enabled. 168 # 169 enable_testing() 170ENDIF() 171 172 173ADD_CUSTOM_TARGET(docs doxygen dox.cfg) 174