CMakeLists.txt revision 5d77f141
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
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)
74461e84d8SAmol Deshpande    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()
78461e84d8SAmol Deshpande    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 )
86461e84d8SAmol Deshpande
875d77f141SAmol DeshpandeSET (VCPKG_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows-static)
885d77f141SAmol Deshpandeset (BORINGSSL_BASE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../boringssl/build/x64)
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
116461e84d8SAmol DeshpandeIF (NOT (CMAKE_C_COMPILER MATCHES "MSVC"))
117c51ce338SDmitri Tikhonovadd_executable(http_client
118c51ce338SDmitri Tikhonov    test/http_client.c
119c51ce338SDmitri Tikhonov    test/prog.c
120c51ce338SDmitri Tikhonov    test/test_common.c
121c51ce338SDmitri Tikhonov)
122e0197994SDmitri Tikhonovtarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
12350aadb33SDmitri Tikhonov
1245d77f141SAmol Deshpande#MSVC
125461e84d8SAmol DeshpandeELSE()
126461e84d8SAmol Deshpandeadd_executable(http_client
127461e84d8SAmol Deshpande    test/http_client.c
128461e84d8SAmol Deshpande    test/prog.c
129461e84d8SAmol Deshpande    wincompat/test_common_win.c
130461e84d8SAmol Deshpande    wincompat/getopt.c
131461e84d8SAmol Deshpande    wincompat/getopt1.c
132461e84d8SAmol Deshpande)
133461e84d8SAmol Deshpande
1345d77f141SAmol Deshpandetarget_link_libraries(http_client 
1355d77f141SAmol Deshpande		debug  $(SolutionDir)src/liblsquic/debug/lsquic.lib
1365d77f141SAmol Deshpande		debug  ${VCPKG_BASE_DIR}/debug/lib/event.lib
1375d77f141SAmol Deshpande		debug  ${VCPKG_BASE_DIR}/debug/lib/zlibd.lib
1385d77f141SAmol Deshpande		debug  ${BORINGSSL_BASE_LIB_DIR}/debug/ssl.lib 
1395d77f141SAmol Deshpande		debug  ${BORINGSSL_BASE_LIB_DIR}/debug/crypto.lib
1405d77f141SAmol Deshpande		ws2_32
1415d77f141SAmol Deshpande		optimized  $(SolutionDir)src/liblsquic/release/lsquic.lib
1425d77f141SAmol Deshpande		optimized  ${VCPKG_BASE_DIR}/lib/event.lib
1435d77f141SAmol Deshpande		optimized  ${VCPKG_BASE_DIR}/lib/zlib.lib
1445d77f141SAmol Deshpande		optimized  ${BORINGSSL_BASE_LIB_DIR}/ssl.lib 
1455d77f141SAmol Deshpande		optimized  ${BORINGSSL_BASE_LIB_DIR}/crypto.lib
1465d77f141SAmol Deshpande		${FIULIB} )
147461e84d8SAmol Deshpande
148461e84d8SAmol DeshpandeENDIF()
149461e84d8SAmol Deshpande
150461e84d8SAmol Deshpande
15150aadb33SDmitri Tikhonov
15250aadb33SDmitri Tikhonovadd_subdirectory(src)
15350aadb33SDmitri Tikhonov
154bfc7bfd8SDmitri Tikhonovadd_subdirectory(test)
15550aadb33SDmitri Tikhonov
1567fbe101bSDmitri TikhonovIF(DEVEL_MODE EQUAL 1)
1577fbe101bSDmitri Tikhonov    # Our test framework relies on assertions, only compile if assertions are
1587fbe101bSDmitri Tikhonov    # enabled.
1597fbe101bSDmitri Tikhonov    #
1607fbe101bSDmitri Tikhonov    enable_testing()
1617fbe101bSDmitri TikhonovENDIF()
1627fbe101bSDmitri Tikhonov
16350aadb33SDmitri Tikhonov
16450aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg)
165