From 27bb59d3af887f9c8c9501203a85badba082ecc1 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Mon, 3 Oct 2016 10:38:46 +0200 Subject: [PATCH] better handling of NETTLE version in CMake --- cmake_targets/CMakeLists.txt | 17 +++++++---------- openair3/TEST/test_aes128_ctr_decrypt.c | 2 +- openair3/TEST/test_aes128_ctr_encrypt.c | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index db03e98c23..e1d5fcb12a 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -1538,20 +1538,17 @@ endif() message ("NETTLE VERSION_INSTALLED = ${NETTLE_VERSION}") -string(REGEX MATCH "[+-]?[0-9]+([.][0-9]+)?" nv ${NETTLE_VERSION}) +string(REGEX REPLACE "([0-9]+).*" "\\1" NETTLE_VERSION_MAJOR ${NETTLE_VERSION}) +string(REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" NETTLE_VERSION_MINOR ${NETTLE_VERSION}) +message ("NETTLE_VERSION_MAJOR = ${NETTLE_VERSION_MAJOR}") +message ("NETTLE_VERSION_MINOR = ${NETTLE_VERSION_MINOR}") -# WE only pass the major and first minor in the define and ignore the rest -#message("NETTLE_VERSION USED = ${nv}") - -# we need to remove decimal as floating point arithematic does not work properly with C preprocessor -STRING(REGEX REPLACE "[.]" "" nv ${nv}) - -if ("${nv}" STREQUAL "") +if ("${NETTLE_VERSION_MAJOR}" STREQUAL "" OR "${NETTLE_VERSION_MINOR}" STREQUAL "") message( FATAL_ERROR "The nettle version not detected properly. Try to run build_oai -I again" ) endif() -set (NETTLE_VERSION "${nv}") -add_definitions("-DNETTLE_VERSION=${NETTLE_VERSION}") +add_definitions("-DNETTLE_VERSION_MAJOR=${NETTLE_VERSION_MAJOR}") +add_definitions("-DNETTLE_VERSION_MINOR=${NETTLE_VERSION_MINOR}") pkg_search_module(XPM xpm) if(NOT ${XPM_FOUND}) diff --git a/openair3/TEST/test_aes128_ctr_decrypt.c b/openair3/TEST/test_aes128_ctr_decrypt.c index 15416c5e4b..4106cb90bb 100644 --- a/openair3/TEST/test_aes128_ctr_decrypt.c +++ b/openair3/TEST/test_aes128_ctr_decrypt.c @@ -48,7 +48,7 @@ void test_uncipher_ctr(const struct nettle_cipher *cipher, const uint8_t *key, uint8_t *data = malloc(length); uint8_t *ctr = malloc(cipher->block_size); -#if NETTLE_VERSION <= 27 +#if NETTLE_VERSION_MAJOR < 3 cipher->set_encrypt_key(ctx, key_length, key); #else cipher->set_encrypt_key(ctx, key); diff --git a/openair3/TEST/test_aes128_ctr_encrypt.c b/openair3/TEST/test_aes128_ctr_encrypt.c index dab80b3602..399200aab4 100644 --- a/openair3/TEST/test_aes128_ctr_encrypt.c +++ b/openair3/TEST/test_aes128_ctr_encrypt.c @@ -47,7 +47,7 @@ static void test_cipher_ctr(const struct nettle_cipher *cipher, const uint8_t *k uint8_t *data = malloc(length); uint8_t *ctr = malloc(cipher->block_size); -#if NETTLE_VERSION <= 27 +#if NETTLE_VERSION_MAJOR < 3 cipher->set_encrypt_key(ctx, key_length, key); #else cipher->set_encrypt_key(ctx, key); -- GitLab