1a74702c6SGeorge Wang# Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE.
2454939cdSRyan A. Pavlikcmake_minimum_required(VERSION 3.0...3.23)
350aadb33SDmitri Tikhonov
450aadb33SDmitri Tikhonov
5b1af35d6SDmitri TikhonovPROJECT(lsquic C)
6461e84d8SAmol Deshpande
79a690580SDmitri TikhonovOPTION(LSQUIC_FIU "Use Fault Injection in Userspace (FIU)" OFF)
89a690580SDmitri TikhonovOPTION(LSQUIC_BIN "Compile example binaries that use the library" ON)
99a690580SDmitri TikhonovOPTION(LSQUIC_TESTS "Compile library unit tests" ON)
102e1429b4SDmitri TikhonovOPTION(LSQUIC_SHARED_LIB "Compile as shared librarry" OFF)
1100c58df3SDmitri TikhonovOPTION(LSQUIC_DEVEL "Compile in development mode" OFF)
129a690580SDmitri Tikhonov
13966c52fcSJonas VautherinINCLUDE(GNUInstallDirs)
14966c52fcSJonas Vautherin
15f07b3eaeSTyler YoungMESSAGE(STATUS "CMake v${CMAKE_VERSION}")
16f07b3eaeSTyler Young
1712693a01SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
1812693a01SDmitri Tikhonov    # If using older glibc, need to link with -lrt.  See clock_getres(2).
19d755d26eSRyan A. Pavlik    include(CheckSymbolExists)
20d755d26eSRyan A. Pavlik    check_symbol_exists(clock_getres "time.h" HAS_clock_getres_WITHOUT_LIBRT)
21d755d26eSRyan A. Pavlik
22d755d26eSRyan A. Pavlik    if(NOT HAS_clock_getres_WITHOUT_LIBRT)
23d755d26eSRyan A. Pavlik        find_library(RT_LIBRARY rt)
24d755d26eSRyan A. Pavlik        set(NEED_LIBRT_FOR_clock_getres ON)
25d755d26eSRyan A. Pavlik    endif()
2621c6983aSRahul JadhavELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Android")
2721c6983aSRahul Jadhav    # for android-ndk >= r19b
2821c6983aSRahul Jadhav    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY "BOTH")
2921c6983aSRahul Jadhav    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE "BOTH")
3021c6983aSRahul Jadhav    set(CMAKE_FIND_ROOT_PATH_MODE_PATH "BOTH")
31ccd74161SDmitri TikhonovENDIF()
32ccd74161SDmitri Tikhonov
331e75f938SDmitri TikhonovIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
341e75f938SDmitri Tikhonov    SET(CMAKE_BUILD_TYPE Debug)
3550aadb33SDmitri TikhonovENDIF()
3650aadb33SDmitri Tikhonov
371e75f938SDmitri TikhonovMESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
3850aadb33SDmitri Tikhonov
39a0e1aeeeSDmitri TikhonovIF (NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-DLSQUIC_DEBUG_NEXT_ADV_TICK")
40a0e1aeeeSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "-DLSQUIC_DEBUG_NEXT_ADV_TICK=1")
41a0e1aeeeSDmitri TikhonovENDIF()
42b93f59beSBob Perper
43c0b26eabSDmitri TikhonovIF (NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-DLSQUIC_CONN_STATS=")
44c0b26eabSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_CONN_STATS=1")
45c0b26eabSDmitri TikhonovENDIF()
46c0b26eabSDmitri Tikhonov
4746a5b669SDmitri TikhonovIF (NOT MSVC)
48461e84d8SAmol Deshpande
4950aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
5050aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
5150aadb33SDmitri Tikhonov
52e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
5350aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
5450aadb33SDmitri TikhonovENDIF()
555392f7a3SLiteSpeed Tech
56662de5e1SDmitri TikhonovIF(LSQUIC_FIU)
57662de5e1SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
58662de5e1SDmitri Tikhonov    SET(LIBS ${LIBS} fiu)
59662de5e1SDmitri TikhonovENDIF()
60662de5e1SDmitri Tikhonov
611e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
6250aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
63db8ac9eeSDmitri Tikhonov    IF(CMAKE_C_COMPILER MATCHES "clang" AND
6403e6b668SDmitri Tikhonov                        NOT "$ENV{TRAVIS}" MATCHES "^true$" AND
6503e6b668SDmitri Tikhonov                        NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize")
6650aadb33SDmitri Tikhonov        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
67d6937ddcSinitlife        SET(LIBS ${LIBS} -fsanitize=address)
6850aadb33SDmitri Tikhonov    ENDIF()
695392f7a3SLiteSpeed Tech    # Uncomment to enable cleartext protocol mode (no crypto):
705392f7a3SLiteSpeed Tech    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1")
7150aadb33SDmitri TikhonovELSE()
7250aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
7350aadb33SDmitri Tikhonov    # Comment out the following line to compile out debug messages:
7450aadb33SDmitri Tikhonov    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
7550aadb33SDmitri TikhonovENDIF()
7650aadb33SDmitri Tikhonov
7700c58df3SDmitri TikhonovIF (LSQUIC_DEVEL)
7800c58df3SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_DEVEL=1")
7900c58df3SDmitri TikhonovENDIF()
8000c58df3SDmitri Tikhonov
8167b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1)
8267b0dc15SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
8367b0dc15SDmitri TikhonovENDIF()
8467b0dc15SDmitri Tikhonov
8516a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1)
8616a9b66aSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
8716a9b66aSDmitri TikhonovENDIF()
8816a9b66aSDmitri Tikhonov
8950aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
9050aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is ON")
9150aadb33SDmitri TikhonovELSE()
9250aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is OFF")
9350aadb33SDmitri TikhonovENDIF()
9450aadb33SDmitri Tikhonov
95461e84d8SAmol Deshpande#MSVC
96461e84d8SAmol DeshpandeELSE()
97fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4100")	# unreferenced formal parameter
98fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4115")	# unnamed type definition in parentheses
99fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4116")	# named type definition in parentheses
100fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4146")	# unary minus operator applied to unsigned type, result still unsigned
101fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4132")	# const initialization
102fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4200")	# zero-sized array
103fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4204")	# non-constant aggregate initializer
104fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4244")	# integer conversion
105fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4245")	# conversion from 'int' to 'unsigned int', signed/unsigned mismatch
106fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4267")	# integer conversion
1072d296031SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4214")	# nonstandard extension used: bit field types other than int
108fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4295")	# array is too small to include a terminating null character
109fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4334")	# result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
110fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4456")	# hide previous local declaration
111fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4459")	# hide global declaration
112fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4706")	# assignment within conditional expression
113464a1af9SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4090")	# different 'const' qualifier (TODO: debug ls-sfparser.c)
11457fe5a13SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4305")	# truncation from double to float
115461e84d8SAmol 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")
116f07b3eaeSTyler YoungIF(LSQUIC_SHARED_LIB)
117f07b3eaeSTyler Young    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_SHARED_LIB")
118f07b3eaeSTyler YoungENDIF()
1191e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
120b5d685fcSBob Perper    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
121461e84d8SAmol Deshpande    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
122ccd74161SDmitri Tikhonov    #SET(LIBS ${LIBS} fiu)
123461e84d8SAmol DeshpandeELSE()
124b5d685fcSBob Perper    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
125461e84d8SAmol Deshpande    # Comment out the following line to compile out debug messages:
126461e84d8SAmol Deshpande    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
127461e84d8SAmol DeshpandeENDIF()
128461e84d8SAmol Deshpande
129461e84d8SAmol DeshpandeENDIF() #MSVC
130461e84d8SAmol Deshpande
13150aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
13250aadb33SDmitri Tikhonov
13350aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
13450aadb33SDmitri Tikhonov
135fb3e20e0SDmitri Tikhonovfind_package(Perl)
136fb3e20e0SDmitri TikhonovIF(NOT PERL_FOUND)
137fb3e20e0SDmitri Tikhonov    MESSAGE(FATAL_ERROR "Perl not found -- need it to generate source code")
138fb3e20e0SDmitri TikhonovENDIF()
139fb3e20e0SDmitri Tikhonov
140f07b3eaeSTyler YoungIF (MSVC)
141f07b3eaeSTyler Young    IF(LSQUIC_SHARED_LIB)
142f07b3eaeSTyler Young        set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES CACHE BOOL "Export all symbols")
143f07b3eaeSTyler Young        SET(LIB_SUFFIX .dll)
144f07b3eaeSTyler Young    ELSE()
145f07b3eaeSTyler Young        SET(LIB_SUFFIX .lib)
146f07b3eaeSTyler Young    ENDIF()
1472e1429b4SDmitri TikhonovELSE()
148f07b3eaeSTyler Young    IF(LSQUIC_SHARED_LIB)
149f07b3eaeSTyler Young        SET(LIB_SUFFIX .so)
150f07b3eaeSTyler Young    ELSE()
151f07b3eaeSTyler Young        SET(LIB_SUFFIX .a)
152f07b3eaeSTyler Young    ENDIF()
1532e1429b4SDmitri TikhonovENDIF()
1542e1429b4SDmitri Tikhonov
1558ca33e0eSDmitri TikhonovIF (NOT DEFINED BORINGSSL_INCLUDE AND DEFINED BORINGSSL_DIR)
1568ca33e0eSDmitri Tikhonov    FIND_PATH(BORINGSSL_INCLUDE NAMES openssl/ssl.h
1578ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_DIR}/include
1588ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
1598ca33e0eSDmitri TikhonovENDIF()
160b1af35d6SDmitri Tikhonov# This must be done before adding other include directories to take
161b1af35d6SDmitri Tikhonov# precedence over header files from other SSL installs.
1628ca33e0eSDmitri Tikhonov
1638ca33e0eSDmitri TikhonovIF (BORINGSSL_INCLUDE)
1648ca33e0eSDmitri Tikhonov    MESSAGE(STATUS "BoringSSL include directory ${BORINGSSL_INCLUDE}")
1658ca33e0eSDmitri Tikhonov    INCLUDE_DIRECTORIES(${BORINGSSL_INCLUDE})
166b1af35d6SDmitri TikhonovELSE()
167b1af35d6SDmitri Tikhonov    MESSAGE(FATAL_ERROR "BoringSSL headers not found")
168e0197994SDmitri TikhonovENDIF()
16950aadb33SDmitri Tikhonov
1708ca33e0eSDmitri TikhonovIF (NOT DEFINED BORINGSSL_LIB AND DEFINED BORINGSSL_DIR)
171146ee2acSRyan A. Pavlik    FOREACH(LIB_NAME ssl crypto)
1728ca33e0eSDmitri Tikhonov        IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
1738ca33e0eSDmitri Tikhonov            FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
1748ca33e0eSDmitri Tikhonov                NAMES ${LIB_NAME}
1758ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_DIR}/${LIB_NAME}
176fb3e20e0SDmitri Tikhonov		PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo
1778ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
1788ca33e0eSDmitri Tikhonov        ELSE()
1798ca33e0eSDmitri Tikhonov            FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
1802e1429b4SDmitri Tikhonov                NAMES lib${LIB_NAME}${LIB_SUFFIX}
1818ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_DIR}/${LIB_NAME}
1828ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
1838ca33e0eSDmitri Tikhonov        ENDIF()
1848ca33e0eSDmitri Tikhonov        IF(BORINGSSL_LIB_${LIB_NAME})
1858ca33e0eSDmitri Tikhonov            MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}")
1868ca33e0eSDmitri Tikhonov        ELSE()
1878ca33e0eSDmitri Tikhonov            MESSAGE(STATUS "${LIB_NAME} library not found")
1888ca33e0eSDmitri Tikhonov        ENDIF()
1898ca33e0eSDmitri Tikhonov    ENDFOREACH()
1908ca33e0eSDmitri Tikhonov
1918ca33e0eSDmitri TikhonovELSE()
1928ca33e0eSDmitri Tikhonov
1938ca33e0eSDmitri Tikhonov
194146ee2acSRyan A. Pavlik    FOREACH(LIB_NAME ssl crypto)
19561b4eaa6Squink-black        # If BORINGSSL_LIB is defined, try find each lib. Otherwise, user should define BORINGSSL_LIB_ssl,
19661b4eaa6Squink-black        # BORINGSSL_LIB_crypto and so on explicitly. For example, including boringssl and lsquic both via
19761b4eaa6Squink-black        # add_subdirectory:
19861b4eaa6Squink-black        #   add_subdirectory(third_party/boringssl)
19961b4eaa6Squink-black        #   set(BORINGSSL_LIB_ssl ssl)
20061b4eaa6Squink-black        #   set(BORINGSSL_LIB_crypto crypto)
20161b4eaa6Squink-black        #   add_subdirectory(third_party/lsquic)
20261b4eaa6Squink-black        IF (DEFINED BORINGSSL_LIB)
20361b4eaa6Squink-black            IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
20461b4eaa6Squink-black                FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
20561b4eaa6Squink-black                    NAMES ${LIB_NAME}
20661b4eaa6Squink-black                    PATHS ${BORINGSSL_LIB}
20761b4eaa6Squink-black                    PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo
20861b4eaa6Squink-black                    NO_DEFAULT_PATH)
20961b4eaa6Squink-black            ELSE()
21061b4eaa6Squink-black                FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
21161b4eaa6Squink-black                    NAMES lib${LIB_NAME}${LIB_SUFFIX}
21261b4eaa6Squink-black                    PATHS ${BORINGSSL_LIB}
21361b4eaa6Squink-black                    PATH_SUFFIXES ${LIB_NAME}
21461b4eaa6Squink-black                    NO_DEFAULT_PATH)
21561b4eaa6Squink-black            ENDIF()
2168ca33e0eSDmitri Tikhonov        ENDIF()
2178ca33e0eSDmitri Tikhonov        IF(BORINGSSL_LIB_${LIB_NAME})
21861b4eaa6Squink-black            MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}")
2198ca33e0eSDmitri Tikhonov        ELSE()
22061b4eaa6Squink-black            MESSAGE(FATAL_ERROR "BORINGSSL_LIB_${LIB_NAME} library not found")
2218ca33e0eSDmitri Tikhonov        ENDIF()
2228ca33e0eSDmitri Tikhonov    ENDFOREACH()
223461e84d8SAmol Deshpande
2248ca33e0eSDmitri TikhonovENDIF()
2258ca33e0eSDmitri Tikhonov
2268ca33e0eSDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON)
22783506617SDmitri TikhonovINCLUDE_DIRECTORIES(include)
228b1af35d6SDmitri TikhonovIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
22950aadb33SDmitri Tikhonov    # Find libevent on FreeBSD:
2308ca33e0eSDmitri Tikhonov    include_directories( /usr/local/include )
2318ca33e0eSDmitri Tikhonov    link_directories( /usr/local/lib )
232b1af35d6SDmitri TikhonovENDIF()
233b1af35d6SDmitri Tikhonov
234f07b3eaeSTyler YoungIF (CMAKE_SYSTEM_NAME STREQUAL Windows)
235f07b3eaeSTyler Young    FIND_PATH(GETOPT_INCLUDE_DIR NAMES getopt.h)
236f07b3eaeSTyler Young    IF (GETOPT_INCLUDE_DIR)
237f07b3eaeSTyler Young        INCLUDE_DIRECTORIES(${GETOPT_INCLUDE_DIR})
238f07b3eaeSTyler Young    ELSE()
239f07b3eaeSTyler Young        MESSAGE(FATAL_ERROR "getopt.h was not found")
240f07b3eaeSTyler Young    ENDIF()
241f07b3eaeSTyler Young        FIND_LIBRARY(GETOPT_LIB getopt)
242f07b3eaeSTyler Young    IF(GETOPT_LIB)
243f07b3eaeSTyler Young        MESSAGE(STATUS "Found getopt: ${GETOPT_LIB}")
244f07b3eaeSTyler Young    ELSE()
245f07b3eaeSTyler Young        MESSAGE(STATUS "getopt not found")
246f07b3eaeSTyler Young    ENDIF()
247f07b3eaeSTyler YoungENDIF()
248f07b3eaeSTyler Young
249b1af35d6SDmitri Tikhonov# Find zlib and libevent header files and library files
250b1af35d6SDmitri Tikhonov# TODO: libevent is not strictly necessary to build the library.
251b1af35d6SDmitri TikhonovFIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h)
252b1af35d6SDmitri TikhonovIF (ZLIB_INCLUDE_DIR)
253b1af35d6SDmitri Tikhonov    INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
254b1af35d6SDmitri TikhonovELSE()
255b1af35d6SDmitri Tikhonov    MESSAGE(FATAL_ERROR "zlib.h was not found")
256b1af35d6SDmitri TikhonovENDIF()
257b1af35d6SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL Windows)
258b1af35d6SDmitri Tikhonov    FIND_LIBRARY(ZLIB_LIB zlib)
259b1af35d6SDmitri TikhonovELSEIF(CMAKE_SYSTEM_NAME STREQUAL Darwin)
260b1af35d6SDmitri Tikhonov    # XXX somehow FIND_LIBRARY() does not find zlib on Travis?
261b1af35d6SDmitri Tikhonov    SET(ZLIB_LIB z)
262b1af35d6SDmitri TikhonovELSE()
2632e1429b4SDmitri Tikhonov    FIND_LIBRARY(ZLIB_LIB libz${LIB_SUFFIX})
264b1af35d6SDmitri TikhonovENDIF()
265b1af35d6SDmitri TikhonovIF(ZLIB_LIB)
266b1af35d6SDmitri Tikhonov    MESSAGE(STATUS "Found zlib: ${ZLIB_LIB}")
267b1af35d6SDmitri TikhonovELSE()
268b1af35d6SDmitri Tikhonov    MESSAGE(STATUS "zlib not found")
269b1af35d6SDmitri TikhonovENDIF()
2709a690580SDmitri Tikhonov
271b54d1e63SDmitri TikhonovSET(LIBS lsquic ${BORINGSSL_LIB_ssl} ${BORINGSSL_LIB_crypto} ${ZLIB_LIB} ${LIBS})
272b54d1e63SDmitri Tikhonov
273b54d1e63SDmitri TikhonovIF (LSQUIC_BIN)
274b54d1e63SDmitri Tikhonov    FIND_PATH(EVENT_INCLUDE_DIR NAMES event2/event.h)
275b54d1e63SDmitri Tikhonov    IF (EVENT_INCLUDE_DIR)
276b54d1e63SDmitri Tikhonov        INCLUDE_DIRECTORIES(${EVENT_INCLUDE_DIR})
277b54d1e63SDmitri Tikhonov    ELSE()
278b54d1e63SDmitri Tikhonov        MESSAGE(WARNING "event2/event.h was not found: binaries won't be built")
279b54d1e63SDmitri Tikhonov        SET(LSQUIC_BIN OFF)
280747be414SDmitri Tikhonov    ENDIF()
281b1af35d6SDmitri TikhonovENDIF()
28250aadb33SDmitri Tikhonov
283b54d1e63SDmitri TikhonovIF (LSQUIC_BIN)
284b54d1e63SDmitri Tikhonov    IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
285b54d1e63SDmitri Tikhonov        FIND_LIBRARY(EVENT_LIB event)
286b54d1e63SDmitri Tikhonov    ELSE()
287b54d1e63SDmitri Tikhonov        FIND_LIBRARY(EVENT_LIB libevent${LIB_SUFFIX})
288b54d1e63SDmitri Tikhonov        IF(NOT EVENT_LIB)
289b54d1e63SDmitri Tikhonov            FIND_LIBRARY(EVENT_LIB libevent.so)
290b54d1e63SDmitri Tikhonov        ENDIF()
291b54d1e63SDmitri Tikhonov    ENDIF()
292b54d1e63SDmitri Tikhonov    IF(EVENT_LIB)
293b54d1e63SDmitri Tikhonov        MESSAGE(STATUS "Found event: ${EVENT_LIB}")
294b54d1e63SDmitri Tikhonov    ELSE()
295b54d1e63SDmitri Tikhonov        MESSAGE(WARNING "libevent not found: binaries won't be built")
296b54d1e63SDmitri Tikhonov        SET(LSQUIC_BIN OFF)
297b54d1e63SDmitri Tikhonov    ENDIF()
298fb3e20e0SDmitri TikhonovENDIF()
2998ca33e0eSDmitri Tikhonov
300b93f59beSBob Perper
30146a5b669SDmitri TikhonovIF (NOT MSVC)
302b54d1e63SDmitri Tikhonov    LIST(APPEND LIBS pthread m)
303461e84d8SAmol DeshpandeELSE()
304b54d1e63SDmitri Tikhonov    LIST(APPEND LIBS ws2_32)
305461e84d8SAmol DeshpandeENDIF()
306461e84d8SAmol Deshpande
307b54d1e63SDmitri TikhonovIF (LSQUIC_BIN)
308b54d1e63SDmitri Tikhonov    ADD_SUBDIRECTORY(bin)
309fb3e20e0SDmitri TikhonovENDIF()
31050aadb33SDmitri Tikhonov
31121c6983aSRahul Jadhavadd_subdirectory(src)
31221c6983aSRahul Jadhav
3139a690580SDmitri TikhonovIF(LSQUIC_TESTS AND CMAKE_BUILD_TYPE STREQUAL "Debug")
3147fbe101bSDmitri Tikhonov    # Our test framework relies on assertions, only compile if assertions are
3157fbe101bSDmitri Tikhonov    # enabled.
3167fbe101bSDmitri Tikhonov    #
3177fbe101bSDmitri Tikhonov    enable_testing()
3189a690580SDmitri Tikhonov    add_subdirectory(tests)
3197fbe101bSDmitri TikhonovENDIF()
3207fbe101bSDmitri Tikhonov
321feca77f5SDmitri Tikhonov
3220bd32030SDmitri TikhonovFIND_PROGRAM(SPHINX NAMES sphinx-build)
3230bd32030SDmitri TikhonovIF(SPHINX)
3240bd32030SDmitri Tikhonov    ADD_CUSTOM_TARGET(docs
3250bd32030SDmitri Tikhonov        ${SPHINX} -b html
3260bd32030SDmitri Tikhonov        docs
3270bd32030SDmitri Tikhonov        docs/_build
3280bd32030SDmitri Tikhonov    )
3290bd32030SDmitri TikhonovELSE()
3300bd32030SDmitri Tikhonov    MESSAGE(STATUS "sphinx-build not found: docs won't be made")
3310bd32030SDmitri TikhonovENDIF()
332966c52fcSJonas Vautherin
333966c52fcSJonas VautherinINSTALL(FILES
334966c52fcSJonas Vautherin    include/lsquic.h
335966c52fcSJonas Vautherin    include/lsquic_types.h
336966c52fcSJonas Vautherin    include/lsxpack_header.h
337966c52fcSJonas Vautherin    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lsquic
338966c52fcSJonas Vautherin)
339