diff options
-rw-r--r-- | cmake/check_reqs.cmake | 12 | ||||
-rw-r--r-- | cmake/deps.cmake | 34 | ||||
-rw-r--r-- | cmake/fastd_module.cmake | 28 | ||||
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/crypto/cipher/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/crypto/mac/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/fastd.c | 4 | ||||
-rw-r--r-- | src/fastd_config.h.in | 2 | ||||
-rw-r--r-- | src/methods/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/methods/xsalsa20_poly1305/CMakeLists.txt | 1 |
11 files changed, 68 insertions, 30 deletions
diff --git a/cmake/check_reqs.cmake b/cmake/check_reqs.cmake new file mode 100644 index 0000000..ad12ca7 --- /dev/null +++ b/cmake/check_reqs.cmake @@ -0,0 +1,12 @@ +set(HAVE_LIBSODIUM FALSE) + +get_property(nacl_required GLOBAL PROPERTY NACL_REQUIRED) +if(${nacl_required}) + if("${NACL_LIBRARIES}" STREQUAL "") + message(FATAL_ERROR "NaCl is not available, but a selected module needs it") + endif() + + if(USE_LIBSODIUM) + set(HAVE_LIBSODIUM TRUE) + endif(USE_LIBSODIUM) +endif(${nacl_required}) diff --git a/cmake/deps.cmake b/cmake/deps.cmake index fa3cb03..c3936af 100644 --- a/cmake/deps.cmake +++ b/cmake/deps.cmake @@ -17,24 +17,30 @@ set(NACL_LIBRARIES "") set(NACL_LDFLAGS_OTHER "") 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}") + pkg_check_modules(SODIUM libsodium) + + if(SODIUM_FOUND) + 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}") + endif(SODIUM_FOUND) else(USE_LIBSODIUM) - find_package(NaCl REQUIRED) + find_package(NaCl) - set(NACL_INCLUDE_DIRS "${NACL_INCLUDE_DIR}") - set(NACL_LIBRARIES "${NACL_LIBRARY}") + if(NACL_FOUND) + set(NACL_INCLUDE_DIRS "${NACL_INCLUDE_DIR}") + set(NACL_LIBRARIES "${NACL_LIBRARY}") + endif(NACL_FOUND) endif(USE_LIBSODIUM) +set_property(GLOBAL PROPERTY NACL_REQUIRED FALSE) + if(WITH_CAPABILITIES) find_package(CAP REQUIRED) diff --git a/cmake/fastd_module.cmake b/cmake/fastd_module.cmake index d18719a..d1b6d3b 100644 --- a/cmake/fastd_module.cmake +++ b/cmake/fastd_module.cmake @@ -1,9 +1,13 @@ -function(fastd_module type enabled_var info name) +macro(_fastd_module_handle_name) string(TOUPPER "${type}" TYPE) string(REPLACE - _ name_ "${name}") string(REPLACE " " _ name_ "${name_}") string(TOUPPER "${name_}" NAME) +endmacro(_fastd_module_handle_name) + +function(fastd_module type enabled_var info name) + _fastd_module_handle_name() set(WITH_${TYPE}_${NAME} TRUE CACHE BOOL "Include the ${name} ${info}") @@ -21,11 +25,7 @@ function(fastd_module type enabled_var info name) endfunction(fastd_module) function(fastd_module_include_directories type name) - string(TOUPPER "${type}" TYPE) - - string(REPLACE - _ name_ "${name}") - string(REPLACE " " _ name_ "${name_}") - string(TOUPPER "${name_}" NAME) + _fastd_module_handle_name() if(WITH_${TYPE}_${NAME}) target_include_directories(${type}_${name_} PRIVATE ${ARGN}) @@ -33,13 +33,19 @@ function(fastd_module_include_directories type name) endfunction(fastd_module_include_directories) function(fastd_module_link_libraries type name) - string(TOUPPER "${type}" TYPE) - - string(REPLACE - _ name_ "${name}") - string(REPLACE " " _ name_ "${name_}") - string(TOUPPER "${name_}" NAME) + _fastd_module_handle_name() if(WITH_${TYPE}_${NAME}) target_link_libraries(${type}_${name_} ${ARGN}) endif(WITH_${TYPE}_${NAME}) endfunction(fastd_module_link_libraries) + +function(fastd_module_require type name) + _fastd_module_handle_name() + + if(WITH_${TYPE}_${NAME}) + foreach(req ${ARGN}) + set_property(GLOBAL PROPERTY ${req}_REQUIRED TRUE) + endforeach(req) + endif(WITH_${TYPE}_${NAME}) +endfunction(fastd_module_require) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 361b546..6c882b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,14 +6,14 @@ 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) - include(fastd_module) add_subdirectory(protocols) add_subdirectory(methods) add_subdirectory(crypto) +include(check_reqs) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fastd_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/fastd_config.h) BISON_TARGET(fastd_config_parse config.y ${CMAKE_CURRENT_BINARY_DIR}/config.yy.c) diff --git a/src/crypto/cipher/CMakeLists.txt b/src/crypto/cipher/CMakeLists.txt index 3d70c70..addb28c 100644 --- a/src/crypto/cipher/CMakeLists.txt +++ b/src/crypto/cipher/CMakeLists.txt @@ -31,6 +31,10 @@ macro(fastd_cipher_impl_link_libraries cipher name) fastd_module_link_libraries(cipher "${cipher} ${name}" ${ARGN}) endmacro(fastd_cipher_impl_link_libraries) +macro(fastd_cipher_impl_require cipher name) + fastd_module_require(cipher "${cipher} ${name}" ${ARGN}) +endmacro(fastd_cipher_impl_require) + add_subdirectory(aes128_ctr) diff --git a/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt b/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt index 50e2283..676aa5d 100644 --- a/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt +++ b/src/crypto/cipher/aes128_ctr/nacl/CMakeLists.txt @@ -3,3 +3,4 @@ fastd_cipher_impl(aes128-ctr nacl ) fastd_cipher_impl_include_directories(aes128-ctr nacl ${NACL_INCLUDE_DIRS}) fastd_cipher_impl_link_libraries(aes128-ctr nacl ${NACL_LIBRARIES}) +fastd_cipher_impl_require(aes128-ctr nacl NACL) diff --git a/src/crypto/mac/CMakeLists.txt b/src/crypto/mac/CMakeLists.txt index 8c80ee1..fe13ace 100644 --- a/src/crypto/mac/CMakeLists.txt +++ b/src/crypto/mac/CMakeLists.txt @@ -31,6 +31,10 @@ macro(fastd_mac_impl_link_libraries mac name) fastd_module_link_libraries(mac "${mac} ${name}" ${ARGN}) endmacro(fastd_mac_impl_link_libraries) +macro(fastd_mac_impl_require mac name) + fastd_module_require(mac "${mac} ${name}" ${ARGN}) +endmacro(fastd_mac_impl_require) + add_subdirectory(ghash) diff --git a/src/fastd.c b/src/fastd.c index 6c2b9e5..f30511d 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -39,7 +39,7 @@ #include <syslog.h> #include <sys/resource.h> -#ifdef USE_LIBSODIUM +#ifdef HAVE_LIBSODIUM #include <sodium/core.h> #endif @@ -739,7 +739,7 @@ static void drop_caps(fastd_context_t *ctx) { } int main(int argc, char *argv[]) { -#ifdef USE_LIBSODIUM +#ifdef HAVE_LIBSODIUM sodium_init(); #endif diff --git a/src/fastd_config.h.in b/src/fastd_config.h.in index dd54033..8ef3aa0 100644 --- a/src/fastd_config.h.in +++ b/src/fastd_config.h.in @@ -45,7 +45,7 @@ #cmakedefine WITH_CMDLINE_COMMANDS -#cmakedefine USE_LIBSODIUM +#cmakedefine HAVE_LIBSODIUM #define MAX_CONFIG_DEPTH @MAX_CONFIG_DEPTH_NUM@ diff --git a/src/methods/CMakeLists.txt b/src/methods/CMakeLists.txt index f67ea0c..3d1e2e2 100644 --- a/src/methods/CMakeLists.txt +++ b/src/methods/CMakeLists.txt @@ -17,6 +17,10 @@ macro(fastd_method_link_libraries) fastd_module_link_libraries(method ${ARGN}) endmacro(fastd_method_link_libraries) +macro(fastd_method_require) + fastd_module_require(method ${ARGN}) +endmacro(fastd_method_require) + add_subdirectory(null) add_subdirectory(generic_gcm) diff --git a/src/methods/xsalsa20_poly1305/CMakeLists.txt b/src/methods/xsalsa20_poly1305/CMakeLists.txt index d071d99..97dee39 100644 --- a/src/methods/xsalsa20_poly1305/CMakeLists.txt +++ b/src/methods/xsalsa20_poly1305/CMakeLists.txt @@ -3,3 +3,4 @@ fastd_method(xsalsa20-poly1305 ) fastd_method_include_directories(xsalsa20-poly1305 ${NACL_INCLUDE_DIRS}) fastd_method_link_libraries(xsalsa20-poly1305 method_common ${NACL_LIBRARIES}) +fastd_method_require(xsalsa20-poly1305 NACL) |