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