From 38b7d50694b4a9929cc0d5bca884a52d5aeaa8a4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 2 Nov 2013 17:42:30 +0100 Subject: Separate cmake files --- CMakeLists.txt | 136 ++----------------------------------------- FindCAP.cmake | 16 ----- FindNaCl.cmake | 16 ----- cmake/FindCAP.cmake | 16 +++++ cmake/FindNaCl.cmake | 16 +++++ cmake/checks.cmake | 38 ++++++++++++ cmake/config.cmake | 40 +++++++++++++ cmake/deps.cmake | 46 +++++++++++++++ cmake/generate_version.cmake | 12 ++++ src/CMakeLists.txt | 13 +---- 10 files changed, 174 insertions(+), 175 deletions(-) delete mode 100644 FindCAP.cmake delete mode 100644 FindNaCl.cmake create mode 100644 cmake/FindCAP.cmake create mode 100644 cmake/FindNaCl.cmake create mode 100644 cmake/checks.cmake create mode 100644 cmake/config.cmake create mode 100644 cmake/deps.cmake create mode 100644 cmake/generate_version.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e937c..2420488 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,139 +1,11 @@ cmake_minimum_required(VERSION 2.8.3) project(FASTD C) -set(CMAKE_MODULE_PATH ${FASTD_SOURCE_DIR}) +set(CMAKE_MODULE_PATH ${FASTD_SOURCE_DIR}/cmake) set(FASTD_VERSION "v10+") - -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(LINUX TRUE) -else() - set(LINUX FALSE) -endif() - - -set(USE_BINDTODEVICE ${LINUX}) -set(USE_PMTU ${LINUX}) -set(USE_PKTINFO ${LINUX}) - -if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") - set(USE_MULTIAF_BIND FALSE) -else() - set(USE_MULTIAF_BIND TRUE) -endif() - - -set(WITH_CAPABILITIES ${LINUX} CACHE BOOL "Include support for POSIX capabilities") -set(WITH_CMDLINE_USER TRUE CACHE BOOL "Include support for setting user/group related options on the command line") -set(WITH_CMDLINE_LOGGING TRUE CACHE BOOL "Include support for setting logging related options on the command line") -set(WITH_CMDLINE_OPERATION TRUE CACHE BOOL "Include support for setting options related to the VPN operation (like mode, interface, encryption method) on the command line") -set(WITH_CMDLINE_COMMANDS TRUE CACHE BOOL "Include support for setting handler scripts (e.g. --on-up) on the command line") - - -set(WITH_CIPHER_AES128_CTR TRUE CACHE BOOL "Include the AES128-CTR cipher algorithm") -set(WITH_CIPHER_AES128_CTR_NACL TRUE CACHE BOOL "Include the AES128-CTR implementation from the NaCl library") - -set(WITH_MAC_GHASH TRUE CACHE BOOL "Include the GHASH MAC algorithm") -set(WITH_MAC_GHASH_BUILTIN TRUE CACHE BOOL "Include the built-in GHASH implementation") - -set(WITH_METHOD_XSALSA20_POLY1305 TRUE CACHE BOOL "Include xsalsa20-poly1305 method") -set(WITH_METHOD_GENERIC_GCM TRUE CACHE BOOL "Include generic gcm method") - -set(USE_LIBSODIUM FALSE CACHE BOOL "Use libsodium instead of NaCl") - - -set(MAX_CONFIG_DEPTH 10 CACHE STRING "Maximum config include depth") - - -# Ensure the value is numeric -math(EXPR MAX_CONFIG_DEPTH_NUM ${MAX_CONFIG_DEPTH}) - - -find_package(BISON 2.5 REQUIRED) - -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -find_package(Threads) -if(NOT CMAKE_USE_PTHREADS_INIT) - MESSAGE(FATAL_ERROR "No pthread support found.") -endif(NOT CMAKE_USE_PTHREADS_INIT) - -find_package(PkgConfig REQUIRED) -pkg_check_modules(UECC REQUIRED libuecc>=3) - - -set(NACL_INCLUDE_DIRS "") -set(NACL_CFLAGS_OTHER "") -set(NACL_LIBRARY_DIRS "") -set(NACL_LIBRARIES "") -set(NACL_LDFLAGS_OTHER "") - -if(WITH_METHOD_XSALSA20_POLY1305 OR WITH_CIPHER_AES128_CTR_NACL) - if(USE_LIBSODIUM) - pkg_check_modules(SODIUM REQUIRED libsodium) - - set(NACL_INCLUDE_DIRS "${SODIUM_INCLUDE_DIRS}") - foreach(dir "${SODIUM_INCLUDEDIR}" ${SODIUM_INCLUDE_DIRS}) - list(APPEND NACL_INCLUDE_DIRS "${dir}/sodium") - endforeach(dir) - - set(NACL_CFLAGS_OTHER "${SODIUM_CFLAGS_OTHER}") - set(NACL_LIBRARY_DIRS "${SODIUM_LIBRARY_DIRS}") - set(NACL_LIBRARIES "${SODIUM_LIBRARIES}") - set(NACL_LDFLAGS_OTHER "${SODIUM_LDFLAGS_OTHER}") - else(USE_LIBSODIUM) - find_package(NaCl REQUIRED) - - set(NACL_INCLUDE_DIRS "${NACL_INCLUDE_DIR}") - set(NACL_LIBRARIES "${NACL_LIBRARY}") - endif(USE_LIBSODIUM) -endif() - - -if(WITH_CAPABILITIES) - find_package(CAP REQUIRED) -else(WITH_CAPABILITIES) - set(CAP_INCLUDE_DIR "") - set(CAP_LIBRARY "") -endif(WITH_CAPABILITIES) - - -include(CheckCSourceCompiles) -include(CheckPrototypeDefinition) -include(CheckSymbolExists) -include(CheckTypeSize) -set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") - - -check_c_source_compiles(" -#include -#include -#include - -int main() { - return AI_ADDRCONFIG; -} -" HAVE_AI_ADDRCONFIG) - - -check_prototype_definition("get_current_dir_name" "char *get_current_dir_name(void)" "NULL" "unistd.h" HAVE_GET_CURRENT_DIR_NAME) - - -set(RT_LIBRARY "") -check_symbol_exists("clock_gettime" "time.h" HAVE_CLOCK_GETTIME) - -if(NOT HAVE_CLOCK_GETTIME) - set(RT_LIBRARY "rt") - list(APPEND CMAKE_REQUIRED_LIBRARIES "rt") - - check_symbol_exists("clock_gettime" "time.h" HAVE_CLOCK_GETTIME_RT) - if(NOT HAVE_CLOCK_GETTIME_RT) - message(FATAL_ERROR "clock_gettime() not found") - endif(NOT HAVE_CLOCK_GETTIME_RT) -endif(NOT HAVE_CLOCK_GETTIME) - - -set(CMAKE_EXTRA_INCLUDE_FILES "netinet/if_ether.h") -check_type_size("struct ethhdr" SIZEOF_ETHHDR) -string(COMPARE NOTEQUAL "${SIZEOF_ETHHDR}" "" HAVE_ETHHDR) +include(config) +include(deps) +include(checks) add_subdirectory(src) diff --git a/FindCAP.cmake b/FindCAP.cmake deleted file mode 100644 index 80afff3..0000000 --- a/FindCAP.cmake +++ /dev/null @@ -1,16 +0,0 @@ -FIND_PATH(CAP_INCLUDE_DIR sys/capability.h) -FIND_LIBRARY(CAP_LIBRARY NAMES cap) - -IF (CAP_INCLUDE_DIR AND CAP_LIBRARY) - SET(CAP_FOUND TRUE) -ENDIF (CAP_INCLUDE_DIR AND CAP_LIBRARY) - -IF (CAP_FOUND) - IF (NOT CAP_FIND_QUIETLY) - MESSAGE(STATUS "Found libcap: ${CAP_LIBRARY}; include path: ${CAP_INCLUDE_DIR}") - ENDIF (NOT CAP_FIND_QUIETLY) -ELSE (CAP_FOUND) - IF (CAP_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find libcap") - ENDIF (CAP_FIND_REQUIRED) -ENDIF (CAP_FOUND) diff --git a/FindNaCl.cmake b/FindNaCl.cmake deleted file mode 100644 index 6388df6..0000000 --- a/FindNaCl.cmake +++ /dev/null @@ -1,16 +0,0 @@ -FIND_PATH(NACL_INCLUDE_DIR crypto_secretbox_xsalsa20poly1305.h PATH_SUFFIXES nacl) -FIND_LIBRARY(NACL_LIBRARY NAMES nacl) - -IF (NACL_INCLUDE_DIR AND NACL_LIBRARY) - SET(NACL_FOUND TRUE) -ENDIF (NACL_INCLUDE_DIR AND NACL_LIBRARY) - -IF (NACL_FOUND) - IF (NOT NaCl_FIND_QUIETLY) - MESSAGE(STATUS "Found NaCl: Networking and Cryptography library: ${NACL_LIBRARY}; include path: ${NACL_INCLUDE_DIR}") - ENDIF (NOT NaCl_FIND_QUIETLY) -ELSE (NACL_FOUND) - IF (NaCl_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find NaCl: Networking and Cryptography library") - ENDIF (NaCl_FIND_REQUIRED) -ENDIF (NACL_FOUND) diff --git a/cmake/FindCAP.cmake b/cmake/FindCAP.cmake new file mode 100644 index 0000000..80afff3 --- /dev/null +++ b/cmake/FindCAP.cmake @@ -0,0 +1,16 @@ +FIND_PATH(CAP_INCLUDE_DIR sys/capability.h) +FIND_LIBRARY(CAP_LIBRARY NAMES cap) + +IF (CAP_INCLUDE_DIR AND CAP_LIBRARY) + SET(CAP_FOUND TRUE) +ENDIF (CAP_INCLUDE_DIR AND CAP_LIBRARY) + +IF (CAP_FOUND) + IF (NOT CAP_FIND_QUIETLY) + MESSAGE(STATUS "Found libcap: ${CAP_LIBRARY}; include path: ${CAP_INCLUDE_DIR}") + ENDIF (NOT CAP_FIND_QUIETLY) +ELSE (CAP_FOUND) + IF (CAP_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find libcap") + ENDIF (CAP_FIND_REQUIRED) +ENDIF (CAP_FOUND) diff --git a/cmake/FindNaCl.cmake b/cmake/FindNaCl.cmake new file mode 100644 index 0000000..6388df6 --- /dev/null +++ b/cmake/FindNaCl.cmake @@ -0,0 +1,16 @@ +FIND_PATH(NACL_INCLUDE_DIR crypto_secretbox_xsalsa20poly1305.h PATH_SUFFIXES nacl) +FIND_LIBRARY(NACL_LIBRARY NAMES nacl) + +IF (NACL_INCLUDE_DIR AND NACL_LIBRARY) + SET(NACL_FOUND TRUE) +ENDIF (NACL_INCLUDE_DIR AND NACL_LIBRARY) + +IF (NACL_FOUND) + IF (NOT NaCl_FIND_QUIETLY) + MESSAGE(STATUS "Found NaCl: Networking and Cryptography library: ${NACL_LIBRARY}; include path: ${NACL_INCLUDE_DIR}") + ENDIF (NOT NaCl_FIND_QUIETLY) +ELSE (NACL_FOUND) + IF (NaCl_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find NaCl: Networking and Cryptography library") + ENDIF (NaCl_FIND_REQUIRED) +ENDIF (NACL_FOUND) diff --git a/cmake/checks.cmake b/cmake/checks.cmake new file mode 100644 index 0000000..cd80856 --- /dev/null +++ b/cmake/checks.cmake @@ -0,0 +1,38 @@ +include(CheckCSourceCompiles) +include(CheckPrototypeDefinition) +include(CheckSymbolExists) +include(CheckTypeSize) +set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") + + +check_c_source_compiles(" +#include +#include +#include + +int main() { + return AI_ADDRCONFIG; +} +" HAVE_AI_ADDRCONFIG) + + +check_prototype_definition("get_current_dir_name" "char *get_current_dir_name(void)" "NULL" "unistd.h" HAVE_GET_CURRENT_DIR_NAME) + + +set(RT_LIBRARY "") +check_symbol_exists("clock_gettime" "time.h" HAVE_CLOCK_GETTIME) + +if(NOT HAVE_CLOCK_GETTIME) + set(RT_LIBRARY "rt") + list(APPEND CMAKE_REQUIRED_LIBRARIES "rt") + + check_symbol_exists("clock_gettime" "time.h" HAVE_CLOCK_GETTIME_RT) + if(NOT HAVE_CLOCK_GETTIME_RT) + message(FATAL_ERROR "clock_gettime() not found") + endif(NOT HAVE_CLOCK_GETTIME_RT) +endif(NOT HAVE_CLOCK_GETTIME) + + +set(CMAKE_EXTRA_INCLUDE_FILES "netinet/if_ether.h") +check_type_size("struct ethhdr" SIZEOF_ETHHDR) +string(COMPARE NOTEQUAL "${SIZEOF_ETHHDR}" "" HAVE_ETHHDR) diff --git a/cmake/config.cmake b/cmake/config.cmake new file mode 100644 index 0000000..dd8d8c8 --- /dev/null +++ b/cmake/config.cmake @@ -0,0 +1,40 @@ +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(LINUX TRUE) +else() + set(LINUX FALSE) +endif() + + +set(USE_BINDTODEVICE ${LINUX}) +set(USE_PMTU ${LINUX}) +set(USE_PKTINFO ${LINUX}) + +if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + set(USE_MULTIAF_BIND FALSE) +else() + set(USE_MULTIAF_BIND TRUE) +endif() + +set(WITH_CAPABILITIES ${LINUX} CACHE BOOL "Include support for POSIX capabilities") + +set(USE_LIBSODIUM FALSE CACHE BOOL "Use libsodium instead of NaCl") + +set(WITH_CMDLINE_USER TRUE CACHE BOOL "Include support for setting user/group related options on the command line") +set(WITH_CMDLINE_LOGGING TRUE CACHE BOOL "Include support for setting logging related options on the command line") +set(WITH_CMDLINE_OPERATION TRUE CACHE BOOL "Include support for setting options related to the VPN operation (like mode, interface, encryption method) on the command line") +set(WITH_CMDLINE_COMMANDS TRUE CACHE BOOL "Include support for setting handler scripts (e.g. --on-up) on the command line") + +set(MAX_CONFIG_DEPTH 10 CACHE STRING "Maximum config include depth") + +set(WITH_CIPHER_AES128_CTR TRUE CACHE BOOL "Include the AES128-CTR cipher algorithm") +set(WITH_CIPHER_AES128_CTR_NACL TRUE CACHE BOOL "Include the AES128-CTR implementation from the NaCl library") + +set(WITH_MAC_GHASH TRUE CACHE BOOL "Include the GHASH MAC algorithm") +set(WITH_MAC_GHASH_BUILTIN TRUE CACHE BOOL "Include the built-in GHASH implementation") + +set(WITH_METHOD_XSALSA20_POLY1305 TRUE CACHE BOOL "Include xsalsa20-poly1305 method") +set(WITH_METHOD_GENERIC_GCM TRUE CACHE BOOL "Include generic gcm method") + + +# Ensure the value is numeric +math(EXPR MAX_CONFIG_DEPTH_NUM ${MAX_CONFIG_DEPTH}) diff --git a/cmake/deps.cmake b/cmake/deps.cmake new file mode 100644 index 0000000..e49efcd --- /dev/null +++ b/cmake/deps.cmake @@ -0,0 +1,46 @@ +find_package(BISON 2.5 REQUIRED) + +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +find_package(Threads) +if(NOT CMAKE_USE_PTHREADS_INIT) + MESSAGE(FATAL_ERROR "No pthread support found.") +endif(NOT CMAKE_USE_PTHREADS_INIT) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(UECC REQUIRED libuecc>=3) + + +set(NACL_INCLUDE_DIRS "") +set(NACL_CFLAGS_OTHER "") +set(NACL_LIBRARY_DIRS "") +set(NACL_LIBRARIES "") +set(NACL_LDFLAGS_OTHER "") + +if(WITH_METHOD_XSALSA20_POLY1305 OR WITH_CIPHER_AES128_CTR_NACL) + if(USE_LIBSODIUM) + pkg_check_modules(SODIUM REQUIRED libsodium) + + set(NACL_INCLUDE_DIRS "${SODIUM_INCLUDE_DIRS}") + foreach(dir "${SODIUM_INCLUDEDIR}" ${SODIUM_INCLUDE_DIRS}) + list(APPEND NACL_INCLUDE_DIRS "${dir}/sodium") + endforeach(dir) + + set(NACL_CFLAGS_OTHER "${SODIUM_CFLAGS_OTHER}") + set(NACL_LIBRARY_DIRS "${SODIUM_LIBRARY_DIRS}") + set(NACL_LIBRARIES "${SODIUM_LIBRARIES}") + set(NACL_LDFLAGS_OTHER "${SODIUM_LDFLAGS_OTHER}") + else(USE_LIBSODIUM) + find_package(NaCl REQUIRED) + + set(NACL_INCLUDE_DIRS "${NACL_INCLUDE_DIR}") + set(NACL_LIBRARIES "${NACL_LIBRARY}") + endif(USE_LIBSODIUM) +endif() + + +if(WITH_CAPABILITIES) + find_package(CAP REQUIRED) +else(WITH_CAPABILITIES) + set(CAP_INCLUDE_DIR "") + set(CAP_LIBRARY "") +endif(WITH_CAPABILITIES) diff --git a/cmake/generate_version.cmake b/cmake/generate_version.cmake new file mode 100644 index 0000000..bf69bac --- /dev/null +++ b/cmake/generate_version.cmake @@ -0,0 +1,12 @@ +set(VERSION_FILE "${FASTD_BINARY_DIR}/src/fastd_version.h") + +add_custom_target( + version + COMMAND echo "#ifndef _FASTD_FASTD_VERSION_H_" > "${VERSION_FILE}.new" + COMMAND echo "#define _FASTD_FASTD_VERSION_H_" >> "${VERSION_FILE}.new" + COMMAND sh -c "echo \"#define FASTD_VERSION \\\"$(git --git-dir=./.git describe --dirty 2>/dev/null || echo ${FASTD_VERSION})\\\"\"" >> "${VERSION_FILE}.new" + COMMAND echo "#endif /* _FASTD_FASTD_VERSION_H_ */" >> "${VERSION_FILE}.new" + COMMAND cmp -s "${VERSION_FILE}" "${VERSION_FILE}.new" && rm "${VERSION_FILE}.new" || mv "${VERSION_FILE}.new" "${VERSION_FILE}" + WORKING_DIRECTORY "${FASTD_SOURCE_DIR}" + VERBATIM +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc5b8a1..6b4dc92 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,24 +5,15 @@ include_directories(${FASTD_SOURCE_DIR} ${FASTD_BINARY_DIR}/src ${CAP_INCLUDE_D link_directories(${UECC_LIBRARY_DIRS} ${NACL_LIBRARY_DIRS}) +include(generate_version) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fastd_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/fastd_config.h) + add_subdirectory(protocols) add_subdirectory(methods) add_subdirectory(crypto) -add_custom_target( - version - COMMAND echo "#ifndef _FASTD_FASTD_VERSION_H_" > ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h.new - COMMAND echo "#define _FASTD_FASTD_VERSION_H_" >> ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h.new - COMMAND sh -c "echo \"#define FASTD_VERSION \\\"$(git --git-dir=./.git describe --dirty 2>/dev/null || echo ${FASTD_VERSION})\\\"\"" >> ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h.new - COMMAND echo "#endif /* _FASTD_FASTD_VERSION_H_ */" >> ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h.new - COMMAND cmp -s ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h.new ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h && rm ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h.new || mv ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h.new ${CMAKE_CURRENT_BINARY_DIR}/fastd_version.h - WORKING_DIRECTORY "${FASTD_SOURCE_DIR}" - VERBATIM -) - BISON_TARGET(fastd_config_parse config.y ${CMAKE_CURRENT_BINARY_DIR}/config.yy.c) add_executable(fastd -- cgit v1.2.3