diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-02 20:04:57 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-11-02 21:06:23 +0100 |
commit | d04123c9ed17d7a590702cd574e651aa78021a5c (patch) | |
tree | b71c7f3b365c90d15393c8d3becfc741015e0ced | |
parent | 8764a80ac01c5b37e6657db07bba7323e2a61906 (diff) | |
download | fastd-d04123c9ed17d7a590702cd574e651aa78021a5c.tar fastd-d04123c9ed17d7a590702cd574e651aa78021a5c.zip |
Make adding new methods a bit nicer
-rw-r--r-- | cmake/config.cmake | 3 | ||||
-rw-r--r-- | src/methods/CMakeLists.txt | 47 | ||||
-rw-r--r-- | src/methods/generic_gcm/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/methods/null/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/methods/xsalsa20_poly1305/CMakeLists.txt | 5 |
5 files changed, 38 insertions, 23 deletions
diff --git a/cmake/config.cmake b/cmake/config.cmake index dd8d8c8..53f4b65 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -32,9 +32,6 @@ set(WITH_CIPHER_AES128_CTR_NACL TRUE CACHE BOOL "Include the AES128-CTR implemen 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/src/methods/CMakeLists.txt b/src/methods/CMakeLists.txt index d707884..7676c25 100644 --- a/src/methods/CMakeLists.txt +++ b/src/methods/CMakeLists.txt @@ -1,15 +1,39 @@ -set(METHODS null) +set(METHODS "") set(METHOD_COMMON FALSE) -if(WITH_METHOD_XSALSA20_POLY1305) - list(APPEND METHODS xsalsa20_poly1305) - set(METHOD_COMMON TRUE) -endif(WITH_METHOD_XSALSA20_POLY1305) +macro(fastd_method name needs_common) + string(REPLACE - _ name_ "${name}") + string(TOUPPER "${name_}" NAME) -if(WITH_METHOD_GENERIC_GCM) - list(APPEND METHODS generic_gcm) - set(METHOD_COMMON TRUE) -endif(WITH_METHOD_GENERIC_GCM) + set(WITH_METHOD_${NAME} TRUE CACHE BOOL "Include the ${name} method") + + if(WITH_METHOD_${NAME}) + add_library(method_${name_} OBJECT ${ARGN}) + set_property(TARGET method_${name_} PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") + + list(APPEND METHODS ${name_}) + set(METHODS "${METHODS}" PARENT_SCOPE) + endif(WITH_METHOD_${NAME}) + + if(${needs_common}) + set(METHOD_COMMON TRUE PARENT_SCOPE) + endif(${needs_common}) +endmacro(fastd_method) + +macro(fastd_method_include_directories name) + string(REPLACE - _ name_ "${name}") + string(TOUPPER "${name_}" NAME) + + if(WITH_METHOD_${NAME}) + target_include_directories(method_${name_} PRIVATE ${ARGN}) + endif(WITH_METHOD_${NAME}) +endmacro(fastd_method_include_directories) + + +add_subdirectory(null) + +add_subdirectory(generic_gcm) +add_subdirectory(xsalsa20_poly1305) set(METHOD_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/methods.c") @@ -18,20 +42,17 @@ set(METHOD_DEFINITIONS "") set(METHOD_LIST "") foreach(method ${METHODS}) - add_subdirectory(${method}) - list(APPEND METHOD_SOURCES $<TARGET_OBJECTS:method_${method}>) set(METHOD_DEFINITIONS "${METHOD_DEFINITIONS}\nextern const fastd_method_t fastd_method_${method};") set(METHOD_LIST "${METHOD_LIST}\n&fastd_method_${method},") endforeach(method) + if(METHOD_COMMON) list(APPEND METHOD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/common.c) endif(METHOD_COMMON) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/methods.c.in ${CMAKE_CURRENT_BINARY_DIR}/methods.c) - set(METHOD_SOURCES "${METHOD_SOURCES}" PARENT_SCOPE) diff --git a/src/methods/generic_gcm/CMakeLists.txt b/src/methods/generic_gcm/CMakeLists.txt index df1cec9..99d07a8 100644 --- a/src/methods/generic_gcm/CMakeLists.txt +++ b/src/methods/generic_gcm/CMakeLists.txt @@ -1,4 +1,3 @@ -add_library(method_generic_gcm OBJECT +fastd_method(generic-gcm TRUE generic_gcm.c ) -set_property(TARGET method_generic_gcm PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") diff --git a/src/methods/null/CMakeLists.txt b/src/methods/null/CMakeLists.txt index 750da66..6e3073d 100644 --- a/src/methods/null/CMakeLists.txt +++ b/src/methods/null/CMakeLists.txt @@ -1,4 +1,3 @@ -add_library(method_null OBJECT +fastd_method(null FALSE null.c ) -set_property(TARGET method_null PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") diff --git a/src/methods/xsalsa20_poly1305/CMakeLists.txt b/src/methods/xsalsa20_poly1305/CMakeLists.txt index f2129d6..36e486a 100644 --- a/src/methods/xsalsa20_poly1305/CMakeLists.txt +++ b/src/methods/xsalsa20_poly1305/CMakeLists.txt @@ -1,5 +1,4 @@ -add_library(method_xsalsa20_poly1305 OBJECT +fastd_method(xsalsa20-poly1305 TRUE xsalsa20_poly1305.c ) -set_property(TARGET method_xsalsa20_poly1305 PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") -target_include_directories(method_xsalsa20_poly1305 PRIVATE ${NACL_INCLUDE_DIRS}) +fastd_method_include_directories(xsalsa20-poly1305 ${NACL_INCLUDE_DIRS}) |