CMakeLists.txt revision 461e84d8
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 7461e84d8SAmol DeshpandeIF (NOT (CMAKE_C_COMPILER MATCHES "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 31461e84d8SAmol DeshpandeIF (NOT (CMAKE_C_COMPILER MATCHES "MSVC")) 32461e84d8SAmol Deshpande 3350aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 3450aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 3550aadb33SDmitri Tikhonov 36e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 3750aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 3850aadb33SDmitri TikhonovENDIF() 3950aadb33SDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 4050aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 4150aadb33SDmitri Tikhonov # -Werror is used to force us to fix warnings early. 4250aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror") 4350aadb33SDmitri Tikhonov IF(CMAKE_C_COMPILER MATCHES "clang") 4450aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 4550aadb33SDmitri Tikhonov ENDIF() 4650aadb33SDmitri Tikhonov # Uncomment to enable fault injection testing via libfiu: 4750aadb33SDmitri Tikhonov #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 4850aadb33SDmitri Tikhonov #SET (FIULIB "fiu") 4950aadb33SDmitri TikhonovELSE() 5050aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 5150aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 5250aadb33SDmitri Tikhonov # Comment out the following line to compile out debug messages: 5350aadb33SDmitri Tikhonov #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 5450aadb33SDmitri TikhonovENDIF() 5550aadb33SDmitri Tikhonov 5667b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1) 5767b0dc15SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 5867b0dc15SDmitri TikhonovENDIF() 5967b0dc15SDmitri Tikhonov 6050aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 6150aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is ON") 6250aadb33SDmitri TikhonovELSE() 6350aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is OFF") 6450aadb33SDmitri TikhonovENDIF() 6550aadb33SDmitri Tikhonov 66461e84d8SAmol Deshpande#MSVC 67461e84d8SAmol DeshpandeELSE() 68461e84d8SAmol 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") 69461e84d8SAmol DeshpandeIF(DEVEL_MODE EQUAL 1) 70461e84d8SAmol Deshpande SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od ") 71461e84d8SAmol Deshpande #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 72461e84d8SAmol Deshpande #SET (FIULIB "fiu") 73461e84d8SAmol DeshpandeELSE() 74461e84d8SAmol Deshpande SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -OX") 75461e84d8SAmol Deshpande SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG") 76461e84d8SAmol Deshpande # Comment out the following line to compile out debug messages: 77461e84d8SAmol Deshpande #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 78461e84d8SAmol DeshpandeENDIF() 79461e84d8SAmol Deshpande 80461e84d8SAmol DeshpandeSET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include) 81461e84d8SAmol DeshpandeSET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include ) 82461e84d8SAmol Deshpande 83461e84d8SAmol DeshpandeIF(CMAKE_BUILD_TYPE MATCHES "Debug") 84461e84d8SAmol DeshpandeSET (BORINGSSL_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/ssl ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/x64/debug) 85461e84d8SAmol DeshpandeSET (VCPKG_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/lib) 86461e84d8SAmol DeshpandeSET (ZLIB_NAME "zlibd") 87461e84d8SAmol DeshpandeELSE() 88461e84d8SAmol DeshpandeSET (BORINGSSL_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/ssl ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/x64) 89461e84d8SAmol DeshpandeSET (VCPKG_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/debug/lib) 90461e84d8SAmol DeshpandeSET (ZLIB_NAME zlibd) 91461e84d8SAmol DeshpandeENDIF() 92461e84d8SAmol Deshpande 93461e84d8SAmol Deshpande 94461e84d8SAmol DeshpandeENDIF() #MSVC 95461e84d8SAmol Deshpande 9650aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 9750aadb33SDmitri Tikhonov 9850aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 9950aadb33SDmitri Tikhonov 100e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_INCLUDE) 101cdf70916SDmitri Tikhonov SET(BORINGSSL_INCLUDE /usr/local/include) 102e0197994SDmitri TikhonovENDIF() 103e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_LIB) 104cdf70916SDmitri Tikhonov SET(BORINGSSL_LIB /usr/local/lib) 105e0197994SDmitri TikhonovENDIF() 10650aadb33SDmitri Tikhonov 107461e84d8SAmol Deshpande 108461e84d8SAmol Deshpandeinclude_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} ) 109461e84d8SAmol Deshpandelink_directories( ${BORINGSSL_LIB} ${VCPKG_LIB} ) 110cdf70916SDmitri Tikhonov 11150aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON) 11250aadb33SDmitri Tikhonovinclude_directories( include ) 11350aadb33SDmitri Tikhonov 11450aadb33SDmitri TikhonovIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 11550aadb33SDmitri Tikhonov # Find libevent on FreeBSD: 11650aadb33SDmitri Tikhonov include_directories( /usr/local/include ) 11750aadb33SDmitri Tikhonov link_directories( /usr/local/lib ) 11850aadb33SDmitri TikhonovENDIF() 11950aadb33SDmitri Tikhonov 120461e84d8SAmol DeshpandeIF (NOT (CMAKE_C_COMPILER MATCHES "MSVC")) 121c51ce338SDmitri Tikhonovadd_executable(http_client 122c51ce338SDmitri Tikhonov test/http_client.c 123c51ce338SDmitri Tikhonov test/prog.c 124c51ce338SDmitri Tikhonov test/test_common.c 125c51ce338SDmitri Tikhonov) 126e0197994SDmitri Tikhonovtarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m) 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 136461e84d8SAmol Deshpandetarget_link_libraries(http_client lsquic event ssl crypto ${FIULIB} ${ZLIB_NAME} ws2_32) 137461e84d8SAmol Deshpande 138461e84d8SAmol DeshpandeENDIF() 139461e84d8SAmol Deshpande 140461e84d8SAmol Deshpande 14150aadb33SDmitri Tikhonov 14250aadb33SDmitri Tikhonovadd_subdirectory(src) 14350aadb33SDmitri Tikhonov 144bfc7bfd8SDmitri Tikhonovadd_subdirectory(test) 14550aadb33SDmitri Tikhonov 1467fbe101bSDmitri TikhonovIF(DEVEL_MODE EQUAL 1) 1477fbe101bSDmitri Tikhonov # Our test framework relies on assertions, only compile if assertions are 1487fbe101bSDmitri Tikhonov # enabled. 1497fbe101bSDmitri Tikhonov # 1507fbe101bSDmitri Tikhonov enable_testing() 1517fbe101bSDmitri TikhonovENDIF() 1527fbe101bSDmitri Tikhonov 15350aadb33SDmitri Tikhonov 15450aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg) 155