From d04123c9ed17d7a590702cd574e651aa78021a5c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 2 Nov 2013 20:04:57 +0100 Subject: Make adding new methods a bit nicer --- src/methods/CMakeLists.txt | 47 ++++++++++++++++++++-------- src/methods/generic_gcm/CMakeLists.txt | 3 +- src/methods/null/CMakeLists.txt | 3 +- src/methods/xsalsa20_poly1305/CMakeLists.txt | 5 ++- 4 files changed, 38 insertions(+), 20 deletions(-) (limited to 'src') 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 $) 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}) -- cgit v1.2.3