CMakeLists.txt revision 16a9b66a
150aadb33SDmitri Tikhonov# Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. 250aadb33SDmitri Tikhonovcmake_minimum_required(VERSION 2.8) 350aadb33SDmitri Tikhonov 450aadb33SDmitri Tikhonov 550aadb33SDmitri Tikhonovproject(lsquic) 650aadb33SDmitri Tikhonov 750aadb33SDmitri Tikhonov# We prefer clang 850aadb33SDmitri TikhonovIF(NOT ("${CMAKE_C_COMPILER}" MATCHES "ccc-analyzer" OR 950aadb33SDmitri Tikhonov "${CMAKE_C_COMPILER}" MATCHES "gcc" OR 1050aadb33SDmitri Tikhonov "${CMAKE_C_COMPILER}" MATCHES "afl-gcc")) 1150aadb33SDmitri Tikhonov FIND_PROGRAM(CLANG "clang") 1250aadb33SDmitri Tikhonov IF(CLANG) 1350aadb33SDmitri Tikhonov SET(CMAKE_C_COMPILER "${CLANG}") 1450aadb33SDmitri Tikhonov ENDIF() 1550aadb33SDmitri TikhonovENDIF() 1650aadb33SDmitri Tikhonov 1750aadb33SDmitri Tikhonov# By default, we compile in development mode. To compile production code, 1850aadb33SDmitri Tikhonov# pass -DDEVEL_MODE=0 to cmake (before that, `make clean' and remove any 1950aadb33SDmitri Tikhonov# cmake cache files). 2050aadb33SDmitri Tikhonov# 2150aadb33SDmitri TikhonovIF(NOT DEFINED DEVEL_MODE) 2250aadb33SDmitri Tikhonov SET(DEVEL_MODE 1) 2350aadb33SDmitri TikhonovENDIF() 2450aadb33SDmitri Tikhonov 2550aadb33SDmitri Tikhonov 2650aadb33SDmitri TikhonovMESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}") 2750aadb33SDmitri Tikhonov 2850aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 2950aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 3050aadb33SDmitri Tikhonov 31e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 3250aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 3350aadb33SDmitri TikhonovENDIF() 3450aadb33SDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 3550aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 3650aadb33SDmitri Tikhonov # -Werror is used to force us to fix warnings early. 3750aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror") 3850aadb33SDmitri Tikhonov IF(CMAKE_C_COMPILER MATCHES "clang") 3950aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 4050aadb33SDmitri Tikhonov ENDIF() 4150aadb33SDmitri Tikhonov # Uncomment to enable fault injection testing via libfiu: 4250aadb33SDmitri Tikhonov #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 4350aadb33SDmitri Tikhonov #SET (FIULIB "fiu") 4450aadb33SDmitri TikhonovELSE() 4550aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 4650aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 4750aadb33SDmitri Tikhonov # Comment out the following line to compile out debug messages: 4850aadb33SDmitri Tikhonov #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 4950aadb33SDmitri TikhonovENDIF() 5050aadb33SDmitri Tikhonov 5167b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1) 5267b0dc15SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 5367b0dc15SDmitri TikhonovENDIF() 5467b0dc15SDmitri Tikhonov 5516a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1) 5616a9b66aSDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 5716a9b66aSDmitri TikhonovENDIF() 5816a9b66aSDmitri Tikhonov 5950aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 6050aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is ON") 6150aadb33SDmitri TikhonovELSE() 6250aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is OFF") 6350aadb33SDmitri TikhonovENDIF() 6450aadb33SDmitri Tikhonov 6550aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 6650aadb33SDmitri Tikhonov 6750aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 6850aadb33SDmitri Tikhonov 69e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_INCLUDE) 70cdf70916SDmitri Tikhonov SET(BORINGSSL_INCLUDE /usr/local/include) 71e0197994SDmitri TikhonovENDIF() 72e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_LIB) 73cdf70916SDmitri Tikhonov SET(BORINGSSL_LIB /usr/local/lib) 74e0197994SDmitri TikhonovENDIF() 7550aadb33SDmitri Tikhonov 76cdf70916SDmitri Tikhonovinclude_directories( ${BORINGSSL_INCLUDE} ) 77cdf70916SDmitri Tikhonovlink_directories( ${BORINGSSL_LIB} ) 78cdf70916SDmitri Tikhonov 7950aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON) 8050aadb33SDmitri Tikhonovinclude_directories( include ) 8150aadb33SDmitri Tikhonov 8250aadb33SDmitri TikhonovIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 8350aadb33SDmitri Tikhonov # Find libevent on FreeBSD: 8450aadb33SDmitri Tikhonov include_directories( /usr/local/include ) 8550aadb33SDmitri Tikhonov link_directories( /usr/local/lib ) 8650aadb33SDmitri TikhonovENDIF() 8750aadb33SDmitri Tikhonov 88c51ce338SDmitri Tikhonovadd_executable(http_client 89c51ce338SDmitri Tikhonov test/http_client.c 90c51ce338SDmitri Tikhonov test/prog.c 91c51ce338SDmitri Tikhonov test/test_common.c 92c51ce338SDmitri Tikhonov) 9350aadb33SDmitri Tikhonov 94e0197994SDmitri Tikhonovtarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m) 9550aadb33SDmitri Tikhonov 9650aadb33SDmitri Tikhonovadd_subdirectory(src) 9750aadb33SDmitri Tikhonov 98bfc7bfd8SDmitri Tikhonovadd_subdirectory(test) 9950aadb33SDmitri Tikhonov 1007fbe101bSDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 1017fbe101bSDmitri Tikhonov # Our test framework relies on assertions, only compile if assertions are 1027fbe101bSDmitri Tikhonov # enabled. 1037fbe101bSDmitri Tikhonov # 1047fbe101bSDmitri Tikhonov enable_testing() 1057fbe101bSDmitri TikhonovENDIF() 1067fbe101bSDmitri Tikhonov 10750aadb33SDmitri Tikhonov 10850aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg) 109