From e7893cc54fb0eaba0cfe88ff44cf52a3f7ff2200 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 3 Nov 2013 02:20:09 +0100 Subject: Even nicer method specification --- cmake/fastd_module.cmake | 41 +++++++++++++++++++++++ src/CMakeLists.txt | 4 +-- src/methods/CMakeLists.txt | 49 +++++++--------------------- src/methods/generic_gcm/CMakeLists.txt | 3 +- src/methods/null/CMakeLists.txt | 2 +- src/methods/xsalsa20_poly1305/CMakeLists.txt | 3 +- 6 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 cmake/fastd_module.cmake diff --git a/cmake/fastd_module.cmake b/cmake/fastd_module.cmake new file mode 100644 index 0000000..1c2da9d --- /dev/null +++ b/cmake/fastd_module.cmake @@ -0,0 +1,41 @@ +function(fastd_module type name) + string(TOUPPER "${type}" TYPE) + + string(REPLACE - _ name_ "${name}") + string(TOUPPER "${name_}" NAME) + + set(WITH_${TYPE}_${NAME} TRUE CACHE BOOL "Include the ${name} ${type}") + + if(WITH_${TYPE}_${NAME}) + add_library(${type}_${name_} STATIC ${ARGN}) + set_property(TARGET ${type}_${name_} PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") + + set_property(TARGET ${type}s APPEND PROPERTY LINK_LIBRARIES ${type}_${name_}) + + list(APPEND ${TYPE}S ${name_}) + + set_property(GLOBAL APPEND PROPERTY FASTD_${TYPE}S ${name_}) + endif(WITH_${TYPE}_${NAME}) +endfunction(fastd_module) + +function(fastd_module_include_directories type name) + string(TOUPPER "${type}" TYPE) + + string(REPLACE - _ name_ "${name}") + string(TOUPPER "${name_}" NAME) + + if(WITH_${TYPE}_${NAME}) + target_include_directories(${type}_${name_} PRIVATE ${ARGN}) + endif(WITH_${TYPE}_${NAME}) +endfunction(fastd_module_include_directories) + +function(fastd_module_link_libraries type name) + string(TOUPPER "${type}" TYPE) + + string(REPLACE - _ name_ "${name}") + string(TOUPPER "${name_}" NAME) + + if(WITH_${TYPE}_${NAME}) + target_link_libraries(${type}_${name_} ${ARGN}) + endif(WITH_${TYPE}_${NAME}) +endfunction(fastd_module_link_libraries) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 286d3d7..e5c900f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,7 @@ 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) @@ -36,13 +37,12 @@ add_executable(fastd tuntap.c ${BISON_fastd_config_parse_OUTPUTS} ${PROTOCOL_SOURCES} - ${METHOD_SOURCES} ${CRYPTO_SOURCES} ) set_property(TARGET fastd PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}") set_property(TARGET fastd PROPERTY LINK_FLAGS "-pthread ${UECC_LDFLAGS_OTHER} ${NACL_LDFLAGS_OTHER}") target_include_directories(fastd PRIVATE ${CAP_INCLUDE_DIR} ${NACL_INCLUDE_DIRS}) -target_link_libraries(fastd ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARIES}) +target_link_libraries(fastd methods ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARIES}) add_dependencies(fastd version) diff --git a/src/methods/CMakeLists.txt b/src/methods/CMakeLists.txt index 7676c25..4a1f986 100644 --- a/src/methods/CMakeLists.txt +++ b/src/methods/CMakeLists.txt @@ -1,58 +1,31 @@ -set(METHODS "") -set(METHOD_COMMON FALSE) +add_library(methods STATIC "${CMAKE_CURRENT_BINARY_DIR}/methods.c") +add_library(method_common STATIC "common.c") -macro(fastd_method name needs_common) - string(REPLACE - _ name_ "${name}") - string(TOUPPER "${name_}" NAME) - - 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}) +macro(fastd_method) + fastd_module(method ${ARGV}) 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}) +macro(fastd_method_include_directories) + fastd_module_include_directories(method ${ARGV}) endmacro(fastd_method_include_directories) +macro(fastd_method_link_libraries) + fastd_module_link_libraries(method ${ARGV}) +endmacro(fastd_method_link_libraries) -add_subdirectory(null) +add_subdirectory(null) add_subdirectory(generic_gcm) add_subdirectory(xsalsa20_poly1305) -set(METHOD_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/methods.c") - set(METHOD_DEFINITIONS "") set(METHOD_LIST "") +get_property(METHODS GLOBAL PROPERTY FASTD_METHODS) foreach(method ${METHODS}) - 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 99d07a8..c50c1ab 100644 --- a/src/methods/generic_gcm/CMakeLists.txt +++ b/src/methods/generic_gcm/CMakeLists.txt @@ -1,3 +1,4 @@ -fastd_method(generic-gcm TRUE +fastd_method(generic-gcm generic_gcm.c ) +fastd_method_link_libraries(generic-gcm method_common) diff --git a/src/methods/null/CMakeLists.txt b/src/methods/null/CMakeLists.txt index 6e3073d..bfd3109 100644 --- a/src/methods/null/CMakeLists.txt +++ b/src/methods/null/CMakeLists.txt @@ -1,3 +1,3 @@ -fastd_method(null FALSE +fastd_method(null null.c ) diff --git a/src/methods/xsalsa20_poly1305/CMakeLists.txt b/src/methods/xsalsa20_poly1305/CMakeLists.txt index 36e486a..d071d99 100644 --- a/src/methods/xsalsa20_poly1305/CMakeLists.txt +++ b/src/methods/xsalsa20_poly1305/CMakeLists.txt @@ -1,4 +1,5 @@ -fastd_method(xsalsa20-poly1305 TRUE +fastd_method(xsalsa20-poly1305 xsalsa20_poly1305.c ) fastd_method_include_directories(xsalsa20-poly1305 ${NACL_INCLUDE_DIRS}) +fastd_method_link_libraries(xsalsa20-poly1305 method_common ${NACL_LIBRARIES}) -- cgit v1.2.3