From 0bbf08fea77d91d48e0836b53e48b5860a8ed29b Mon Sep 17 00:00:00 2001 From: Andy Walsh Date: Tue, 31 Jul 2018 11:49:55 +0200 Subject: [PATCH] cmake: lib cleanup and use cmake package_find * use OPENSSL_ROOT_DIR * add special .configure handling for osx * move readline, curses to cedar Signed-off-by: Andy Walsh --- .travis.yml | 1 + CMakeLists.txt | 2 +- configure | 8 ++++++++ src/CMakeLists.txt | 2 -- src/Cedar/CMakeLists.txt | 5 +++++ src/Mayaqua/CMakeLists.txt | 20 ++++---------------- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4c3cc9fc..24bb73c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,6 +48,7 @@ before_install: - bash .ci/build-openssl.sh > build-deps.log 2>&1 || (cat build-deps.log && exit 1) script: + - export OPENSSL_ROOT_DIR=${OPENSSL_INSTALL_DIR} - export LD_LIBRARY_PATH="${HOME}/opt/lib:${LD_LIBRARY_PATH:-}" - export CFLAGS="-I${HOME}/opt/include" - export LDFLAGS="-L${HOME}/opt/lib" diff --git a/CMakeLists.txt b/CMakeLists.txt index 10f05835..9eac7fd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.4.3) project(SoftEtherVPN LANGUAGES C) diff --git a/configure b/configure index 7927680d..14118fda 100755 --- a/configure +++ b/configure @@ -25,6 +25,14 @@ if [ ! -z ${CMAKE_INSTALL_PREFIX+x} ]; then CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}" fi +if [ -z ${OPENSSL_ROOT_DIR} ]; then + unameOut="$(uname -s)" + if [ "$unameOut" = "Darwin" ]; then + echo "Environment variable OPENSSL_ROOT_DIR not set, using default Homebrew path: /usr/local/opt/openssl/" + export OPENSSL_ROOT_DIR="/usr/local/opt/openssl/" + fi +fi + (cd tmp && cmake ${CMAKE_FLAGS} .. || exit 1) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 76830fad..449256d0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,8 +63,6 @@ if(UNIX) if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") add_definitions(-DUNIX_MACOS -DBRIDGE_PCAP) - include_directories(SYSTEM /usr/local/opt/openssl/include) - link_directories(SYSTEM /usr/local/opt/openssl/lib) endif() endif() diff --git a/src/Cedar/CMakeLists.txt b/src/Cedar/CMakeLists.txt index f4339bb1..0a84134a 100644 --- a/src/Cedar/CMakeLists.txt +++ b/src/Cedar/CMakeLists.txt @@ -10,6 +10,11 @@ set_target_properties(cedar RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/tmp/Cedar" ) +find_library(LIB_READLINE readline) +find_package(Curses REQUIRED) + +target_link_libraries(cedar ${LIB_READLINE} ${CURSES_LIBRARIES}) + if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") target_link_libraries(cedar pcap) endif() diff --git a/src/Mayaqua/CMakeLists.txt b/src/Mayaqua/CMakeLists.txt index 9fc1898c..c4f08cfd 100644 --- a/src/Mayaqua/CMakeLists.txt +++ b/src/Mayaqua/CMakeLists.txt @@ -12,26 +12,14 @@ set_target_properties(mayaqua RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/tmp/Mayaqua" ) -find_package(Threads) -find_library(LIB_READLINE readline) -find_library(LIB_NCURSES ncurses) -find_library(LIB_Z z) +find_package(OpenSSL REQUIRED) +find_package(Threads REQUIRED) +find_package(ZLIB REQUIRED) # In some cases libiconv is not included in libc find_library(LIB_ICONV iconv) -# This is required in order to link to the correct OpenSSL library -find_library(LIB_SSL - NAMES ssl - HINTS "/usr/local/opt/openssl/lib" -) - -find_library(LIB_CRYPTO - NAMES crypto - HINTS "/usr/local/opt/openssl/lib" -) - -target_link_libraries(mayaqua ${CMAKE_THREAD_LIBS_INIT} ${LIB_SSL} ${LIB_CRYPTO} ${LIB_READLINE} ${LIB_NCURSES} ${LIB_Z}) +target_link_libraries(mayaqua OpenSSL::SSL OpenSSL::Crypto Threads::Threads ZLIB::ZLIB) if(LIB_ICONV) target_link_libraries(mayaqua ${LIB_ICONV})