CMakeLists.txt revision f07b3eae
106b2a236SDmitri Tikhonov# Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc.  See LICENSE.
250aadb33SDmitri Tikhonovcmake_minimum_required(VERSION 2.8)
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).
1912693a01SDmitri Tikhonov    EXECUTE_PROCESS(
2012693a01SDmitri Tikhonov        COMMAND ${PROJECT_SOURCE_DIR}/print-glibc-version.sh ${CMAKE_C_COMPILER}
2112693a01SDmitri Tikhonov        OUTPUT_VARIABLE GLIBC_VERSION)
2212693a01SDmitri Tikhonov    IF(NOT GLIBC_VERSION EQUAL "" AND GLIBC_VERSION VERSION_LESS 2.17)
2312693a01SDmitri Tikhonov        SET(LIBS ${LIBS} rt)
2412693a01SDmitri Tikhonov    ENDIF()
2521c6983aSRahul JadhavELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Android")
2621c6983aSRahul Jadhav    # for android-ndk >= r19b
2721c6983aSRahul Jadhav    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY "BOTH")
2821c6983aSRahul Jadhav    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE "BOTH")
2921c6983aSRahul Jadhav    set(CMAKE_FIND_ROOT_PATH_MODE_PATH "BOTH")
30ccd74161SDmitri TikhonovENDIF()
31ccd74161SDmitri Tikhonov
321e75f938SDmitri TikhonovIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
331e75f938SDmitri Tikhonov    SET(CMAKE_BUILD_TYPE Debug)
3450aadb33SDmitri TikhonovENDIF()
3550aadb33SDmitri Tikhonov
361e75f938SDmitri TikhonovMESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
3750aadb33SDmitri Tikhonov
38a0e1aeeeSDmitri TikhonovIF (NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-DLSQUIC_DEBUG_NEXT_ADV_TICK")
39a0e1aeeeSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "-DLSQUIC_DEBUG_NEXT_ADV_TICK=1")
40a0e1aeeeSDmitri TikhonovENDIF()
41b93f59beSBob Perper
42c0b26eabSDmitri TikhonovIF (NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-DLSQUIC_CONN_STATS=")
43c0b26eabSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_CONN_STATS=1")
44c0b26eabSDmitri TikhonovENDIF()
45c0b26eabSDmitri Tikhonov
4646a5b669SDmitri TikhonovIF (NOT MSVC)
47461e84d8SAmol Deshpande
4850aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
4950aadb33SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")
5050aadb33SDmitri Tikhonov
51e0197994SDmitri TikhonovIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
5250aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
5350aadb33SDmitri TikhonovENDIF()
545392f7a3SLiteSpeed Tech
55662de5e1SDmitri TikhonovIF(LSQUIC_FIU)
56662de5e1SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
57662de5e1SDmitri Tikhonov    SET(LIBS ${LIBS} fiu)
58662de5e1SDmitri TikhonovENDIF()
59662de5e1SDmitri Tikhonov
601e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
6150aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O0 -g3")
62db8ac9eeSDmitri Tikhonov    IF(CMAKE_C_COMPILER MATCHES "clang" AND
6303e6b668SDmitri Tikhonov                        NOT "$ENV{TRAVIS}" MATCHES "^true$" AND
6403e6b668SDmitri Tikhonov                        NOT "$ENV{EXTRA_CFLAGS}" MATCHES "-fsanitize")
6550aadb33SDmitri Tikhonov        SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fsanitize=address")
66d6937ddcSinitlife        SET(LIBS ${LIBS} -fsanitize=address)
6750aadb33SDmitri Tikhonov    ENDIF()
685392f7a3SLiteSpeed Tech    # Uncomment to enable cleartext protocol mode (no crypto):
695392f7a3SLiteSpeed Tech    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_ENABLE_HANDSHAKE_DISABLE=1")
7050aadb33SDmitri TikhonovELSE()
7150aadb33SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -O3 -g0")
7250aadb33SDmitri Tikhonov    # Comment out the following line to compile out debug messages:
7350aadb33SDmitri Tikhonov    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
7450aadb33SDmitri TikhonovENDIF()
7550aadb33SDmitri Tikhonov
7600c58df3SDmitri TikhonovIF (LSQUIC_DEVEL)
7700c58df3SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_DEVEL=1")
7800c58df3SDmitri TikhonovENDIF()
7900c58df3SDmitri Tikhonov
8067b0dc15SDmitri TikhonovIF(LSQUIC_PROFILE EQUAL 1)
8167b0dc15SDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -g -pg")
8267b0dc15SDmitri TikhonovENDIF()
8367b0dc15SDmitri Tikhonov
8416a9b66aSDmitri TikhonovIF(LSQUIC_COVERAGE EQUAL 1)
8516a9b66aSDmitri Tikhonov    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fprofile-arcs -ftest-coverage")
8616a9b66aSDmitri TikhonovENDIF()
8716a9b66aSDmitri Tikhonov
8850aadb33SDmitri TikhonovIF(MY_CMAKE_FLAGS MATCHES "fsanitize=address")
8950aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is ON")
9050aadb33SDmitri TikhonovELSE()
9150aadb33SDmitri Tikhonov    MESSAGE(STATUS "AddressSanitizer is OFF")
9250aadb33SDmitri TikhonovENDIF()
9350aadb33SDmitri Tikhonov
94461e84d8SAmol Deshpande#MSVC
95461e84d8SAmol DeshpandeELSE()
96fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4100")	# unreferenced formal parameter
97fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4115")	# unnamed type definition in parentheses
98fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4116")	# named type definition in parentheses
99fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4146")	# unary minus operator applied to unsigned type, result still unsigned
100fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4132")	# const initialization
101fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4200")	# zero-sized array
102fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4204")	# non-constant aggregate initializer
103fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4244")	# integer conversion
104fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4245")	# conversion from 'int' to 'unsigned int', signed/unsigned mismatch
105fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4267")	# integer conversion
1062d296031SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4214")	# nonstandard extension used: bit field types other than int
107fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4295")	# array is too small to include a terminating null character
108fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4334")	# result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
109fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4456")	# hide previous local declaration
110fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4459")	# hide global declaration
111fb3e20e0SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4706")	# assignment within conditional expression
112464a1af9SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4090")	# different 'const' qualifier (TODO: debug ls-sfparser.c)
11357fe5a13SDmitri TikhonovSET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} /wd4305")	# truncation from double to float
114461e84d8SAmol 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")
115f07b3eaeSTyler YoungIF(LSQUIC_SHARED_LIB)
116f07b3eaeSTyler Young    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_SHARED_LIB")
117f07b3eaeSTyler YoungENDIF()
1181e75f938SDmitri TikhonovIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
119b5d685fcSBob Perper    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Od")
120461e84d8SAmol Deshpande    #SET (MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DFIU_ENABLE=1")
121ccd74161SDmitri Tikhonov    #SET(LIBS ${LIBS} fiu)
122461e84d8SAmol DeshpandeELSE()
123b5d685fcSBob Perper    SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Ox")
124461e84d8SAmol Deshpande    # Comment out the following line to compile out debug messages:
125461e84d8SAmol Deshpande    #SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -DLSQUIC_LOWEST_LOG_LEVEL=LSQ_LOG_INFO")
126461e84d8SAmol DeshpandeENDIF()
127461e84d8SAmol Deshpande
128461e84d8SAmol DeshpandeENDIF() #MSVC
129461e84d8SAmol Deshpande
13050aadb33SDmitri Tikhonovset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
13150aadb33SDmitri Tikhonov
13250aadb33SDmitri TikhonovMESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
13350aadb33SDmitri Tikhonov
134fb3e20e0SDmitri Tikhonovfind_package(Perl)
135fb3e20e0SDmitri TikhonovIF(NOT PERL_FOUND)
136fb3e20e0SDmitri Tikhonov    MESSAGE(FATAL_ERROR "Perl not found -- need it to generate source code")
137fb3e20e0SDmitri TikhonovENDIF()
138fb3e20e0SDmitri Tikhonov
139f07b3eaeSTyler YoungIF (MSVC)
140f07b3eaeSTyler Young    IF(LSQUIC_SHARED_LIB)
141f07b3eaeSTyler Young        set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES CACHE BOOL "Export all symbols")
142f07b3eaeSTyler Young        SET(LIB_SUFFIX .dll)
143f07b3eaeSTyler Young    ELSE()
144f07b3eaeSTyler Young        SET(LIB_SUFFIX .lib)
145f07b3eaeSTyler Young    ENDIF()
1462e1429b4SDmitri TikhonovELSE()
147f07b3eaeSTyler Young    IF(LSQUIC_SHARED_LIB)
148f07b3eaeSTyler Young        SET(LIB_SUFFIX .so)
149f07b3eaeSTyler Young    ELSE()
150f07b3eaeSTyler Young        SET(LIB_SUFFIX .a)
151f07b3eaeSTyler Young    ENDIF()
1522e1429b4SDmitri TikhonovENDIF()
1532e1429b4SDmitri Tikhonov
1548ca33e0eSDmitri TikhonovIF (NOT DEFINED BORINGSSL_INCLUDE AND DEFINED BORINGSSL_DIR)
1558ca33e0eSDmitri Tikhonov    FIND_PATH(BORINGSSL_INCLUDE NAMES openssl/ssl.h
1568ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_DIR}/include
1578ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
1588ca33e0eSDmitri TikhonovENDIF()
159b1af35d6SDmitri Tikhonov# This must be done before adding other include directories to take
160b1af35d6SDmitri Tikhonov# precedence over header files from other SSL installs.
1618ca33e0eSDmitri Tikhonov
1628ca33e0eSDmitri TikhonovIF (BORINGSSL_INCLUDE)
1638ca33e0eSDmitri Tikhonov    MESSAGE(STATUS "BoringSSL include directory ${BORINGSSL_INCLUDE}")
1648ca33e0eSDmitri Tikhonov    INCLUDE_DIRECTORIES(${BORINGSSL_INCLUDE})
165b1af35d6SDmitri TikhonovELSE()
166b1af35d6SDmitri Tikhonov    MESSAGE(FATAL_ERROR "BoringSSL headers not found")
167e0197994SDmitri TikhonovENDIF()
16850aadb33SDmitri Tikhonov
1698ca33e0eSDmitri TikhonovIF (NOT DEFINED BORINGSSL_LIB AND DEFINED BORINGSSL_DIR)
1708ca33e0eSDmitri Tikhonov    FOREACH(LIB_NAME ssl crypto decrepit)
1718ca33e0eSDmitri Tikhonov        IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
1728ca33e0eSDmitri Tikhonov            FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
1738ca33e0eSDmitri Tikhonov                NAMES ${LIB_NAME}
1748ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_DIR}/${LIB_NAME}
175fb3e20e0SDmitri Tikhonov		PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo
1768ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
1778ca33e0eSDmitri Tikhonov        ELSE()
1788ca33e0eSDmitri Tikhonov            FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
1792e1429b4SDmitri Tikhonov                NAMES lib${LIB_NAME}${LIB_SUFFIX}
1808ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_DIR}/${LIB_NAME}
1818ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
1828ca33e0eSDmitri Tikhonov        ENDIF()
1838ca33e0eSDmitri Tikhonov        IF(BORINGSSL_LIB_${LIB_NAME})
1848ca33e0eSDmitri Tikhonov            MESSAGE(STATUS "Found ${LIB_NAME} library: ${BORINGSSL_LIB_${LIB_NAME}}")
1858ca33e0eSDmitri Tikhonov        ELSE()
1868ca33e0eSDmitri Tikhonov            MESSAGE(STATUS "${LIB_NAME} library not found")
1878ca33e0eSDmitri Tikhonov        ENDIF()
1888ca33e0eSDmitri Tikhonov    ENDFOREACH()
1898ca33e0eSDmitri Tikhonov
1908ca33e0eSDmitri TikhonovELSE()
1918ca33e0eSDmitri Tikhonov
1928ca33e0eSDmitri Tikhonov
1938ca33e0eSDmitri Tikhonov    FOREACH(LIB_NAME ssl crypto decrepit)
1948ca33e0eSDmitri Tikhonov        IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
1958ca33e0eSDmitri Tikhonov            FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
1968ca33e0eSDmitri Tikhonov                NAMES ${LIB_NAME}
1978ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_LIB}
1988ca33e0eSDmitri Tikhonov                PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo
1998ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
2008ca33e0eSDmitri Tikhonov        ELSE()
2018ca33e0eSDmitri Tikhonov            FIND_LIBRARY(BORINGSSL_LIB_${LIB_NAME}
2022e1429b4SDmitri Tikhonov                NAMES lib${LIB_NAME}${LIB_SUFFIX}
2038ca33e0eSDmitri Tikhonov                PATHS ${BORINGSSL_LIB}
20481558c3fSRahul Jadhav                PATH_SUFFIXES ${LIB_NAME}
2058ca33e0eSDmitri Tikhonov                NO_DEFAULT_PATH)
2068ca33e0eSDmitri Tikhonov        ENDIF()
2078ca33e0eSDmitri Tikhonov        IF(BORINGSSL_LIB_${LIB_NAME})
2088ca33e0eSDmitri Tikhonov            MESSAGE(STATUS "Found ${BORINGSSL_LIB} library: ${BORINGSSL_LIB_${LIB_NAME}}")
2098ca33e0eSDmitri Tikhonov        ELSE()
2108ca33e0eSDmitri Tikhonov            MESSAGE(STATUS "${BORINGSSL_LIB} library not found")
2118ca33e0eSDmitri Tikhonov        ENDIF()
2128ca33e0eSDmitri Tikhonov    ENDFOREACH()
213461e84d8SAmol Deshpande
2148ca33e0eSDmitri TikhonovENDIF()
2158ca33e0eSDmitri Tikhonov
2168ca33e0eSDmitri TikhonovSET(CMAKE_INCLUDE_CURRENT_DIR ON)
21783506617SDmitri TikhonovINCLUDE_DIRECTORIES(include)
218b1af35d6SDmitri TikhonovIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
21950aadb33SDmitri Tikhonov    # Find libevent on FreeBSD:
2208ca33e0eSDmitri Tikhonov    include_directories( /usr/local/include )
2218ca33e0eSDmitri Tikhonov    link_directories( /usr/local/lib )
222b1af35d6SDmitri TikhonovENDIF()
223b1af35d6SDmitri Tikhonov
224f07b3eaeSTyler YoungIF (CMAKE_SYSTEM_NAME STREQUAL Windows)
225f07b3eaeSTyler Young    FIND_PATH(GETOPT_INCLUDE_DIR NAMES getopt.h)
226f07b3eaeSTyler Young    IF (GETOPT_INCLUDE_DIR)
227f07b3eaeSTyler Young        INCLUDE_DIRECTORIES(${GETOPT_INCLUDE_DIR})
228f07b3eaeSTyler Young    ELSE()
229f07b3eaeSTyler Young        MESSAGE(FATAL_ERROR "getopt.h was not found")
230f07b3eaeSTyler Young    ENDIF()
231f07b3eaeSTyler Young        FIND_LIBRARY(GETOPT_LIB getopt)
232f07b3eaeSTyler Young    IF(GETOPT_LIB)
233f07b3eaeSTyler Young        MESSAGE(STATUS "Found getopt: ${GETOPT_LIB}")
234f07b3eaeSTyler Young    ELSE()
235f07b3eaeSTyler Young        MESSAGE(STATUS "getopt not found")
236f07b3eaeSTyler Young    ENDIF()
237f07b3eaeSTyler YoungENDIF()
238f07b3eaeSTyler Young
239b1af35d6SDmitri Tikhonov# Find zlib and libevent header files and library files
240b1af35d6SDmitri Tikhonov# TODO: libevent is not strictly necessary to build the library.
241b1af35d6SDmitri TikhonovFIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h)
242b1af35d6SDmitri TikhonovIF (ZLIB_INCLUDE_DIR)
243b1af35d6SDmitri Tikhonov    INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
244b1af35d6SDmitri TikhonovELSE()
245b1af35d6SDmitri Tikhonov    MESSAGE(FATAL_ERROR "zlib.h was not found")
246b1af35d6SDmitri TikhonovENDIF()
247b1af35d6SDmitri TikhonovIF (CMAKE_SYSTEM_NAME STREQUAL Windows)
248b1af35d6SDmitri Tikhonov    FIND_LIBRARY(ZLIB_LIB zlib)
249b1af35d6SDmitri TikhonovELSEIF(CMAKE_SYSTEM_NAME STREQUAL Darwin)
250b1af35d6SDmitri Tikhonov    # XXX somehow FIND_LIBRARY() does not find zlib on Travis?
251b1af35d6SDmitri Tikhonov    SET(ZLIB_LIB z)
252b1af35d6SDmitri TikhonovELSE()
2532e1429b4SDmitri Tikhonov    FIND_LIBRARY(ZLIB_LIB libz${LIB_SUFFIX})
254b1af35d6SDmitri TikhonovENDIF()
255b1af35d6SDmitri TikhonovIF(ZLIB_LIB)
256b1af35d6SDmitri Tikhonov    MESSAGE(STATUS "Found zlib: ${ZLIB_LIB}")
257b1af35d6SDmitri TikhonovELSE()
258b1af35d6SDmitri Tikhonov    MESSAGE(STATUS "zlib not found")
259b1af35d6SDmitri TikhonovENDIF()
2609a690580SDmitri Tikhonov
261b54d1e63SDmitri TikhonovSET(LIBS lsquic ${BORINGSSL_LIB_ssl} ${BORINGSSL_LIB_crypto} ${ZLIB_LIB} ${LIBS})
262b54d1e63SDmitri Tikhonov
263b54d1e63SDmitri TikhonovIF (LSQUIC_BIN)
264b54d1e63SDmitri Tikhonov    FIND_PATH(EVENT_INCLUDE_DIR NAMES event2/event.h)
265b54d1e63SDmitri Tikhonov    IF (EVENT_INCLUDE_DIR)
266b54d1e63SDmitri Tikhonov        INCLUDE_DIRECTORIES(${EVENT_INCLUDE_DIR})
267b54d1e63SDmitri Tikhonov    ELSE()
268b54d1e63SDmitri Tikhonov        MESSAGE(WARNING "event2/event.h was not found: binaries won't be built")
269b54d1e63SDmitri Tikhonov        SET(LSQUIC_BIN OFF)
270747be414SDmitri Tikhonov    ENDIF()
271b1af35d6SDmitri TikhonovENDIF()
27250aadb33SDmitri Tikhonov
273b54d1e63SDmitri TikhonovIF (LSQUIC_BIN)
274b54d1e63SDmitri Tikhonov    IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
275b54d1e63SDmitri Tikhonov        FIND_LIBRARY(EVENT_LIB event)
276b54d1e63SDmitri Tikhonov    ELSE()
277b54d1e63SDmitri Tikhonov        FIND_LIBRARY(EVENT_LIB libevent${LIB_SUFFIX})
278b54d1e63SDmitri Tikhonov        IF(NOT EVENT_LIB)
279b54d1e63SDmitri Tikhonov            FIND_LIBRARY(EVENT_LIB libevent.so)
280b54d1e63SDmitri Tikhonov        ENDIF()
281b54d1e63SDmitri Tikhonov    ENDIF()
282b54d1e63SDmitri Tikhonov    IF(EVENT_LIB)
283b54d1e63SDmitri Tikhonov        MESSAGE(STATUS "Found event: ${EVENT_LIB}")
284b54d1e63SDmitri Tikhonov    ELSE()
285b54d1e63SDmitri Tikhonov        MESSAGE(WARNING "libevent not found: binaries won't be built")
286b54d1e63SDmitri Tikhonov        SET(LSQUIC_BIN OFF)
287b54d1e63SDmitri Tikhonov    ENDIF()
288fb3e20e0SDmitri TikhonovENDIF()
2898ca33e0eSDmitri Tikhonov
290b93f59beSBob Perper
29146a5b669SDmitri TikhonovIF (NOT MSVC)
292b54d1e63SDmitri Tikhonov    LIST(APPEND LIBS pthread m)
293461e84d8SAmol DeshpandeELSE()
294b54d1e63SDmitri Tikhonov    LIST(APPEND LIBS ws2_32)
295461e84d8SAmol DeshpandeENDIF()
296461e84d8SAmol Deshpande
297b54d1e63SDmitri TikhonovIF (LSQUIC_BIN)
298b54d1e63SDmitri Tikhonov    ADD_SUBDIRECTORY(bin)
299fb3e20e0SDmitri TikhonovENDIF()
30050aadb33SDmitri Tikhonov
30121c6983aSRahul Jadhavadd_subdirectory(src)
30221c6983aSRahul Jadhav
3039a690580SDmitri TikhonovIF(LSQUIC_TESTS AND CMAKE_BUILD_TYPE STREQUAL "Debug")
3047fbe101bSDmitri Tikhonov    # Our test framework relies on assertions, only compile if assertions are
3057fbe101bSDmitri Tikhonov    # enabled.
3067fbe101bSDmitri Tikhonov    #
3077fbe101bSDmitri Tikhonov    enable_testing()
3089a690580SDmitri Tikhonov    add_subdirectory(tests)
3097fbe101bSDmitri TikhonovENDIF()
3107fbe101bSDmitri Tikhonov
311feca77f5SDmitri Tikhonov
3120bd32030SDmitri TikhonovFIND_PROGRAM(SPHINX NAMES sphinx-build)
3130bd32030SDmitri TikhonovIF(SPHINX)
3140bd32030SDmitri Tikhonov    ADD_CUSTOM_TARGET(docs
3150bd32030SDmitri Tikhonov        ${SPHINX} -b html
3160bd32030SDmitri Tikhonov        docs
3170bd32030SDmitri Tikhonov        docs/_build
3180bd32030SDmitri Tikhonov    )
3190bd32030SDmitri TikhonovELSE()
3200bd32030SDmitri Tikhonov    MESSAGE(STATUS "sphinx-build not found: docs won't be made")
3210bd32030SDmitri TikhonovENDIF()
322966c52fcSJonas Vautherin
323966c52fcSJonas VautherinINSTALL(FILES
324966c52fcSJonas Vautherin    include/lsquic.h
325966c52fcSJonas Vautherin    include/lsquic_types.h
326966c52fcSJonas Vautherin    include/lsxpack_header.h
327966c52fcSJonas Vautherin    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lsquic
328966c52fcSJonas Vautherin)
329