CMakeLists.txt revision db236e90
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")
42db8ac9eeSDmitri Tikhonov    IF(CMAKE_C_COMPILER MATCHES "clang" AND
43db8ac9eeSDmitri Tikhonov                        NOT "$ENV{TRAVIS}" MATCHES "^true$")
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
6016a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1)
6116a9b66aSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
6216a9b66aSDmitri TikhonovENDIF()
6316a9b66aSDmitri Tikhonov
6450aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
6550aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is ON")
6650aadb33SDmitri TikhonovELSE()
6750aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is OFF")
6850aadb33SDmitri TikhonovENDIF()
6950aadb33SDmitri Tikhonov
70461e84d8SAmol Deshpande#MSVC
71461e84d8SAmol DeshpandeELSE()
72461e84d8SAmol 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")
73461e84d8SAmol DeshpandeIF(DEVEL_MODE EQUAL 1)
74b5d685fcSBob Perper    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
75461e84d8SAmol Deshpande    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
76461e84d8SAmol Deshpande    #SET (FIULIB "fiu")
77461e84d8SAmol DeshpandeELSE()
78b5d685fcSBob Perper    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
79461e84d8SAmol Deshpande    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
80461e84d8SAmol Deshpande    # Comment out the following line to compile out debug messages:
81461e84d8SAmol Deshpande    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
82461e84d8SAmol DeshpandeENDIF()
83461e84d8SAmol Deshpande
84461e84d8SAmol DeshpandeSET (BORINGSSL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/include)
85461e84d8SAmol DeshpandeSET (VCPKG_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static/include )
86b5d685fcSBob Perperset (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl)
87461e84d8SAmol Deshpande
885d77f141SAmol DeshpandeSET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static)
89461e84d8SAmol Deshpande
90461e84d8SAmol DeshpandeENDIF() #MSVC
91461e84d8SAmol Deshpande
9250aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
9350aadb33SDmitri Tikhonov
9450aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
9550aadb33SDmitri Tikhonov
96e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_INCLUDE)
97cdf70916SDmitri Tikhonov    SET(BORINGSSL_INCLUDE /usr/local/include)
98e0197994SDmitri TikhonovENDIF()
99e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_LIB)
100cdf70916SDmitri Tikhonov    SET(BORINGSSL_LIB /usr/local/lib)
101e0197994SDmitri TikhonovENDIF()
10250aadb33SDmitri Tikhonov
103461e84d8SAmol Deshpande
104461e84d8SAmol Deshpandeinclude_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE} )
1055d77f141SAmol Deshpandelink_directories( ${BORINGSSL_LIB}  )
106cdf70916SDmitri Tikhonov
10750aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON)
10850aadb33SDmitri Tikhonovinclude_directories( include )
10950aadb33SDmitri Tikhonov
11050aadb33SDmitri TikhonovIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
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)
12314931b3aSBob Perpertarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} 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
1365d77f141SAmol Deshpande		debug  $(SolutionDir)src/liblsquic/debug/lsquic.lib
1375d77f141SAmol Deshpande		debug  ${VCPKG_BASE_DIR}/debug/lib/event.lib
1385d77f141SAmol Deshpande		debug  ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib
139b5d685fcSBob Perper		debug  ${BORINGSSL_BASE_LIB_DIR}/ssl/debug/ssl.lib
140b5d685fcSBob Perper		debug  ${BORINGSSL_BASE_LIB_DIR}/crypto/debug/crypto.lib
1415d77f141SAmol Deshpande		ws2_32
1425d77f141SAmol Deshpande		optimized  $(SolutionDir)src/liblsquic/release/lsquic.lib
1435d77f141SAmol Deshpande		optimized  ${VCPKG_BASE_DIR}/lib/event.lib
1445d77f141SAmol Deshpande		optimized  ${VCPKG_BASE_DIR}/lib/zlib.lib
145b5d685fcSBob Perper		optimized  ${BORINGSSL_BASE_LIB_DIR}/ssl/release/ssl.lib
146b5d685fcSBob Perper		optimized  ${BORINGSSL_BASE_LIB_DIR}/crypto/release/crypto.lib
1475d77f141SAmol Deshpande		${FIULIB} )
148461e84d8SAmol Deshpande
149461e84d8SAmol DeshpandeENDIF()
150461e84d8SAmol Deshpande
15114931b3aSBob Perper#target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
15250aadb33SDmitri Tikhonov
15350aadb33SDmitri Tikhonovadd_subdirectory(src)
15450aadb33SDmitri Tikhonov
155bfc7bfd8SDmitri Tikhonovadd_subdirectory(test)
15650aadb33SDmitri Tikhonov
1577fbe101bSDmitri TikhonovIF(DEVEL_MODE EQUAL 1)
1587fbe101bSDmitri Tikhonov    # Our test framework relies on assertions, only compile if assertions are
1597fbe101bSDmitri Tikhonov    # enabled.
1607fbe101bSDmitri Tikhonov    #
1617fbe101bSDmitri Tikhonov    enable_testing()
1627fbe101bSDmitri TikhonovENDIF()
1637fbe101bSDmitri Tikhonov
16450aadb33SDmitri Tikhonov
16550aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg)
166