CMakeLists.txt revision 2d296031
1229fce07SDmitri Tikhonov# Copyright (c) 2017 - 2019 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 2012693a01SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL "Linux") 2112693a01SDmitri Tikhonov # If using older glibc, need to link with -lrt. See clock_getres(2). 2212693a01SDmitri Tikhonov EXECUTE_PROCESS( 2312693a01SDmitri Tikhonov COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER} 2412693a01SDmitri Tikhonov OUTPUT_VARIABLE GLIBC_VERSION) 2512693a01SDmitri Tikhonov IF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17) 2612693a01SDmitri Tikhonov SET(LIBS ${LIBS} rt) 2712693a01SDmitri Tikhonov ENDIF() 28ccd74161SDmitri TikhonovENDIF() 29ccd74161SDmitri Tikhonov 301e75f938SDmitri TikhonovIF("${CMAKE_BUILD_TYPE}" STREQUAL "") 311e75f938SDmitri Tikhonov SET(CMAKE_BUILD_TYPE Debug) 3250aadb33SDmitri TikhonovENDIF() 3350aadb33SDmitri Tikhonov 3450aadb33SDmitri Tikhonov 351e75f938SDmitri TikhonovMESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 3650aadb33SDmitri Tikhonov 37b93f59beSBob Perper 3846a5b669SDmitri TikhonovIF (NOT MSVC) 39461e84d8SAmol Deshpande 4050aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 4150aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 4250aadb33SDmitri Tikhonov 43e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 4450aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 4550aadb33SDmitri TikhonovENDIF() 461e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug") 4750aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 48db8ac9eeSDmitri Tikhonov IF(CMAKE_C_COMPILER MATCHES "clang" AND 49db8ac9eeSDmitri Tikhonov NOT "$ENV{TRAVIS}" MATCHES "^true$") 5050aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 5150aadb33SDmitri Tikhonov ENDIF() 5250aadb33SDmitri Tikhonov # Uncomment to enable fault injection testing via libfiu: 5350aadb33SDmitri Tikhonov #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 54ccd74161SDmitri Tikhonov #SET(LIBS ${LIBS} fiu) 5550aadb33SDmitri TikhonovELSE() 5650aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 5750aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 5850aadb33SDmitri Tikhonov # Comment out the following line to compile out debug messages: 5950aadb33SDmitri Tikhonov #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 6050aadb33SDmitri TikhonovENDIF() 6150aadb33SDmitri Tikhonov 6267b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1) 6367b0dc15SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 6467b0dc15SDmitri TikhonovENDIF() 6567b0dc15SDmitri Tikhonov 6616a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1) 6716a9b66aSDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 6816a9b66aSDmitri TikhonovENDIF() 6916a9b66aSDmitri Tikhonov 7050aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 7150aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is ON") 7250aadb33SDmitri TikhonovELSE() 7350aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is OFF") 7450aadb33SDmitri TikhonovENDIF() 7550aadb33SDmitri Tikhonov 76461e84d8SAmol Deshpande#MSVC 77461e84d8SAmol DeshpandeELSE() 782d296031SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4214") # nonstandard extension used: bit field types other than int 79461e84d8SAmol 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") 801e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug") 81b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 82461e84d8SAmol Deshpande #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 83ccd74161SDmitri Tikhonov #SET(LIBS ${LIBS} fiu) 84461e84d8SAmol DeshpandeELSE() 85b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 86461e84d8SAmol Deshpande SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 87461e84d8SAmol Deshpande # Comment out the following line to compile out debug messages: 88461e84d8SAmol Deshpande #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 89461e84d8SAmol DeshpandeENDIF() 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 1052d296031SDmitri Tikhonovinclude_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE}) 1065d77f141SAmol Deshpandelink_directories( ${BORINGSSL_LIB} ) 107cdf70916SDmitri Tikhonov 10850aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON) 10914e3680dSDmitri Tikhonovinclude_directories( include src/lshpack) 110083b5939SZhang ChiIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 11150aadb33SDmitri Tikhonov # Find libevent on FreeBSD: 11250aadb33SDmitri Tikhonov include_directories( /usr/local/include ) 11350aadb33SDmitri Tikhonov link_directories( /usr/local/lib ) 11450aadb33SDmitri TikhonovENDIF() 11550aadb33SDmitri Tikhonov 116b93f59beSBob Perper 11746a5b669SDmitri TikhonovIF (NOT MSVC) 118c51ce338SDmitri Tikhonovadd_executable(http_client 119c51ce338SDmitri Tikhonov test/http_client.c 120c51ce338SDmitri Tikhonov test/prog.c 121c51ce338SDmitri Tikhonov test/test_common.c 122c51ce338SDmitri Tikhonov) 123ccd74161SDmitri Tikhonovtarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 12450aadb33SDmitri Tikhonov 1255d77f141SAmol Deshpande#MSVC 126461e84d8SAmol DeshpandeELSE() 127461e84d8SAmol Deshpandeadd_executable(http_client 128461e84d8SAmol Deshpande test/http_client.c 129461e84d8SAmol Deshpande test/prog.c 130db236e90SDmitri Tikhonov test/test_common.c 131461e84d8SAmol Deshpande wincompat/getopt.c 132461e84d8SAmol Deshpande wincompat/getopt1.c 133461e84d8SAmol Deshpande) 134461e84d8SAmol Deshpande 135b93f59beSBob Perpertarget_link_libraries(http_client 1362d296031SDmitri Tikhonov lsquic 1372d296031SDmitri Tikhonov ${VCPKG_LIB}/event.lib 1382d296031SDmitri Tikhonov ${VCPKG_LIB}/zlib.lib 1392d296031SDmitri Tikhonov ${BORINGSSL_LIB}/ssl.lib 1402d296031SDmitri Tikhonov ${BORINGSSL_LIB}/crypto.lib 1415d77f141SAmol Deshpande ws2_32 142ccd74161SDmitri Tikhonov ${LIBS} ) 143461e84d8SAmol Deshpande 144461e84d8SAmol DeshpandeENDIF() 145461e84d8SAmol Deshpande 146ccd74161SDmitri Tikhonov#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) 14750aadb33SDmitri Tikhonov 14850aadb33SDmitri Tikhonovadd_subdirectory(src) 14950aadb33SDmitri Tikhonov 150bfc7bfd8SDmitri Tikhonovadd_subdirectory(test) 15150aadb33SDmitri Tikhonov 1521e75f938SDmitri TikhonovIF(NOT (CMAKE_C_FLAGS MATCHES "-DNDEBUG")) 1537fbe101bSDmitri Tikhonov # Our test framework relies on assertions, only compile if assertions are 1547fbe101bSDmitri Tikhonov # enabled. 1557fbe101bSDmitri Tikhonov # 1567fbe101bSDmitri Tikhonov enable_testing() 1577fbe101bSDmitri TikhonovENDIF() 1587fbe101bSDmitri Tikhonov 15950aadb33SDmitri Tikhonov 16050aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg) 161