Browse Source

Address CMake config ordering requirements (#942)

For a moment there, I was starting to think that I might have found
a good feature in cmake, but then it turned out that it had specific
ordering requirements and strange cryptic functions that error out
in mysterious ways.

If I am going to have an antique build engine with special quirks that
I must learn in order to use it, I may as well choose the one that is
not also trying to be clever and hiding its internal magic from me.
Which means that I still prefer Makefiles - they are more debuggable.
pull/945/head
Hamish Coleman 3 years ago
committed by GitHub
parent
commit
670aadcf1b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 61
      CMakeLists.txt
  2. 7
      scripts/cmake_all.sh

61
CMakeLists.txt

@ -52,7 +52,6 @@ if(N2N_OPTION_USE_PTHREAD)
endif(NOT PTHREAD_LIB) endif(NOT PTHREAD_LIB)
MESSAGE(INFO "Using libpthread.") MESSAGE(INFO "Using libpthread.")
ADD_DEFINITIONS("-DHAVE_PTHREAD") ADD_DEFINITIONS("-DHAVE_PTHREAD")
target_link_libraries(n2n pthread)
endif(N2N_OPTION_USE_PTHREAD) endif(N2N_OPTION_USE_PTHREAD)
if(N2N_OPTION_USE_OPENSSL) if(N2N_OPTION_USE_OPENSSL)
@ -67,32 +66,31 @@ if(N2N_OPTION_USE_OPENSSL)
endif() endif()
include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DHAVE_OPENSSL_1_1) 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) # TODO: the find_library() call works for some of the config, but not others
if(NOT LIBZSTD) #find_library(LIBZSTD libzstd)
MESSAGE(FATAL_ERROR "libzstd not found.") #if(NOT LIBZSTD)
endif(NOT LIBZSTD) # MESSAGE(FATAL_ERROR "libzstd not found.")
#endif(NOT LIBZSTD)
MESSAGE(INFO "Using libztd.") 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) if(N2N_OPTION_USE_PCAPLIB)
find_library(PCAP_LIB pcap) # TODO: the find_library() call works for some of the config, but not others
if(NOT PCAP_LIB) #find_library(PCAP_LIB pcap)
MESSAGE(FATAL_ERROR "libpcap not found.") #if(NOT PCAP_LIB)
endif(NOT PCAP_LIB) # MESSAGE(FATAL_ERROR "libpcap not found.")
#endif(NOT PCAP_LIB)
# TODO # TODO
# - this is different to the configure.ac logic # - this is different to the configure.ac logic
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE) check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
IF(NOT HAVE_PCAP_IMMEDIATE_MODE) IF(NOT HAVE_PCAP_IMMEDIATE_MODE)
MESSAGE(FATAL_ERROR "libpcap not support pcap_set_immediate_modei()") MESSAGE(FATAL_ERROR "libpcap not support pcap_set_immediate_mode()")
ENDIF(HAVE_PCAP_IMMEDIATE_MODE) ENDIF(NOT HAVE_PCAP_IMMEDIATE_MODE)
MESSAGE(INFO "Using libpcap.") MESSAGE(INFO "Using libpcap.")
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE") ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE")
@ -107,14 +105,14 @@ endif(N2N_OPTION_USE_PCAPLIB)
if(N2N_OPTION_USE_CAPLIB) if(N2N_OPTION_USE_CAPLIB)
# Linux Capabilities # Linux Capabilities
find_library(CAP_LIB cap) # TODO: the find_library() call works for some of the config, but not others
if(NOT CAP_LIB) #find_library(CAP_LIB cap)
MESSAGE(FATAL_ERROR "libcap not found.") #if(NOT CAP_LIB)
endif(NOT CAP_LIB) # MESSAGE(FATAL_ERROR "libcap not found.")
#endif(NOT CAP_LIB)
MESSAGE(INFO "Using libpcap.") MESSAGE(INFO "Using libpcap.")
ADD_DEFINITIONS("-DHAVE_LIBCAP") ADD_DEFINITIONS("-DHAVE_LIBCAP")
target_link_libraries(edge cap.a)
# TODO: # TODO:
# - This variable is also set elsewhere, I dont think it works this way # - This variable is also set elsewhere, I dont think it works this way
@ -126,13 +124,11 @@ if(N2N_OPTION_USE_PORTMAPPING)
include_directories(${THIRD_PARTY_DIR}/miniupnp/miniupnpc/include) include_directories(${THIRD_PARTY_DIR}/miniupnp/miniupnpc/include)
add_subdirectory(${THIRD_PARTY_DIR}/miniupnp/miniupnpc lib_miniupnpc) add_subdirectory(${THIRD_PARTY_DIR}/miniupnp/miniupnpc lib_miniupnpc)
link_directories(${PROJECT_BINARY_DIR}/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) add_subdirectory(${THIRD_PARTY_DIR}/libnatpmp libnatpmp)
link_directories(${PROJECT_BINARY_DIR}/libnatpmp) link_directories(${PROJECT_BINARY_DIR}/libnatpmp)
target_link_libraries(n2n natpmp)
# TODO: # TODO:
# - this is the odd one out, is it needed? # - this is the odd one out, is it needed?
@ -229,6 +225,29 @@ 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_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_CAPLIB)
# TODO: this is a static library, shouldnt we have a generic one?
target_link_libraries(edge cap.a)
endif(N2N_OPTION_USE_CAPLIB)
if(N2N_OPTION_USE_PORTMAPPING)
target_link_libraries(n2n libminiupnpc-static)
target_link_libraries(n2n natpmp)
endif(N2N_OPTION_USE_PORTMAPPING)
install(TARGETS edge supernode install(TARGETS edge supernode
RUNTIME DESTINATION sbin RUNTIME DESTINATION sbin
LIBRARY DESTINATION lib LIBRARY DESTINATION lib

7
scripts/cmake_all.sh

@ -10,7 +10,12 @@ if [ ! -f CMakeLists.txt ]; then
fi fi
OPTS="" OPTS=""
#OPTS+=-DN2N_OPTION_USE_ZSTD=ON #OPTS+=" -DN2N_OPTION_USE_PTHREAD=ON"
#OPTS+=" -DN2N_OPTION_USE_OPENSSL=ON"
#OPTS+=" -DN2N_OPTION_USE_CAPLIB=ON"
#OPTS+=" -DN2N_OPTION_USE_PCAPLIB=ON"
#OPTS+=" -DN2N_OPTION_USE_ZSTD=ON"
#OPTS+=" -DN2N_OPTION_USE_PORTMAPPING=ON"
set -e set -e

Loading…
Cancel
Save