CMakeLists.txt revision e0197994
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
750aadb33SDmitri Tikhonov# We prefer clang
850aadb33SDmitri TikhonovIF(NOT ("${CMAKE_C_COMPILER}" MATCHES "ccc-analyzer" OR
950aadb33SDmitri Tikhonov        "${CMAKE_C_COMPILER}" MATCHES "gcc"          OR
1050aadb33SDmitri Tikhonov        "${CMAKE_C_COMPILER}" MATCHES "afl-gcc"))
1150aadb33SDmitri Tikhonov    FIND_PROGRAM(CLANG "clang")
1250aadb33SDmitri Tikhonov    IF(CLANG)
1350aadb33SDmitri Tikhonov        SET(CMAKE_C_COMPILER "${CLANG}")
1450aadb33SDmitri Tikhonov    ENDIF()
1550aadb33SDmitri TikhonovENDIF()
1650aadb33SDmitri Tikhonov
1750aadb33SDmitri Tikhonov# By default, we compile in development mode.  To compile production code,
1850aadb33SDmitri Tikhonov# pass -DDEVEL_MODE=0 to cmake (before that, `make clean' and remove any
1950aadb33SDmitri Tikhonov# cmake cache files).
2050aadb33SDmitri Tikhonov#
2150aadb33SDmitri TikhonovIF(NOT DEFINED DEVEL_MODE)
2250aadb33SDmitri Tikhonov    SET(DEVEL_MODE 1)
2350aadb33SDmitri TikhonovENDIF()
2450aadb33SDmitri Tikhonov
2550aadb33SDmitri Tikhonov
2650aadb33SDmitri TikhonovMESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}")
2750aadb33SDmitri Tikhonov
2850aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
2950aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
3050aadb33SDmitri Tikhonov
31e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
3250aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
3350aadb33SDmitri TikhonovENDIF()
3450aadb33SDmitri TikhonovIF(DEVEL_MODE EQUAL 1)
3550aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
3650aadb33SDmitri Tikhonov    # -Werror is used to force us to fix warnings early.
3750aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror")
3850aadb33SDmitri Tikhonov    IF(CMAKE_C_COMPILER MATCHES "clang")
3950aadb33SDmitri Tikhonov        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
4050aadb33SDmitri Tikhonov    ENDIF()
4150aadb33SDmitri Tikhonov    # Uncomment to enable fault injection testing via libfiu:
4250aadb33SDmitri Tikhonov    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
4350aadb33SDmitri Tikhonov    #SET (FIULIB "fiu")
4450aadb33SDmitri TikhonovELSE()
4550aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
4650aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
4750aadb33SDmitri Tikhonov    # Comment out the following line to compile out debug messages:
4850aadb33SDmitri Tikhonov    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
4950aadb33SDmitri TikhonovENDIF()
5050aadb33SDmitri Tikhonov
5150aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
5250aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is ON")
5350aadb33SDmitri TikhonovELSE()
5450aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is OFF")
5550aadb33SDmitri TikhonovENDIF()
5650aadb33SDmitri Tikhonov
5750aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
5850aadb33SDmitri Tikhonov
5950aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
6050aadb33SDmitri Tikhonov
61e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_INCLUDE)
62e0197994SDmitri Tikhonov    include_directories( /usr/local/lib )
63e0197994SDmitri TikhonovENDIF()
64e0197994SDmitri TikhonovIF(NOT DEFINED BORINGSSL_LIB)
65e0197994SDmitri Tikhonov    link_directories( /usr/local/include )
66e0197994SDmitri TikhonovENDIF()
6750aadb33SDmitri Tikhonov
6850aadb33SDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON)
6950aadb33SDmitri Tikhonovinclude_directories( include )
7050aadb33SDmitri Tikhonov
7150aadb33SDmitri TikhonovIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
7250aadb33SDmitri Tikhonov    # Find libevent on FreeBSD:
7350aadb33SDmitri Tikhonov    include_directories( /usr/local/include )
7450aadb33SDmitri Tikhonov    link_directories( /usr/local/lib )
7550aadb33SDmitri TikhonovENDIF()
7650aadb33SDmitri Tikhonov
7750aadb33SDmitri Tikhonovadd_executable(http_client test/http_client.c test/prog.c test/test_common.c test/test_cert.c)
7850aadb33SDmitri Tikhonov
79e0197994SDmitri Tikhonovtarget_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
8050aadb33SDmitri Tikhonov
8150aadb33SDmitri Tikhonovadd_subdirectory(src)
8250aadb33SDmitri Tikhonov
8350aadb33SDmitri TikhonovIF(DEVEL_MODE EQUAL 1)
8450aadb33SDmitri Tikhonov    # Our test framework relies on assertions, only compile if assertions are
8550aadb33SDmitri Tikhonov    # enabled.
8650aadb33SDmitri Tikhonov    #
8750aadb33SDmitri Tikhonov    add_subdirectory(test)
8850aadb33SDmitri Tikhonov    enable_testing()
8950aadb33SDmitri TikhonovENDIF()
9050aadb33SDmitri Tikhonov
9150aadb33SDmitri Tikhonov
9250aadb33SDmitri TikhonovADD_CUSTOM_TARGET(docs doxygen dox.cfg)
93