CMakeLists.txt revision 7d09751d
17d09751dSDmitri Tikhonov# Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. 250aadb33SDmitri Tikhonovcmake_minimum_required(VERSION 2.8) 350aadb33SDmitri Tikhonov 450aadb33SDmitri Tikhonov 5b1af35d6SDmitri TikhonovPROJECT(lsquic C) 6461e84d8SAmol Deshpande 712693a01SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL "Linux") 812693a01SDmitri Tikhonov # If using older glibc, need to link with -lrt. See clock_getres(2). 912693a01SDmitri Tikhonov EXECUTE_PROCESS( 1012693a01SDmitri Tikhonov COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER} 1112693a01SDmitri Tikhonov OUTPUT_VARIABLE GLIBC_VERSION) 1212693a01SDmitri Tikhonov IF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17) 1312693a01SDmitri Tikhonov SET(LIBS ${LIBS} rt) 1412693a01SDmitri Tikhonov ENDIF() 15ccd74161SDmitri TikhonovENDIF() 16ccd74161SDmitri Tikhonov 171e75f938SDmitri TikhonovIF("${CMAKE_BUILD_TYPE}" STREQUAL "") 181e75f938SDmitri Tikhonov SET(CMAKE_BUILD_TYPE Debug) 1950aadb33SDmitri TikhonovENDIF() 2050aadb33SDmitri Tikhonov 211e75f938SDmitri TikhonovMESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 2250aadb33SDmitri Tikhonov 23662de5e1SDmitri TikhonovOPTION(LSQUIC_FIU "Use Fault Injection in Userspace (FIU)" OFF) 24662de5e1SDmitri Tikhonov 25a0e1aeeeSDmitri TikhonovIF (NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-DLSQUIC_DEBUG_NEXT_ADV_TICK") 26a0e1aeeeSDmitri Tikhonov SET(MY_CMAKE_FLAGS "-DLSQUIC_DEBUG_NEXT_ADV_TICK=1") 27a0e1aeeeSDmitri TikhonovENDIF() 28b93f59beSBob Perper 2946a5b669SDmitri TikhonovIF (NOT MSVC) 30461e84d8SAmol Deshpande 3150aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter") 3250aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer") 335392f7a3SLiteSpeed TechINCLUDE(CheckCCompilerFlag) 345392f7a3SLiteSpeed TechCHECK_C_COMPILER_FLAG(-Wno-implicit-fallthrough HAS_NO_IMPLICIT_FALLTHROUGH) 355392f7a3SLiteSpeed TechIF (HAS_NO_IMPLICIT_FALLTHROUGH) 365392f7a3SLiteSpeed Tech SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-implicit-fallthrough") 375392f7a3SLiteSpeed TechENDIF() 3850aadb33SDmitri Tikhonov 39e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3) 4050aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers") 4150aadb33SDmitri TikhonovENDIF() 425392f7a3SLiteSpeed Tech 43662de5e1SDmitri TikhonovIF(LSQUIC_FIU) 44662de5e1SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 45662de5e1SDmitri Tikhonov SET(LIBS ${LIBS} fiu) 46662de5e1SDmitri TikhonovENDIF() 47662de5e1SDmitri Tikhonov 481e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug") 4950aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3") 505392f7a3SLiteSpeed Tech SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror") 51db8ac9eeSDmitri Tikhonov IF(CMAKE_C_COMPILER MATCHES "clang" AND 5203e6b668SDmitri Tikhonov NOT "$ENV{TRAVIS}" MATCHES "^true$" AND 5303e6b668SDmitri Tikhonov NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize") 5450aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address") 55d6937ddcSinitlife SET(LIBS ${LIBS} -fsanitize=address) 5650aadb33SDmitri Tikhonov ENDIF() 575392f7a3SLiteSpeed Tech # Uncomment to enable cleartext protocol mode (no crypto): 585392f7a3SLiteSpeed Tech #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1") 5950aadb33SDmitri TikhonovELSE() 6050aadb33SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0") 6150aadb33SDmitri Tikhonov # Comment out the following line to compile out debug messages: 6250aadb33SDmitri Tikhonov #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 6350aadb33SDmitri TikhonovENDIF() 6450aadb33SDmitri Tikhonov 6567b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1) 6667b0dc15SDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg") 6767b0dc15SDmitri TikhonovENDIF() 6867b0dc15SDmitri Tikhonov 6916a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1) 7016a9b66aSDmitri Tikhonov SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage") 7116a9b66aSDmitri TikhonovENDIF() 7216a9b66aSDmitri Tikhonov 7350aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address") 7450aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is ON") 7550aadb33SDmitri TikhonovELSE() 7650aadb33SDmitri Tikhonov MESSAGE(STATUS "AddressSanitizer is OFF") 7750aadb33SDmitri TikhonovENDIF() 7850aadb33SDmitri Tikhonov 79461e84d8SAmol Deshpande#MSVC 80461e84d8SAmol DeshpandeELSE() 812d296031SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4214") # nonstandard extension used: bit field types other than int 82461e84d8SAmol 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") 831e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug") 84b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od") 85461e84d8SAmol Deshpande #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1") 86ccd74161SDmitri Tikhonov #SET(LIBS ${LIBS} fiu) 87461e84d8SAmol DeshpandeELSE() 88b5d685fcSBob Perper SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox") 89461e84d8SAmol Deshpande # Comment out the following line to compile out debug messages: 90461e84d8SAmol Deshpande #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO") 91461e84d8SAmol DeshpandeENDIF() 92461e84d8SAmol Deshpande 93461e84d8SAmol DeshpandeENDIF() #MSVC 94461e84d8SAmol Deshpande 9550aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}") 9650aadb33SDmitri Tikhonov 9750aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") 9850aadb33SDmitri Tikhonov 998ca33e0eSDmitri TikhonovIF (NOT DEFINED BORINGSSL_INCLUDE AND DEFINED BORINGSSL_DIR) 1008ca33e0eSDmitri Tikhonov FIND_PATH(BORINGSSL_INCLUDE NAMES openssl/ssl.h 1018ca33e0eSDmitri Tikhonov PATHS ${BORINGSSL_DIR}/include 1028ca33e0eSDmitri Tikhonov NO_DEFAULT_PATH) 1038ca33e0eSDmitri TikhonovENDIF() 104b1af35d6SDmitri Tikhonov# This must be done before adding other include directories to take 105b1af35d6SDmitri Tikhonov# precedence over header files from other SSL installs. 1068ca33e0eSDmitri Tikhonov 1078ca33e0eSDmitri TikhonovIF (BORINGSSL_INCLUDE) 1088ca33e0eSDmitri Tikhonov MESSAGE(STATUS "BoringSSL include directory ${BORINGSSL_INCLUDE}") 1098ca33e0eSDmitri Tikhonov INCLUDE_DIRECTORIES(${BORINGSSL_INCLUDE}) 110b1af35d6SDmitri TikhonovELSE() 111b1af35d6SDmitri Tikhonov MESSAGE(FATAL_ERROR "BoringSSL headers not found") 112e0197994SDmitri TikhonovENDIF() 11350aadb33SDmitri Tikhonov 1148ca33e0eSDmitri TikhonovIF (NOT DEFINED BORINGSSL_LIB AND DEFINED BORINGSSL_DIR) 1158ca33e0eSDmitri Tikhonov FOREACH(LIB_NAME ssl crypto decrepit) 1168ca33e0eSDmitri Tikhonov IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 1178ca33e0eSDmitri Tikhonov FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 1188ca33e0eSDmitri Tikhonov NAMES ${LIB_NAME} 1198ca33e0eSDmitri Tikhonov PATHS ${BORINGSSL_DIR}/${LIB_NAME} 1208ca33e0eSDmitri Tikhonov PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo 1218ca33e0eSDmitri Tikhonov NO_DEFAULT_PATH) 1228ca33e0eSDmitri Tikhonov ELSE() 1238ca33e0eSDmitri Tikhonov FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 1248ca33e0eSDmitri Tikhonov NAMES lib${LIB_NAME}.a 1258ca33e0eSDmitri Tikhonov PATHS ${BORINGSSL_DIR}/${LIB_NAME} 1268ca33e0eSDmitri Tikhonov NO_DEFAULT_PATH) 1278ca33e0eSDmitri Tikhonov ENDIF() 1288ca33e0eSDmitri Tikhonov IF(BORINGSSL_LIB_${LIB_NAME}) 1298ca33e0eSDmitri Tikhonov MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}") 1308ca33e0eSDmitri Tikhonov ELSE() 1318ca33e0eSDmitri Tikhonov MESSAGE(STATUS "${LIB_NAME} library not found") 1328ca33e0eSDmitri Tikhonov ENDIF() 1338ca33e0eSDmitri Tikhonov ENDFOREACH() 1348ca33e0eSDmitri Tikhonov 1358ca33e0eSDmitri TikhonovELSE() 1368ca33e0eSDmitri Tikhonov 1378ca33e0eSDmitri Tikhonov 1388ca33e0eSDmitri Tikhonov FOREACH(LIB_NAME ssl crypto decrepit) 1398ca33e0eSDmitri Tikhonov IF (CMAKE_SYSTEM_NAME STREQUAL Windows) 1408ca33e0eSDmitri Tikhonov FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 1418ca33e0eSDmitri Tikhonov NAMES ${LIB_NAME} 1428ca33e0eSDmitri Tikhonov PATHS ${BORINGSSL_LIB} 1438ca33e0eSDmitri Tikhonov PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo 1448ca33e0eSDmitri Tikhonov NO_DEFAULT_PATH) 1458ca33e0eSDmitri Tikhonov ELSE() 1468ca33e0eSDmitri Tikhonov FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME} 1478ca33e0eSDmitri Tikhonov NAMES lib${LIB_NAME}.a 1488ca33e0eSDmitri Tikhonov PATHS ${BORINGSSL_LIB} 1498ca33e0eSDmitri Tikhonov NO_DEFAULT_PATH) 1508ca33e0eSDmitri Tikhonov ENDIF() 1518ca33e0eSDmitri Tikhonov IF(BORINGSSL_LIB_${LIB_NAME}) 1528ca33e0eSDmitri Tikhonov MESSAGE(STATUS "Found ${BORINGSSL_LIB} library: ${BORINGSSL_LIB_${LIB_NAME}}") 1538ca33e0eSDmitri Tikhonov ELSE() 1548ca33e0eSDmitri Tikhonov MESSAGE(STATUS "${BORINGSSL_LIB} library not found") 1558ca33e0eSDmitri Tikhonov ENDIF() 1568ca33e0eSDmitri Tikhonov ENDFOREACH() 1578ca33e0eSDmitri Tikhonov#endif 158461e84d8SAmol Deshpande 1598ca33e0eSDmitri TikhonovENDIF() 1608ca33e0eSDmitri Tikhonov 1618ca33e0eSDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON) 1628ca33e0eSDmitri TikhonovINCLUDE_DIRECTORIES(include src/lshpack) 163b1af35d6SDmitri TikhonovIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") 16450aadb33SDmitri Tikhonov # Find libevent on FreeBSD: 1658ca33e0eSDmitri Tikhonov include_directories( /usr/local/include ) 1668ca33e0eSDmitri Tikhonov link_directories( /usr/local/lib ) 167b1af35d6SDmitri TikhonovENDIF() 168b1af35d6SDmitri Tikhonov 169b1af35d6SDmitri Tikhonov# Find zlib and libevent header files and library files 170b1af35d6SDmitri Tikhonov# TODO: libevent is not strictly necessary to build the library. 171b1af35d6SDmitri TikhonovFIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h) 172b1af35d6SDmitri TikhonovIF (ZLIB_INCLUDE_DIR) 173b1af35d6SDmitri Tikhonov INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) 174b1af35d6SDmitri TikhonovELSE() 175b1af35d6SDmitri Tikhonov MESSAGE(FATAL_ERROR "zlib.h was not found") 176b1af35d6SDmitri TikhonovENDIF() 177b1af35d6SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL Windows) 178b1af35d6SDmitri Tikhonov FIND_LIBRARY(ZLIB_LIB zlib) 179b1af35d6SDmitri TikhonovELSEIF(CMAKE_SYSTEM_NAME STREQUAL Darwin) 180b1af35d6SDmitri Tikhonov # XXX somehow FIND_LIBRARY() does not find zlib on Travis? 181b1af35d6SDmitri Tikhonov SET(ZLIB_LIB z) 182b1af35d6SDmitri TikhonovELSE() 183b1af35d6SDmitri Tikhonov FIND_LIBRARY(ZLIB_LIB libz.a) 184b1af35d6SDmitri TikhonovENDIF() 185b1af35d6SDmitri TikhonovIF(ZLIB_LIB) 186b1af35d6SDmitri Tikhonov MESSAGE(STATUS "Found zlib: ${ZLIB_LIB}") 187b1af35d6SDmitri TikhonovELSE() 188b1af35d6SDmitri Tikhonov MESSAGE(STATUS "zlib not found") 189b1af35d6SDmitri TikhonovENDIF() 190b1af35d6SDmitri TikhonovFIND_PATH(EVENT_INCLUDE_DIR NAMES event2/event.h) 191b1af35d6SDmitri TikhonovIF (EVENT_INCLUDE_DIR) 192b1af35d6SDmitri Tikhonov INCLUDE_DIRECTORIES(${EVENT_INCLUDE_DIR}) 193b1af35d6SDmitri TikhonovELSE() 194b1af35d6SDmitri Tikhonov MESSAGE(FATAL_ERROR "event2/event.h was not found") 195b1af35d6SDmitri TikhonovENDIF() 196b1af35d6SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL Windows) 197b1af35d6SDmitri Tikhonov FIND_LIBRARY(EVENT_LIB event) 198b1af35d6SDmitri TikhonovELSE() 199747be414SDmitri Tikhonov FIND_LIBRARY(EVENT_LIB libevent.a) 200747be414SDmitri Tikhonov IF(NOT EVENT_LIB) 201747be414SDmitri Tikhonov FIND_LIBRARY(EVENT_LIB libevent.so) 202747be414SDmitri Tikhonov ENDIF() 203b1af35d6SDmitri TikhonovENDIF() 204b1af35d6SDmitri TikhonovIF(EVENT_LIB) 205b1af35d6SDmitri Tikhonov MESSAGE(STATUS "Found event: ${EVENT_LIB}") 206b1af35d6SDmitri TikhonovELSE() 207b1af35d6SDmitri Tikhonov MESSAGE(STATUS "libevent not found") 20850aadb33SDmitri TikhonovENDIF() 20950aadb33SDmitri Tikhonov 2105392f7a3SLiteSpeed Techadd_executable(http_server test/http_server.c test/prog.c test/test_common.c test/test_cert.c) 2110adf085aSDmitri Tikhonovadd_executable(md5_server test/md5_server.c test/prog.c test/test_common.c test/test_cert.c) 2120adf085aSDmitri Tikhonovadd_executable(md5_client test/md5_client.c test/prog.c test/test_common.c test/test_cert.c) 2130adf085aSDmitri Tikhonovadd_executable(echo_server test/echo_server.c test/prog.c test/test_common.c test/test_cert.c) 2140adf085aSDmitri Tikhonovadd_executable(echo_client test/echo_client.c test/prog.c test/test_common.c test/test_cert.c) 2155392f7a3SLiteSpeed Tech 2168ca33e0eSDmitri Tikhonov 2178ca33e0eSDmitri TikhonovSET(LIBS lsquic ${EVENT_LIB} ${BORINGSSL_LIB_ssl} ${BORINGSSL_LIB_crypto} ${ZLIB_LIB} ${LIBS}) 218b93f59beSBob Perper 21946a5b669SDmitri TikhonovIF (NOT MSVC) 2205392f7a3SLiteSpeed Tech 221c51ce338SDmitri Tikhonovadd_executable(http_client 222c51ce338SDmitri Tikhonov test/http_client.c 223c51ce338SDmitri Tikhonov test/prog.c 224c51ce338SDmitri Tikhonov test/test_common.c 2255392f7a3SLiteSpeed Tech test/test_cert.c 226c51ce338SDmitri Tikhonov) 2278ca33e0eSDmitri TikhonovLIST(APPEND LIBS pthread m) 22850aadb33SDmitri Tikhonov 2295d77f141SAmol Deshpande#MSVC 230461e84d8SAmol DeshpandeELSE() 2315392f7a3SLiteSpeed Tech 232461e84d8SAmol Deshpandeadd_executable(http_client 233461e84d8SAmol Deshpande test/http_client.c 234461e84d8SAmol Deshpande test/prog.c 235db236e90SDmitri Tikhonov test/test_common.c 236461e84d8SAmol Deshpande wincompat/getopt.c 237461e84d8SAmol Deshpande wincompat/getopt1.c 238461e84d8SAmol Deshpande) 2398ca33e0eSDmitri TikhonovLIST(APPEND LIBS ws2_32) 240461e84d8SAmol Deshpande 241461e84d8SAmol DeshpandeENDIF() 242461e84d8SAmol Deshpande 2438ca33e0eSDmitri TikhonovTARGET_LINK_LIBRARIES(http_client ${LIBS}) 2445392f7a3SLiteSpeed TechTARGET_LINK_LIBRARIES(http_server ${LIBS}) 2450adf085aSDmitri TikhonovTARGET_LINK_LIBRARIES(md5_server ${LIBS}) 2460adf085aSDmitri TikhonovTARGET_LINK_LIBRARIES(md5_client ${LIBS}) 2470adf085aSDmitri TikhonovTARGET_LINK_LIBRARIES(echo_server ${LIBS}) 2480adf085aSDmitri TikhonovTARGET_LINK_LIBRARIES(echo_client ${LIBS}) 24950aadb33SDmitri Tikhonov 25050aadb33SDmitri Tikhonovadd_subdirectory(src) 25150aadb33SDmitri Tikhonov 252bfc7bfd8SDmitri Tikhonovadd_subdirectory(test) 25350aadb33SDmitri Tikhonov 2545392f7a3SLiteSpeed TechIF(CMAKE_BUILD_TYPE STREQUAL "Debug") 2557fbe101bSDmitri Tikhonov # Our test framework relies on assertions, only compile if assertions are 2567fbe101bSDmitri Tikhonov # enabled. 2577fbe101bSDmitri Tikhonov # 2587fbe101bSDmitri Tikhonov enable_testing() 2597fbe101bSDmitri TikhonovENDIF() 2607fbe101bSDmitri Tikhonov 26150aadb33SDmitri Tikhonov 26250aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg) 263