From 58dda6713ce49d483628b7d59ca36077f288802c Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 15 Feb 2023 14:44:25 +0000 Subject: [PATCH] Use emptiness-checks rather than DEFINED checks For the MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE variables, check that they are non-empty and defined. This means they can be unconditionally created in the cache, simplifying the CMakeLists.txt Signed-off-by: David Horstmann --- CMakeLists.txt | 14 +++++--------- library/CMakeLists.txt | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0743295fa3..30cef2fea0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,13 +135,9 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) FORCE) endif() -# If set, make MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE into PATHs -if(DEFINED MBEDTLS_CONFIG_FILE) - set(MBEDTLS_CONFIG_FILE "" CACHE PATH "Mbed TLS config file (overrides default).") -endif() -if(DEFINED MBEDTLS_USER_CONFIG_FILE) - set(MBEDTLS_USER_CONFIG_FILE "" CACHE PATH "Mbed TLS user config file (appended to default).") -endif() +# Make MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE into PATHs +set(MBEDTLS_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS config file (overrides default).") +set(MBEDTLS_USER_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS user config file (appended to default).") # Create a symbolic link from ${base_name} in the binary directory # to the corresponding path in the source directory. @@ -314,13 +310,13 @@ if(ENABLE_TESTING OR ENABLE_PROGRAMS) PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/everest/include) # Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE - if(DEFINED MBEDTLS_CONFIG_FILE) + if(MBEDTLS_CONFIG_FILE) target_compile_definitions(mbedtls_test PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") target_compile_definitions(mbedtls_test_helpers PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") endif() - if(DEFINED MBEDTLS_USER_CONFIG_FILE) + if(MBEDTLS_USER_CONFIG_FILE) target_compile_definitions(mbedtls_test PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}") target_compile_definitions(mbedtls_test_helpers diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 61532ff796..a15925198d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -230,11 +230,11 @@ foreach(target IN LISTS target_libraries) target_compile_definitions(${target} PRIVATE ${thirdparty_def}) # Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE - if(DEFINED MBEDTLS_CONFIG_FILE) + if(MBEDTLS_CONFIG_FILE) target_compile_definitions(${target} PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}") endif() - if(DEFINED MBEDTLS_USER_CONFIG_FILE) + if(MBEDTLS_USER_CONFIG_FILE) target_compile_definitions(${target} PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}") endif()