CMakeLists.txt revision bfc7bfd8
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 5550aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 5650aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is ON") 5750aadb33SDmitri TikhonovELSE() 5850aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is OFF") 5950aadb33SDmitri TikhonovENDIF() 6050aadb33SDmitri Tikhonov 6150aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 6250aadb33SDmitri Tikhonov 6350aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 6450aadb33SDmitri Tikhonov 65e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_INCLUDE) 66cdf70916SDmitri Tikhonov SET(BORINGSSL_INCLUDE /usr/local/include) 67e0197994SDmitri TikhonovENDIF() 68e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_LIB) 69cdf70916SDmitri Tikhonov SET(BORINGSSL_LIB /usr/local/lib) 70e0197994SDmitri TikhonovENDIF() 7150aadb33SDmitri Tikhonov 72cdf70916SDmitri Tikhonovinclude_directories( ${BORINGSSL_INCLUDE} ) 73cdf70916SDmitri Tikhonovlink_directories( ${BORINGSSL_LIB} ) 74cdf70916SDmitri Tikhonov 7550aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON) 7650aadb33SDmitri Tikhonovinclude_directories( include ) 7750aadb33SDmitri Tikhonov 7850aadb33SDmitri TikhonovIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 7950aadb33SDmitri Tikhonov # Find libevent on FreeBSD: 8050aadb33SDmitri Tikhonov include_directories( /usr/local/include ) 8150aadb33SDmitri Tikhonov link_directories( /usr/local/lib ) 8250aadb33SDmitri TikhonovENDIF() 8350aadb33SDmitri Tikhonov 84c51ce338SDmitri Tikhonovadd_executable(http_client 85c51ce338SDmitri Tikhonov test/http_client.c 86c51ce338SDmitri Tikhonov test/prog.c 87c51ce338SDmitri Tikhonov test/test_common.c 88c51ce338SDmitri Tikhonov) 8950aadb33SDmitri Tikhonov 90e0197994SDmitri Tikhonovtarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m) 9150aadb33SDmitri Tikhonov 9250aadb33SDmitri Tikhonovadd_subdirectory(src) 9350aadb33SDmitri Tikhonov 94bfc7bfd8SDmitri Tikhonovadd_subdirectory(test) 9550aadb33SDmitri Tikhonov 9650aadb33SDmitri Tikhonov 9750aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg) 98