Simplify configuration -- use more cmake functions (#62)

This commit is contained in:
Dmitri Tikhonov 2019-02-01 02:12:06 -05:00 committed by LiteSpeed Tech
parent 93b02ebee8
commit b1af35d6c0
4 changed files with 85 additions and 46 deletions

View file

@ -11,10 +11,8 @@ task:
- git checkout 32e59d2d3264e4e104b355ef73663b8b79ac4093 - git checkout 32e59d2d3264e4e104b355ef73663b8b79ac4093
- cmake . - cmake .
- make - make
- ln -s ssl/libssl.a
- ln -s crypto/libcrypto.a
- cd - - cd -
script: script:
- cmake -DBORINGSSL_INCLUDE=$PWD/boringssl/include -DBORINGSSL_LIB=$PWD/boringssl . - cmake -DBORINGSSL_DIR=$PWD/boringssl .
- make - make
- make test - make test

View file

@ -26,10 +26,8 @@ before_script:
- git checkout 32e59d2d3264e4e104b355ef73663b8b79ac4093 - git checkout 32e59d2d3264e4e104b355ef73663b8b79ac4093
- cmake . - cmake .
- make - make
- ln -s ssl/libssl.a
- ln -s crypto/libcrypto.a
- cd - - cd -
- cmake -DBORINGSSL_INCLUDE=$PWD/boringssl/include -DBORINGSSL_LIB=$PWD/boringssl . - cmake -DBORINGSSL_DIR=$PWD/boringssl .
script: script:
# Now build lsquic-client # Now build lsquic-client
- make - make

View file

@ -2,20 +2,7 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
project(lsquic) PROJECT(lsquic C)
IF (NOT MSVC)
# We prefer clang
IF(NOT ("${CMAKE_C_COMPILER}" MATCHES "ccc-analyzer" OR
"${CMAKE_C_COMPILER}" MATCHES "gcc" OR
"${CMAKE_C_COMPILER}" MATCHES "afl-gcc"))
FIND_PROGRAM(CLANG "clang")
IF(CLANG)
SET(CMAKE_C_COMPILER "${CLANG}")
ENDIF()
ENDIF()
ENDIF()
IF (CMAKE_SYSTEM_NAME STREQUAL "Linux") IF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# If using older glibc, need to link with -lrt. See clock_getres(2). # If using older glibc, need to link with -lrt. See clock_getres(2).
@ -94,25 +81,84 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")
MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}") MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
IF(NOT DEFINED BORINGSSL_INCLUDE) # This must be done before adding other include directories to take
SET(BORINGSSL_INCLUDE /usr/local/include) # precedence over header files from other SSL installs.
ENDIF() FIND_PATH(BORINGSSL_INCLUDE_DIR NAMES openssl/ssl.h
IF(NOT DEFINED BORINGSSL_LIB) PATHS ${BORINGSSL_DIR}/include
SET(BORINGSSL_LIB /usr/local/lib) NO_DEFAULT_PATH)
IF (BORINGSSL_INCLUDE_DIR)
MESSAGE(STATUS "BoringSSL include directory ${BORINGSSL_INCLUDE_DIR}")
INCLUDE_DIRECTORIES(${BORINGSSL_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "BoringSSL headers not found")
ENDIF() ENDIF()
FOREACH(BORINGSSL_LIB ssl crypto decrepit)
IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
FIND_LIBRARY(BORINGSSL_LIB_${BORINGSSL_LIB}
NAMES ${BORINGSSL_LIB}
PATHS ${BORINGSSL_DIR}/${BORINGSSL_LIB}
PATH_SUFFIXES Debug Release MinSizeRel RelWithDebInfo
NO_DEFAULT_PATH)
ELSE()
FIND_LIBRARY(BORINGSSL_LIB_${BORINGSSL_LIB}
NAMES lib${BORINGSSL_LIB}.a
PATHS ${BORINGSSL_DIR}/${BORINGSSL_LIB}
NO_DEFAULT_PATH)
ENDIF()
IF(BORINGSSL_LIB_${BORINGSSL_LIB})
MESSAGE(STATUS "Found ${BORINGSSL_LIB} library: ${BORINGSSL_LIB_${BORINGSSL_LIB}}")
ELSE()
MESSAGE(STATUS "${BORINGSSL_LIB} library not found")
ENDIF()
ENDFOREACH()
include_directories(${BORINGSSL_INCLUDE} ${VCPKG_INCLUDE}) IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
link_directories( ${BORINGSSL_LIB} ) # Find libevent on FreeBSD:
INCLUDE_DIRECTORIES( /usr/local/include )
LINK_DIRECTORIES( /usr/local/lib )
ENDIF()
# Find zlib and libevent header files and library files
# TODO: libevent is not strictly necessary to build the library.
FIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h)
IF (ZLIB_INCLUDE_DIR)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "zlib.h was not found")
ENDIF()
IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
FIND_LIBRARY(ZLIB_LIB zlib)
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL Darwin)
# XXX somehow FIND_LIBRARY() does not find zlib on Travis?
SET(ZLIB_LIB z)
ELSE()
FIND_LIBRARY(ZLIB_LIB libz.a)
ENDIF()
IF(ZLIB_LIB)
MESSAGE(STATUS "Found zlib: ${ZLIB_LIB}")
ELSE()
MESSAGE(STATUS "zlib not found")
ENDIF()
FIND_PATH(EVENT_INCLUDE_DIR NAMES event2/event.h)
IF (EVENT_INCLUDE_DIR)
INCLUDE_DIRECTORIES(${EVENT_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "event2/event.h was not found")
ENDIF()
IF (CMAKE_SYSTEM_NAME STREQUAL Windows)
FIND_LIBRARY(EVENT_LIB event)
ELSE()
FIND_LIBRARY(EVENT_LIB libevent.a)
ENDIF()
IF(EVENT_LIB)
MESSAGE(STATUS "Found event: ${EVENT_LIB}")
ELSE()
MESSAGE(STATUS "libevent not found")
ENDIF()
SET(CMAKE_INCLUDE_CURRENT_DIR ON) SET(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories( include src/lshpack) include_directories( include src/lshpack)
IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Find libevent on FreeBSD:
include_directories( /usr/local/include )
link_directories( /usr/local/lib )
ENDIF()
IF (NOT MSVC) IF (NOT MSVC)
add_executable(http_client add_executable(http_client
@ -120,7 +166,8 @@ add_executable(http_client
test/prog.c test/prog.c
test/test_common.c test/test_common.c
) )
target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${LIBS} z m) TARGET_LINK_LIBRARIES(http_client lsquic ${EVENT_LIB} pthread
${BORINGSSL_LIB_ssl} ${BORINGSSL_LIB_crypto} ${LIBS} ${ZLIB_LIB} m)
#MSVC #MSVC
ELSE() ELSE()
@ -134,10 +181,10 @@ add_executable(http_client
target_link_libraries(http_client target_link_libraries(http_client
lsquic lsquic
${VCPKG_LIB}/event.lib ${EVENT_LIB}
${VCPKG_LIB}/zlib.lib ${ZLIB_LIB}
${BORINGSSL_LIB}/ssl.lib ${BORINGSSL_LIB_ssl}
${BORINGSSL_LIB}/crypto.lib ${BORINGSSL_LIB_crypto}
ws2_32 ws2_32
${LIBS} ) ${LIBS} )

View file

@ -4,19 +4,15 @@ INCLUDE_DIRECTORIES(../../src/liblsquic)
ENABLE_TESTING() ENABLE_TESTING()
SET(LIBS lsquic ${BORINGSSL_LIB_crypto} ${BORINGSSL_LIB_ssl} ${ZLIB_LIB})
IF (MSVC) IF (MSVC)
SET(LIBS LIST(APPEND LIBS ws2_32)
lsquic
${VCPKG_LIB}/event.lib
${VCPKG_LIB}/zlib.lib
${BORINGSSL_LIB}/ssl.lib
${BORINGSSL_LIB}/crypto.lib
ws2_32)
SET(ADDL_SOURCES ../../wincompat/getopt.c ../../wincompat/getopt1.c) SET(ADDL_SOURCES ../../wincompat/getopt.c ../../wincompat/getopt1.c)
SET(LIB_FLAGS "-FORCE:MULTIPLE") SET(LIB_FLAGS "-FORCE:MULTIPLE")
ELSE() ELSE()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-value") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-value")
SET(LIBS lsquic libcrypto.a libssl.a z m pthread) LIST(APPEND LIBS m pthread)
ENDIF() ENDIF()
SET(TESTS SET(TESTS