mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
Harmonise configuration defaults (#937)
* Ensure all options start off for cmake too * Attempt to make the build time config logic in the cmake process match the makefile process * Add a simple muscle memory helper for cmake * Ask them what they are smoking, then tell them to put it out * Avoid occasional stale package cache errors
This commit is contained in:
parent
45520f3d24
commit
028d6f9b07
1
.github/workflows/tests.yml
vendored
1
.github/workflows/tests.yml
vendored
|
@ -45,6 +45,7 @@ jobs:
|
||||||
|
|
||||||
- name: Install essential
|
- name: Install essential
|
||||||
run: |
|
run: |
|
||||||
|
sudo apt update
|
||||||
make build-dep
|
make build-dep
|
||||||
|
|
||||||
- name: Run the lint tools
|
- name: Run the lint tools
|
||||||
|
|
145
CMakeLists.txt
145
CMakeLists.txt
|
@ -37,55 +37,109 @@ set(THIRD_PARTY_DIR ${CMAKE_SOURCE_DIR}/thirdparty)
|
||||||
OPTION(BUILD_SHARED_LIBS "BUILD Shared Library" OFF)
|
OPTION(BUILD_SHARED_LIBS "BUILD Shared Library" OFF)
|
||||||
|
|
||||||
# N2n specific params
|
# N2n specific params
|
||||||
OPTION(N2N_OPTION_USE_PTHREAD "USE PTHREAD Library" ON)
|
OPTION(N2N_OPTION_USE_PTHREAD "USE PTHREAD Library" OFF)
|
||||||
OPTION(N2N_OPTION_USE_OPENSSL "USE OPENSSL Library" OFF)
|
OPTION(N2N_OPTION_USE_OPENSSL "USE OPENSSL Library" OFF)
|
||||||
|
OPTION(N2N_OPTION_USE_CAPLIB "USE CAP Library" OFF)
|
||||||
OPTION(N2N_OPTION_USE_PCAPLIB "USE PCAP Library" OFF)
|
OPTION(N2N_OPTION_USE_PCAPLIB "USE PCAP Library" OFF)
|
||||||
OPTION(N2N_OPTION_USE_ZSTD "USE ZSTD Library" OFF)
|
OPTION(N2N_OPTION_USE_ZSTD "USE ZSTD Library" OFF)
|
||||||
OPTION(N2N_OPTION_USE_PORTMAPPING "USE MINIUPNP and NATPMP Libraries" ON)
|
OPTION(N2N_OPTION_USE_PORTMAPPING "USE MINIUPNP and NATPMP Libraries" OFF)
|
||||||
|
|
||||||
|
|
||||||
if(N2N_OPTION_USE_PTHREAD)
|
if(N2N_OPTION_USE_PTHREAD)
|
||||||
find_library(PTHREAD_LIB pthread)
|
find_library(PTHREAD_LIB pthread)
|
||||||
if(PTHREAD_LIB)
|
if(NOT PTHREAD_LIB)
|
||||||
ADD_DEFINITIONS("-DHAVE_PTHREAD")
|
MESSAGE(FATAL_ERROR "libpthread not found.")
|
||||||
else()
|
|
||||||
MESSAGE(WARNING "libpthread not found.")
|
|
||||||
set(N2N_OPTION_USE_PTHREAD OFF)
|
|
||||||
endif(PTHREAD_LIB)
|
endif(PTHREAD_LIB)
|
||||||
|
MESSAGE(INFO "Using libpthread.")
|
||||||
|
ADD_DEFINITIONS("-DHAVE_PTHREAD")
|
||||||
|
target_link_libraries(n2n pthread)
|
||||||
endif(N2N_OPTION_USE_PTHREAD)
|
endif(N2N_OPTION_USE_PTHREAD)
|
||||||
|
|
||||||
if(NOT DEFINED N2N_OPTION_USE_OPENSSL)
|
|
||||||
set(N2N_OPTION_USE_OPENSSL OFF)
|
|
||||||
endif(NOT DEFINED N2N_OPTION_USE_OPENSSL)
|
|
||||||
|
|
||||||
if(N2N_OPTION_USE_OPENSSL)
|
if(N2N_OPTION_USE_OPENSSL)
|
||||||
find_package(OpenSSL QUIET)
|
find_package(OpenSSL QUIET)
|
||||||
if(NOT OPENSSL_FOUND)
|
if(NOT OPENSSL_FOUND)
|
||||||
MESSAGE(WARNING "OpenSSL not found, Use built-in AES.")
|
MESSAGE(FATAL_ERROR "OpenSSL not found.")
|
||||||
set(N2N_OPTION_USE_OPENSSL OFF)
|
|
||||||
else()
|
|
||||||
MESSAGE(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
|
|
||||||
string(COMPARE GREATER "${OPENSSL_VERSION}" "1.1" OPENSSL_V11)
|
|
||||||
if(OPENSSL_V11)
|
|
||||||
MESSAGE(STATUS "Use OpenSSL With -DHAVE_OPENSSL_1_1")
|
|
||||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
|
||||||
add_definitions(-DHAVE_OPENSSL_1_1)
|
|
||||||
endif()
|
|
||||||
endif(NOT OPENSSL_FOUND)
|
endif(NOT OPENSSL_FOUND)
|
||||||
|
MESSAGE(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
|
||||||
|
string(COMPARE GREATER "${OPENSSL_VERSION}" "1.1" OPENSSL_V11)
|
||||||
|
if(NOT OPENSSL_V11)
|
||||||
|
MESSAGE(FATAL_ERROR "OpenSSL too old")
|
||||||
|
endif()
|
||||||
|
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||||
|
add_definitions(-DHAVE_OPENSSL_1_1)
|
||||||
|
# target_link_libraries(n2n crypto)
|
||||||
|
target_link_libraries(n2n ${OPENSSL_LIBRARIES})
|
||||||
endif(N2N_OPTION_USE_OPENSSL)
|
endif(N2N_OPTION_USE_OPENSSL)
|
||||||
|
|
||||||
if(N2N_OPTION_USE_ZSTD)
|
if(N2N_OPTION_USE_ZSTD)
|
||||||
|
find_library(LIBZSTD libztd)
|
||||||
|
if(NOT LIBZSTD)
|
||||||
|
MESSAGE(FATAL_ERROR "libzstd not found.")
|
||||||
|
endif(NOT LIBZSTD)
|
||||||
|
MESSAGE(INFO "Using libztd.")
|
||||||
add_definitions(-DN2N_HAVE_ZSTD)
|
add_definitions(-DN2N_HAVE_ZSTD)
|
||||||
|
target_link_libraries(n2n zstd)
|
||||||
endif(N2N_OPTION_USE_ZSTD)
|
endif(N2N_OPTION_USE_ZSTD)
|
||||||
|
|
||||||
|
if(N2N_OPTION_USE_PCAPLIB)
|
||||||
|
find_library(PCAP_LIB pcap)
|
||||||
|
if(NOT PCAP_LIB)
|
||||||
|
MESSAGE(FATAL_ERROR "libpcap not found.")
|
||||||
|
endif(NOT PCAP_LIB)
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
# - this is different to the configure.ac logic
|
||||||
|
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
|
||||||
|
IF(NOT HAVE_PCAP_IMMEDIATE_MODE)
|
||||||
|
MESSAGE(FATAL_ERROR "libpcap not support pcap_set_immediate_modei()")
|
||||||
|
ENDIF(HAVE_PCAP_IMMEDIATE_MODE)
|
||||||
|
MESSAGE(INFO "Using libpcap.")
|
||||||
|
|
||||||
|
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE")
|
||||||
|
add_executable(n2n-decode tools/n2n-decode.c)
|
||||||
|
target_link_libraries(n2n-decode n2n pcap)
|
||||||
|
install(TARGETS n2n-decode RUNTIME DESTINATION bin)
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
# - This variable is also set elsewhere, I dont think it works this way
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIB})
|
||||||
|
endif(N2N_OPTION_USE_PCAPLIB)
|
||||||
|
|
||||||
|
if(N2N_OPTION_USE_CAPLIB)
|
||||||
|
# Linux Capabilities
|
||||||
|
find_library(CAP_LIB cap)
|
||||||
|
if(NOT CAP_LIB)
|
||||||
|
MESSAGE(FATAL_ERROR "libcap not found.")
|
||||||
|
endif(NOT CAP_LIB)
|
||||||
|
MESSAGE(INFO "Using libpcap.")
|
||||||
|
|
||||||
|
ADD_DEFINITIONS("-DHAVE_LIBCAP")
|
||||||
|
target_link_libraries(edge cap.a)
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
# - This variable is also set elsewhere, I dont think it works this way
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${CAP_LIB})
|
||||||
|
endif(N2N_OPTION_USE_CAPLIB)
|
||||||
|
|
||||||
if(N2N_OPTION_USE_PORTMAPPING)
|
if(N2N_OPTION_USE_PORTMAPPING)
|
||||||
ADD_DEFINITIONS("-DHAVE_MINIUPNP")
|
ADD_DEFINITIONS("-DHAVE_MINIUPNP")
|
||||||
include_directories(${THIRD_PARTY_DIR}/miniupnp/miniupnpc/include)
|
include_directories(${THIRD_PARTY_DIR}/miniupnp/miniupnpc/include)
|
||||||
include_directories(${PROJECT_BINARY_DIR}/lib_miniupnpc)
|
add_subdirectory(${THIRD_PARTY_DIR}/miniupnp/miniupnpc lib_miniupnpc)
|
||||||
|
link_directories(${PROJECT_BINARY_DIR}/lib_miniupnpc)
|
||||||
|
target_link_libraries(n2n libminiupnpc-static)
|
||||||
|
|
||||||
ADD_DEFINITIONS("-DHAVE_NATPMP")
|
ADD_DEFINITIONS("-DHAVE_NATPMP")
|
||||||
include_directories(${THIRD_PARTY_DIR}/libnatpmp)
|
include_directories(${THIRD_PARTY_DIR}/libnatpmp)
|
||||||
|
add_subdirectory(${THIRD_PARTY_DIR}/libnatpmp libnatpmp)
|
||||||
|
link_directories(${PROJECT_BINARY_DIR}/libnatpmp)
|
||||||
|
target_link_libraries(n2n natpmp)
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
# - this is the odd one out, is it needed?
|
||||||
|
include_directories(${PROJECT_BINARY_DIR}/lib_miniupnpc)
|
||||||
endif(N2N_OPTION_USE_PORTMAPPING)
|
endif(N2N_OPTION_USE_PORTMAPPING)
|
||||||
|
|
||||||
|
|
||||||
if(NOT DEFINED CMAKE_BUILD_TYPE)
|
if(NOT DEFINED CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE None)
|
set(CMAKE_BUILD_TYPE None)
|
||||||
endif(NOT DEFINED CMAKE_BUILD_TYPE)
|
endif(NOT DEFINED CMAKE_BUILD_TYPE)
|
||||||
|
@ -154,28 +208,6 @@ add_library(n2n STATIC
|
||||||
src/n2n_port_mapping.c)
|
src/n2n_port_mapping.c)
|
||||||
|
|
||||||
|
|
||||||
if(N2N_OPTION_USE_PTHREAD)
|
|
||||||
target_link_libraries(n2n pthread)
|
|
||||||
endif(N2N_OPTION_USE_PTHREAD)
|
|
||||||
|
|
||||||
if(N2N_OPTION_USE_OPENSSL)
|
|
||||||
# target_link_libraries(n2n crypto)
|
|
||||||
target_link_libraries(n2n ${OPENSSL_LIBRARIES})
|
|
||||||
endif(N2N_OPTION_USE_OPENSSL)
|
|
||||||
|
|
||||||
if(N2N_OPTION_USE_ZSTD)
|
|
||||||
target_link_libraries(n2n zstd)
|
|
||||||
endif(N2N_OPTION_USE_ZSTD)
|
|
||||||
|
|
||||||
if(N2N_OPTION_USE_PORTMAPPING)
|
|
||||||
add_subdirectory(${THIRD_PARTY_DIR}/miniupnp/miniupnpc lib_miniupnpc)
|
|
||||||
link_directories(${PROJECT_BINARY_DIR}/lib_miniupnpc)
|
|
||||||
target_link_libraries(n2n libminiupnpc-static)
|
|
||||||
add_subdirectory(${THIRD_PARTY_DIR}/libnatpmp libnatpmp)
|
|
||||||
link_directories(${PROJECT_BINARY_DIR}/libnatpmp)
|
|
||||||
target_link_libraries(n2n natpmp)
|
|
||||||
endif(N2N_OPTION_USE_PORTMAPPING)
|
|
||||||
|
|
||||||
if(DEFINED WIN32)
|
if(DEFINED WIN32)
|
||||||
add_library(edge_utils_win32 src/edge_utils_win32.c)
|
add_library(edge_utils_win32 src/edge_utils_win32.c)
|
||||||
add_subdirectory(win32)
|
add_subdirectory(win32)
|
||||||
|
@ -197,16 +229,6 @@ target_link_libraries(example_edge_embed n2n)
|
||||||
add_executable(example_sn_embed src/example_sn_embed.c)
|
add_executable(example_sn_embed src/example_sn_embed.c)
|
||||||
target_link_libraries(example_sn_embed n2n)
|
target_link_libraries(example_sn_embed n2n)
|
||||||
|
|
||||||
if(N2N_OPTION_USE_PCAPLIB AND (NOT DEFINED WIN32))
|
|
||||||
# Linux Capabilities
|
|
||||||
find_library(CAP_LIB cap)
|
|
||||||
if(CAP_LIB)
|
|
||||||
target_link_libraries(edge cap.a)
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${CAP_LIB})
|
|
||||||
ADD_DEFINITIONS("-DHAVE_LIBCAP")
|
|
||||||
endif()
|
|
||||||
endif(N2N_OPTION_USE_PCAPLIB AND (NOT DEFINED WIN32))
|
|
||||||
|
|
||||||
install(TARGETS edge supernode
|
install(TARGETS edge supernode
|
||||||
RUNTIME DESTINATION sbin
|
RUNTIME DESTINATION sbin
|
||||||
LIBRARY DESTINATION lib
|
LIBRARY DESTINATION lib
|
||||||
|
@ -233,21 +255,6 @@ target_link_libraries(tests-transform n2n)
|
||||||
add_executable(tests-wire tools/tests-wire.c)
|
add_executable(tests-wire tools/tests-wire.c)
|
||||||
target_link_libraries(tests-wire n2n)
|
target_link_libraries(tests-wire n2n)
|
||||||
|
|
||||||
if(N2N_OPTION_USE_PCAPLIB)
|
|
||||||
find_library(PCAP_LIB pcap)
|
|
||||||
if(PCAP_LIB)
|
|
||||||
add_executable(n2n-decode tools/n2n-decode.c)
|
|
||||||
target_link_libraries(n2n-decode n2n pcap)
|
|
||||||
install(TARGETS n2n-decode RUNTIME DESTINATION bin)
|
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIB})
|
|
||||||
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
|
|
||||||
IF(HAVE_PCAP_IMMEDIATE_MODE)
|
|
||||||
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE")
|
|
||||||
ENDIF(HAVE_PCAP_IMMEDIATE_MODE)
|
|
||||||
endif(PCAP_LIB)
|
|
||||||
endif(N2N_OPTION_USE_PCAPLIB)
|
|
||||||
|
|
||||||
install(TARGETS n2n-benchmark RUNTIME DESTINATION bin)
|
install(TARGETS n2n-benchmark RUNTIME DESTINATION bin)
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
|
|
@ -60,11 +60,15 @@ be migrated to use `--enable-X`
|
||||||
|
|
||||||
## CMake configuration
|
## CMake configuration
|
||||||
|
|
||||||
There are still some autodetected libraries in parts of the CMake build
|
|
||||||
system.
|
|
||||||
|
|
||||||
There are a number of OPTION statements in the CMakeLists.txt file that can
|
There are a number of OPTION statements in the CMakeLists.txt file that can
|
||||||
have their settings changed.
|
have their settings changed. This is done by adding a commandline option
|
||||||
|
to the cmake configure stage.
|
||||||
|
|
||||||
|
e.g:
|
||||||
|
`cmake -DN2N_OPTION_USE_ZSTD=ON ..`
|
||||||
|
|
||||||
|
Note that the names of the configure option variables used in the cmake
|
||||||
|
process will probably change to make the source code consistent.
|
||||||
|
|
||||||
## Compiler Optimizations
|
## Compiler Optimizations
|
||||||
|
|
||||||
|
|
31
scripts/cmake_all.sh
Executable file
31
scripts/cmake_all.sh
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Well, cmake might be approximately the same as ./configure && make, but it
|
||||||
|
# never rolls off the fingers as easily
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ ! -f CMakeLists.txt ]; then
|
||||||
|
echo ERROR: run this script from the TOPDIR
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
OPTS=""
|
||||||
|
#OPTS+=-DN2N_OPTION_USE_ZSTD=ON
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
rm -rf build
|
||||||
|
|
||||||
|
cmake -E make_directory build
|
||||||
|
cd build
|
||||||
|
|
||||||
|
# Shell check wants me to use an array in this scenario. Bourne shell
|
||||||
|
# arrays are my line in the sand showing that a script should not be
|
||||||
|
# written in such a horrible language. Since it would be silly to rewrite
|
||||||
|
# a one-page wrapper script in python, we submit that this check is wrong.
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
cmake $OPTS ..
|
||||||
|
|
||||||
|
cmake --build . --config Release
|
||||||
|
|
||||||
|
ctest
|
Loading…
Reference in New Issue
Block a user