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