Skip to content

Commit

Permalink
Build: Auto-detect available libraries by default
Browse files Browse the repository at this point in the history
If neither OFF or ON is defined, enable if auto-detected.
  • Loading branch information
orgads committed Jan 12, 2024
1 parent c9f6f0f commit 97ebcb9
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 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 @@ -103,6 +134,12 @@ if(USE_SSL)
elseif(WOLFSSL_FOUND)
add_definitions("-DUSE_TLS" "-DUSE_WOLFSSL" "-DOPENSSL_ALL")
endif()

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

endif()

if(USE_PCAP)
Expand All @@ -114,10 +151,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 +262,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

0 comments on commit 97ebcb9

Please sign in to comment.