CMakeLists.txt revision 46a5b669
110c492f0SDmitri Tikhonov# Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc. See LICENSE. 250aadb33SDmitri Tikhonovcmake_minimum_required(VERSION 2.8) 350aadb33SDmitri Tikhonov 450aadb33SDmitri Tikhonov 550aadb33SDmitri Tikhonovproject(lsquic) 650aadb33SDmitri Tikhonov 746a5b669SDmitri TikhonovIF (NOT MSVC) 850aadb33SDmitri Tikhonov# We prefer clang 950aadb33SDmitri TikhonovIF(NOT ("${CMAKE_C_COMPILER}" MATCHES "ccc-analyzer" OR 1050aadb33SDmitri Tikhonov "${CMAKE_C_COMPILER}" MATCHES "gcc" OR 1150aadb33SDmitri Tikhonov "${CMAKE_C_COMPILER}" MATCHES "afl-gcc")) 1250aadb33SDmitri Tikhonov FIND_PROGRAM(CLANG "clang") 1350aadb33SDmitri Tikhonov IF(CLANG) 1450aadb33SDmitri Tikhonov SET(CMAKE_C_COMPILER "${CLANG}") 1550aadb33SDmitri Tikhonov ENDIF() 1650aadb33SDmitri TikhonovENDIF() 1750aadb33SDmitri Tikhonov 18461e84d8SAmol DeshpandeENDIF() 19461e84d8SAmol Deshpande 2050aadb33SDmitri Tikhonov# By default, we compile in development mode. To compile production code, 2150aadb33SDmitri Tikhonov# pass -DDEVEL_MODE=0 to cmake (before that, `make clean' and remove any 2250aadb33SDmitri Tikhonov# cmake cache files). 2350aadb33SDmitri Tikhonov# 2450aadb33SDmitri TikhonovIF(NOT DEFINED DEVEL_MODE) 2550aadb33SDmitri Tikhonov SET(DEVEL_MODE 1) 2650aadb33SDmitri TikhonovENDIF() 2750aadb33SDmitri Tikhonov 2850aadb33SDmitri Tikhonov 2950aadb33SDmitri TikhonovMESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}") 3050aadb33SDmitri Tikhonov 31b93f59beSBob Perper 3246a5b669SDmitri TikhonovIF (NOT MSVC) 33461e84d8SAmol Deshpande 3450aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 3550aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 3650aadb33SDmitri Tikhonov 37e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 3850aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 3950aadb33SDmitri TikhonovENDIF() 4050aadb33SDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 4150aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 4250aadb33SDmitri Tikhonov # -Werror is used to force us to fix warnings early. 4350aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror") 4450aadb33SDmitri Tikhonov IF(CMAKE_C_COMPILER MATCHES "clang") 4550aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 4650aadb33SDmitri Tikhonov ENDIF() 4750aadb33SDmitri Tikhonov # Uncomment to enable fault injection testing via libfiu: 4850aadb33SDmitri Tikhonov #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 4950aadb33SDmitri Tikhonov #SET (FIULIB "fiu") 5050aadb33SDmitri TikhonovELSE() 5150aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 5250aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 5350aadb33SDmitri Tikhonov # Comment out the following line to compile out debug messages: 5450aadb33SDmitri Tikhonov #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 5550aadb33SDmitri TikhonovENDIF() 5650aadb33SDmitri Tikhonov 5767b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1) 5867b0dc15SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 5967b0dc15SDmitri TikhonovENDIF() 6067b0dc15SDmitri Tikhonov 6116a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1) 6216a9b66aSDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 6316a9b66aSDmitri TikhonovENDIF() 6416a9b66aSDmitri Tikhonov 6550aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 6650aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is ON") 6750aadb33SDmitri TikhonovELSE() 6850aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is OFF") 6950aadb33SDmitri TikhonovENDIF() 7050aadb33SDmitri Tikhonov 71461e84d8SAmol Deshpande#MSVC 72461e84d8SAmol DeshpandeELSE() 73461e84d8SAmol DeshpandeSET(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") 74461e84d8SAmol DeshpandeIF(DEVEL_MODE EQUAL 1) 75b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 76461e84d8SAmol Deshpande #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 77461e84d8SAmol Deshpande #SET (FIULIB "fiu") 78461e84d8SAmol DeshpandeELSE() 79b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 80461e84d8SAmol Deshpande SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 81461e84d8SAmol Deshpande # Comment out the following line to compile out debug messages: 82461e84d8SAmol Deshpande #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 83461e84d8SAmol DeshpandeENDIF() 84461e84d8SAmol Deshpande 85461e84d8SAmol DeshpandeSET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include) 86461e84d8SAmol DeshpandeSET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include ) 87b5d685fcSBob Perperset (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl) 88461e84d8SAmol Deshpande 895d77f141SAmol DeshpandeSET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static) 90461e84d8SAmol Deshpande 91461e84d8SAmol DeshpandeENDIF() #MSVC 92461e84d8SAmol Deshpande 9350aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 9450aadb33SDmitri Tikhonov 9550aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 9650aadb33SDmitri Tikhonov 97e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_INCLUDE) 98cdf70916SDmitri Tikhonov SET(BORINGSSL_INCLUDE /usr/local/include) 99e0197994SDmitri TikhonovENDIF() 100e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_LIB) 101cdf70916SDmitri Tikhonov SET(BORINGSSL_LIB /usr/local/lib) 102e0197994SDmitri TikhonovENDIF() 10350aadb33SDmitri Tikhonov 104461e84d8SAmol Deshpande 105461e84d8SAmol Deshpandeinclude_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} ) 1065d77f141SAmol Deshpandelink_directories( ${BORINGSSL_LIB} ) 107cdf70916SDmitri Tikhonov 10850aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON) 10950aadb33SDmitri Tikhonovinclude_directories( include ) 11050aadb33SDmitri Tikhonov 11150aadb33SDmitri TikhonovIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 11250aadb33SDmitri Tikhonov # Find libevent on FreeBSD: 11350aadb33SDmitri Tikhonov include_directories( /usr/local/include ) 11450aadb33SDmitri Tikhonov link_directories( /usr/local/lib ) 11550aadb33SDmitri TikhonovENDIF() 11650aadb33SDmitri Tikhonov 117b93f59beSBob Perper 11846a5b669SDmitri TikhonovIF (NOT MSVC) 119c51ce338SDmitri Tikhonovadd_executable(http_client 120c51ce338SDmitri Tikhonov test/http_client.c 121c51ce338SDmitri Tikhonov test/prog.c 122c51ce338SDmitri Tikhonov test/test_common.c 123c51ce338SDmitri Tikhonov) 12414931b3aSBob Perpertarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m) 12550aadb33SDmitri Tikhonov 1265d77f141SAmol Deshpande#MSVC 127461e84d8SAmol DeshpandeELSE() 128461e84d8SAmol Deshpandeadd_executable(http_client 129461e84d8SAmol Deshpande test/http_client.c 130461e84d8SAmol Deshpande test/prog.c 131461e84d8SAmol Deshpande wincompat/test_common_win.c 132461e84d8SAmol Deshpande wincompat/getopt.c 133461e84d8SAmol Deshpande wincompat/getopt1.c 134461e84d8SAmol Deshpande) 135461e84d8SAmol Deshpande 136b93f59beSBob Perpertarget_link_libraries(http_client 1375d77f141SAmol Deshpande debug $(SolutionDir)src/liblsquic/debug/lsquic.lib 1385d77f141SAmol Deshpande debug ${VCPKG_BASE_DIR}/debug/lib/event.lib 1395d77f141SAmol Deshpande debug ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib 140b5d685fcSBob Perper debug ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib 141b5d685fcSBob Perper debug ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib 1425d77f141SAmol Deshpande ws2_32 1435d77f141SAmol Deshpande optimized $(SolutionDir)src/liblsquic/release/lsquic.lib 1445d77f141SAmol Deshpande optimized ${VCPKG_BASE_DIR}/lib/event.lib 1455d77f141SAmol Deshpande optimized ${VCPKG_BASE_DIR}/lib/zlib.lib 146b5d685fcSBob Perper optimized ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib 147b5d685fcSBob Perper optimized ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib 1485d77f141SAmol Deshpande ${FIULIB} ) 149461e84d8SAmol Deshpande 150461e84d8SAmol DeshpandeENDIF() 151461e84d8SAmol Deshpande 15214931b3aSBob Perper#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m) 15350aadb33SDmitri Tikhonov 15450aadb33SDmitri Tikhonovadd_subdirectory(src) 15550aadb33SDmitri Tikhonov 156bfc7bfd8SDmitri Tikhonovadd_subdirectory(test) 15750aadb33SDmitri Tikhonov 1587fbe101bSDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 1597fbe101bSDmitri Tikhonov # Our test framework relies on assertions, only compile if assertions are 1607fbe101bSDmitri Tikhonov # enabled. 1617fbe101bSDmitri Tikhonov # 1627fbe101bSDmitri Tikhonov enable_testing() 1637fbe101bSDmitri TikhonovENDIF() 1647fbe101bSDmitri Tikhonov 16550aadb33SDmitri Tikhonov 16650aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg) 167