Skip to content

Commit

Permalink
Merge pull request #682 from orgads/auto-deps
Browse files Browse the repository at this point in the history
Build: Auto-detect available libraries by default
  • Loading branch information
lemenkov authored Jan 12, 2024
2 parents 0225983 + e776c1a commit b745169
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
69 changes: 51 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,38 @@ include_directories(
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/include)

function(optional_library LIB_NAME DESCRIPTION)
set(USE_${LIB_NAME} "DEFAULT" CACHE STRING "${DESCRIPTION}")

string(TOLOWER "${LIB_NAME}" LIB_LOWER)
if(USE_${LIB_NAME} STREQUAL "ON" OR USE_${LIB_NAME} STREQUAL "1")
find_library(${LIB_NAME}_LIBRARY ${LIB_LOWER})
set(USE_${LIB_NAME} 1)
elseif(USE_${LIB_NAME} STREQUAL "OFF" OR USE_${LIB_NAME} STREQUAL "0")
set(USE_${LIB_NAME} 0)
else()
find_library(${LIB_NAME}_LIBRARY ${LIB_LOWER})
if(${LIB_NAME}_LIBRARY)
message(STATUS "${LIB_NAME} is enabled")
set(USE_${LIB_NAME} 1 PARENT_SCOPE)
else()
message(STATUS "${LIB_NAME} is disabled")
set(USE_${LIB_NAME} 0 PARENT_SCOPE)
endif()
endif()
endfunction()

optional_library(SCTP "Build with SCTP support")
optional_library(PCAP "Build with PCAP playback support")
optional_library(GSL "Build with improved statistical support")
set(USE_SSL "DEFAULT" CACHE STRING "Build with SIPS support")
if(USE_SSL STREQUAL "ON" OR USE_SSL STREQUAL "1")
set(USE_SSL 1)
elseif(USE_SSL STREQUAL "OFF" OR USE_SSL STREQUAL "0")
set(USE_SSL 0)
endif()

option(BUILD_STATIC "Build a statically-linked binary" OFF)
option(USE_SSL "Build with SIPS support" OFF)
option(USE_SCTP "Build with SCTP support" OFF)
option(USE_PCAP "Build with PCAP playback support" OFF)
option(USE_GSL "Build with improved statistical support" ON)
option(USE_LOCAL_IP_HINTS "Build with local ip hints priority" OFF)

file(GLOB all_SRCS
Expand Down Expand Up @@ -58,11 +85,6 @@ list(REMOVE_ITEM all_SRCS
list(REMOVE_ITEM all_SRCS
"${PROJECT_SOURCE_DIR}/src/sipp.cpp")

if(NOT USE_SSL)
list(REMOVE_ITEM all_SRCS
"${PROJECT_SOURCE_DIR}/src/sslsocket.cpp")
endif(NOT USE_SSL)

if(NOT USE_PCAP)
list(REMOVE_ITEM all_SRCS
"${PROJECT_SOURCE_DIR}/src/prepare_pcap.c")
Expand Down Expand Up @@ -94,7 +116,16 @@ if(USE_SSL)
set(WOLFSSL_FOUND True)
endif()
endif()
if(NOT OPENSSL_FOUND AND NOT WOLFSSL_FOUND)
endif()
if(OPENSSL_FOUND OR WOLFSSL_FOUND)
if(USE_SSL STREQUAL "DEFAULT")
message(STATUS "Found ${SSL_LIBRARIES}; enabling sips support")
endif()
else()
if(USE_SSL STREQUAL "DEFAULT")
message(STATUS "Neither OpenSSL nor WolfSSL was found; disabling sips support")
set(USE_SSL 0)
else()
message(FATAL_ERROR "Neither OpenSSL nor WolfSSL was found; please install a devel package")
endif()
endif()
Expand All @@ -105,6 +136,11 @@ if(USE_SSL)
endif()
endif()

if(NOT USE_SSL)
list(REMOVE_ITEM all_SRCS
"${PROJECT_SOURCE_DIR}/src/sslsocket.cpp")
endif(NOT USE_SSL)

if(USE_PCAP)
add_definitions("-DPCAPPLAY")
endif(USE_PCAP)
Expand All @@ -114,10 +150,7 @@ if(USE_LOCAL_IP_HINTS)
endif(USE_LOCAL_IP_HINTS)

if(USE_GSL)
find_library(GSL_LIBRARY gsl)
if(GSL_LIBRARY)
add_definitions("-DHAVE_GSL")
endif(GSL_LIBRARY)
add_definitions("-DHAVE_GSL")
endif(USE_GSL)

if(USE_SCTP)
Expand Down Expand Up @@ -228,19 +261,19 @@ if(CYGWIN)
add_definitions("-D_GNU_SOURCE")
endif(CYGWIN)

if(USE_GSL AND GSL_LIBRARY)
if(USE_GSL)
target_link_libraries(sipp gsl gslcblas)
target_link_libraries(sipp_unittest gsl gslcblas)
endif(USE_GSL AND GSL_LIBRARY)
endif(USE_GSL)

if(USE_SSL AND SSL_LIBRARIES)
if(USE_SSL)
target_link_libraries(sipp ${SSL_LIBRARIES})
target_link_libraries(sipp_unittest ${SSL_LIBRARIES})
if(SSL_INCLUDE_DIRS)
target_include_directories(sipp SYSTEM PUBLIC ${SSL_INCLUDE_DIRS})
target_include_directories(sipp_unittest SYSTEM PUBLIC ${SSL_INCLUDE_DIRS})
endif(SSL_INCLUDE_DIRS)
endif(USE_SSL AND SSL_LIBRARIES)
endif(USE_SSL)

if(USE_PCAP)
target_link_libraries(sipp pcap)
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ elif test "$*" = "--help" || test "$*" = "-h"; then
fi

if test "$*" = "--none"; then
cmake . -DUSE_GSL=
cmake . -DUSE_GSL=0 -DUSE_SSL=0 -DUSE_SCTP=0 -DUSE_PCAP=0
elif test "$*" = "--common"; then
cmake . -DUSE_GSL=1 -DUSE_PCAP=1 -DUSE_SSL= -DUSE_SCTP=
cmake . -DUSE_GSL=1 -DUSE_PCAP=1 -DUSE_SSL=0 -DUSE_SCTP=0
elif test "$*" = "--full"; then
cmake . -DUSE_GSL=1 -DUSE_PCAP=1 -DUSE_SSL=1 -DUSE_SCTP=1
else
Expand Down

0 comments on commit b745169

Please sign in to comment.