CMakeLists.txt revision 16a9b66a
1# Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE.
2cmake_minimum_required(VERSION 2.8)
3
4
5project(lsquic)
6
7# We prefer clang
8IF(NOT ("${CMAKE_C_COMPILER}" MATCHES "ccc-analyzer" OR
9        "${CMAKE_C_COMPILER}" MATCHES "gcc"          OR
10        "${CMAKE_C_COMPILER}" MATCHES "afl-gcc"))
11    FIND_PROGRAM(CLANG "clang")
12    IF(CLANG)
13        SET(CMAKE_C_COMPILER "${CLANG}")
14    ENDIF()
15ENDIF()
16
17# By default, we compile in development mode.  To compile production code,
18# pass -DDEVEL_MODE=0 to cmake (before that, `make clean' and remove any
19# cmake cache files).
20#
21IF(NOT DEFINED DEVEL_MODE)
22    SET(DEVEL_MODE 1)
23ENDIF()
24
25
26MESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}")
27
28SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
29SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
30
31IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
32    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
33ENDIF()
34IF(DEVEL_MODE EQUAL 1)
35    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
36    # -Werror is used to force us to fix warnings early.
37    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Werror")
38    IF(CMAKE_C_COMPILER MATCHES "clang")
39        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
40    ENDIF()
41    # Uncomment to enable fault injection testing via libfiu:
42    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
43    #SET (FIULIB "fiu")
44ELSE()
45    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
46    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DNDEBUG")
47    # Comment out the following line to compile out debug messages:
48    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
49ENDIF()
50
51IF(LSQUIC_PROFILE EQUAL 1)
52    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
53ENDIF()
54
55IF(LSQUIC_COVERAGE EQUAL 1)
56    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
57ENDIF()
58
59IF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
60    MESSAGE(STATUS "AddressSanitizer is ON")
61ELSE()
62    MESSAGE(STATUS "AddressSanitizer is OFF")
63ENDIF()
64
65set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
66
67MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
68
69IF(NOT DEFINED BORINGSSL_INCLUDE)
70    SET(BORINGSSL_INCLUDE /usr/local/include)
71ENDIF()
72IF(NOT DEFINED BORINGSSL_LIB)
73    SET(BORINGSSL_LIB /usr/local/lib)
74ENDIF()
75
76include_directories( ${BORINGSSL_INCLUDE} )
77link_directories( ${BORINGSSL_LIB} )
78
79SET(CMAKE_INCLUDE_CURRENT_DIR ON)
80include_directories( include )
81
82IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
83    # Find libevent on FreeBSD:
84    include_directories( /usr/local/include )
85    link_directories( /usr/local/lib )
86ENDIF()
87
88add_executable(http_client
89    test/http_client.c
90    test/prog.c
91    test/test_common.c
92)
93
94target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)
95
96add_subdirectory(src)
97
98add_subdirectory(test)
99
100IF(DEVEL_MODE EQUAL 1)
101    # Our test framework relies on assertions, only compile if assertions are
102    # enabled.
103    #
104    enable_testing()
105ENDIF()
106
107
108ADD_CUSTOM_TARGET(docs doxygen dox.cfg)
109