CMakeLists.txt revision ccd74161
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 20ccd74161SDmitri Tikhonov# If using older glibc, need to link with -lrt. See clock_getres(2). 21ccd74161SDmitri TikhonovEXECUTE_PROCESS( 22ccd74161SDmitri Tikhonov COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER} 23ccd74161SDmitri Tikhonov OUTPUT_VARIABLE GLIBC_VERSION) 24ccd74161SDmitri TikhonovIF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17) 25ccd74161SDmitri Tikhonov SET(LIBS ${LIBS} rt) 26ccd74161SDmitri TikhonovENDIF() 27ccd74161SDmitri Tikhonov 2850aadb33SDmitri Tikhonov# By default, we compile in development mode. To compile production code, 2950aadb33SDmitri Tikhonov# pass -DDEVEL_MODE=0 to cmake (before that, `make clean' and remove any 3050aadb33SDmitri Tikhonov# cmake cache files). 3150aadb33SDmitri Tikhonov# 3250aadb33SDmitri TikhonovIF(NOT DEFINED DEVEL_MODE) 3350aadb33SDmitri Tikhonov SET(DEVEL_MODE 1) 3450aadb33SDmitri TikhonovENDIF() 3550aadb33SDmitri Tikhonov 3650aadb33SDmitri Tikhonov 3750aadb33SDmitri TikhonovMESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}") 3850aadb33SDmitri Tikhonov 39b93f59beSBob Perper 4046a5b669SDmitri TikhonovIF (NOT MSVC) 41461e84d8SAmol Deshpande 4250aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 4350aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 4450aadb33SDmitri Tikhonov 45e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 4650aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 4750aadb33SDmitri TikhonovENDIF() 4850aadb33SDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 4950aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 50db8ac9eeSDmitri Tikhonov IF(CMAKE_C_COMPILER MATCHES "clang" AND 51db8ac9eeSDmitri Tikhonov NOT "$ENV{TRAVIS}" MATCHES "^true$") 5250aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 5350aadb33SDmitri Tikhonov ENDIF() 5450aadb33SDmitri Tikhonov # Uncomment to enable fault injection testing via libfiu: 5550aadb33SDmitri Tikhonov #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 56ccd74161SDmitri Tikhonov #SET(LIBS ${LIBS} fiu) 5750aadb33SDmitri TikhonovELSE() 5850aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 5950aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 6050aadb33SDmitri Tikhonov # Comment out the following line to compile out debug messages: 6150aadb33SDmitri Tikhonov #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 6250aadb33SDmitri TikhonovENDIF() 6350aadb33SDmitri Tikhonov 6467b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1) 6567b0dc15SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 6667b0dc15SDmitri TikhonovENDIF() 6767b0dc15SDmitri Tikhonov 6816a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1) 6916a9b66aSDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 7016a9b66aSDmitri TikhonovENDIF() 7116a9b66aSDmitri Tikhonov 7250aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 7350aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is ON") 7450aadb33SDmitri TikhonovELSE() 7550aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is OFF") 7650aadb33SDmitri TikhonovENDIF() 7750aadb33SDmitri Tikhonov 78461e84d8SAmol Deshpande#MSVC 79461e84d8SAmol DeshpandeELSE() 80461e84d8SAmol 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") 81461e84d8SAmol DeshpandeIF(DEVEL_MODE EQUAL 1) 82b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 83461e84d8SAmol Deshpande #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 84ccd74161SDmitri Tikhonov #SET(LIBS ${LIBS} fiu) 85461e84d8SAmol DeshpandeELSE() 86b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 87461e84d8SAmol Deshpande SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 88461e84d8SAmol Deshpande # Comment out the following line to compile out debug messages: 89461e84d8SAmol Deshpande #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 90461e84d8SAmol DeshpandeENDIF() 91461e84d8SAmol Deshpande 92461e84d8SAmol DeshpandeSET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include) 93461e84d8SAmol DeshpandeSET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include ) 94b5d685fcSBob Perperset (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl) 95461e84d8SAmol Deshpande 965d77f141SAmol DeshpandeSET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static) 97461e84d8SAmol Deshpande 98461e84d8SAmol DeshpandeENDIF() #MSVC 99461e84d8SAmol Deshpande 10050aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 10150aadb33SDmitri Tikhonov 10250aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 10350aadb33SDmitri Tikhonov 104e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_INCLUDE) 105cdf70916SDmitri Tikhonov SET(BORINGSSL_INCLUDE /usr/local/include) 106e0197994SDmitri TikhonovENDIF() 107e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_LIB) 108cdf70916SDmitri Tikhonov SET(BORINGSSL_LIB /usr/local/lib) 109e0197994SDmitri TikhonovENDIF() 11050aadb33SDmitri Tikhonov 111461e84d8SAmol Deshpande 112461e84d8SAmol Deshpandeinclude_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} ) 1135d77f141SAmol Deshpandelink_directories( ${BORINGSSL_LIB} ) 114cdf70916SDmitri Tikhonov 11550aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON) 11650aadb33SDmitri Tikhonovinclude_directories( include ) 11750aadb33SDmitri Tikhonov 11850aadb33SDmitri TikhonovIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 11950aadb33SDmitri Tikhonov # Find libevent on FreeBSD: 12050aadb33SDmitri Tikhonov include_directories( /usr/local/include ) 12150aadb33SDmitri Tikhonov link_directories( /usr/local/lib ) 12250aadb33SDmitri TikhonovENDIF() 12350aadb33SDmitri Tikhonov 124b93f59beSBob Perper 12546a5b669SDmitri TikhonovIF (NOT MSVC) 126c51ce338SDmitri Tikhonovadd_executable(http_client 127c51ce338SDmitri Tikhonov test/http_client.c 128c51ce338SDmitri Tikhonov test/prog.c 129c51ce338SDmitri Tikhonov test/test_common.c 130c51ce338SDmitri Tikhonov) 131ccd74161SDmitri Tikhonovtarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 13250aadb33SDmitri Tikhonov 1335d77f141SAmol Deshpande#MSVC 134461e84d8SAmol DeshpandeELSE() 135461e84d8SAmol Deshpandeadd_executable(http_client 136461e84d8SAmol Deshpande test/http_client.c 137461e84d8SAmol Deshpande test/prog.c 138db236e90SDmitri Tikhonov test/test_common.c 139461e84d8SAmol Deshpande wincompat/getopt.c 140461e84d8SAmol Deshpande wincompat/getopt1.c 141461e84d8SAmol Deshpande) 142461e84d8SAmol Deshpande 143b93f59beSBob Perpertarget_link_libraries(http_client 1445d77f141SAmol Deshpande debug $(SolutionDir)src/liblsquic/debug/lsquic.lib 1455d77f141SAmol Deshpande debug ${VCPKG_BASE_DIR}/debug/lib/event.lib 1465d77f141SAmol Deshpande debug ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib 147b5d685fcSBob Perper debug ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib 148b5d685fcSBob Perper debug ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib 1495d77f141SAmol Deshpande ws2_32 1505d77f141SAmol Deshpande optimized $(SolutionDir)src/liblsquic/release/lsquic.lib 1515d77f141SAmol Deshpande optimized ${VCPKG_BASE_DIR}/lib/event.lib 1525d77f141SAmol Deshpande optimized ${VCPKG_BASE_DIR}/lib/zlib.lib 153b5d685fcSBob Perper optimized ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib 154b5d685fcSBob Perper optimized ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib 155ccd74161SDmitri Tikhonov ${LIBS} ) 156461e84d8SAmol Deshpande 157461e84d8SAmol DeshpandeENDIF() 158461e84d8SAmol Deshpande 159ccd74161SDmitri Tikhonov#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 16050aadb33SDmitri Tikhonov 16150aadb33SDmitri Tikhonovadd_subdirectory(src) 16250aadb33SDmitri Tikhonov 163bfc7bfd8SDmitri Tikhonovadd_subdirectory(test) 16450aadb33SDmitri Tikhonov 1657fbe101bSDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 1667fbe101bSDmitri Tikhonov # Our test framework relies on assertions, only compile if assertions are 1677fbe101bSDmitri Tikhonov # enabled. 1687fbe101bSDmitri Tikhonov # 1697fbe101bSDmitri Tikhonov enable_testing() 1707fbe101bSDmitri TikhonovENDIF() 1717fbe101bSDmitri Tikhonov 17250aadb33SDmitri Tikhonov 17350aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg) 174