CMakeLists.txt revision 229fce07
1# Copyright (c) 2017 - 2019 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 28IF("${CMAKE_BUILD_TYPE}" STREQUAL "") 29 SET(CMAKE_BUILD_TYPE Debug) 30ENDIF() 31 32 33MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 34 35 36IF (NOT MSVC) 37 38SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 39SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 40 41IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 42 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 43ENDIF() 44IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 45 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 46 IF(CMAKE_C_COMPILER MATCHES "clang" AND 47 NOT "$ENV{TRAVIS}" MATCHES "^true$") 48 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 49 ENDIF() 50 # Uncomment to enable fault injection testing via libfiu: 51 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 52 #SET(LIBS ${LIBS} fiu) 53ELSE() 54 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 55 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 56 # Comment out the following line to compile out debug messages: 57 #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 58ENDIF() 59 60IF(LSQUIC_PROFILE EQUAL 1) 61 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 62ENDIF() 63 64IF(LSQUIC_COVERAGE EQUAL 1) 65 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 66ENDIF() 67 68IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 69 MESSAGE(STATUS "AddressSanitizer is ON") 70ELSE() 71 MESSAGE(STATUS "AddressSanitizer is OFF") 72ENDIF() 73 74#MSVC 75ELSE() 76SET(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") 77IF(CMAKE_BUILD_TYPE STREQUAL "Debug") 78 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 79 #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 80 #SET(LIBS ${LIBS} fiu) 81ELSE() 82 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 83 SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 84 # Comment out the following line to compile out debug messages: 85 #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 86ENDIF() 87 88SET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include) 89SET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include ) 90set (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl) 91 92SET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static) 93 94ENDIF() #MSVC 95 96set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 97 98MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 99 100IF(NOT DEFINED BORINGSSL_INCLUDE) 101 SET(BORINGSSL_INCLUDE /usr/local/include) 102ENDIF() 103IF(NOT DEFINED BORINGSSL_LIB) 104 SET(BORINGSSL_LIB /usr/local/lib) 105ENDIF() 106 107 108include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} ) 109link_directories( ${BORINGSSL_LIB} ) 110 111SET(CMAKE_INCLUDE_CURRENT_DIR ON) 112include_directories( include src/lshpack) 113IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 114 # Find libevent on FreeBSD: 115 include_directories( /usr/local/include ) 116 link_directories( /usr/local/lib ) 117ENDIF() 118 119 120IF (NOT MSVC) 121add_executable(http_client 122 test/http_client.c 123 test/prog.c 124 test/test_common.c 125) 126target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 127 128#MSVC 129ELSE() 130add_executable(http_client 131 test/http_client.c 132 test/prog.c 133 test/test_common.c 134 wincompat/getopt.c 135 wincompat/getopt1.c 136) 137 138target_link_libraries(http_client 139 debug $(SolutionDir)src/liblsquic/debug/lsquic.lib 140 debug ${VCPKG_BASE_DIR}/debug/lib/event.lib 141 debug ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib 142 debug ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib 143 debug ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib 144 ws2_32 145 optimized $(SolutionDir)src/liblsquic/release/lsquic.lib 146 optimized ${VCPKG_BASE_DIR}/lib/event.lib 147 optimized ${VCPKG_BASE_DIR}/lib/zlib.lib 148 optimized ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib 149 optimized ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib 150 ${LIBS} ) 151 152ENDIF() 153 154#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 155 156add_subdirectory(src) 157 158add_subdirectory(test) 159 160IF(NOT (CMAKE_C_FLAGS MATCHES "-DNDEBUG")) 161 # Our test framework relies on assertions, only compile if assertions are 162 # enabled. 163 # 164 enable_testing() 165ENDIF() 166 167 168ADD_CUSTOM_TARGET(docs doxygen dox.cfg) 169