mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-09-13 14:22:19 +08:00
CMake: separate base config
Signed-off-by: Yi Wu <yi.wu2@arm.com>
This commit is contained in:
parent
346ece94cc
commit
1b5aabb7ff
@ -131,25 +131,49 @@ if(NOT MBEDTLS_AS_SUBPROJECT)
|
|||||||
FORCE)
|
FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Make MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE into PATHs
|
# Make configuration file options into PATHs
|
||||||
set(MBEDTLS_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS config file (overrides default).")
|
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).")
|
set(MBEDTLS_USER_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS user config file (appended to default).")
|
||||||
|
set(MBEDTLS_CONFIG_BASE_FILE "" CACHE FILEPATH "Mbed TLS config to copy and optionally transform.")
|
||||||
set(MBEDTLS_CONFIG_NAME "" CACHE STRING "Named Mbed TLS configuration (see config.py).")
|
set(MBEDTLS_CONFIG_NAME "" CACHE STRING "Named Mbed TLS configuration (see config.py).")
|
||||||
set(MBEDTLS_CONFIG_SET "" CACHE STRING "Options to set, separated by semicolons (OPTION or OPTION=VALUE).")
|
set(MBEDTLS_CONFIG_SET "" CACHE STRING "Options to set, separated by semicolons (OPTION or OPTION=VALUE).")
|
||||||
set(MBEDTLS_CONFIG_UNSET "" CACHE STRING "Options to unset, separated by semicolons.")
|
set(MBEDTLS_CONFIG_UNSET "" CACHE STRING "Options to unset, separated by semicolons.")
|
||||||
|
|
||||||
if(MBEDTLS_CONFIG_NAME OR MBEDTLS_CONFIG_SET OR MBEDTLS_CONFIG_UNSET)
|
if(NOT "${MBEDTLS_CONFIG_FILE}" STREQUAL "" AND
|
||||||
if(NOT MBEDTLS_PYTHON_EXECUTABLE)
|
(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_UNSET}" STREQUAL ""))
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"MBEDTLS_CONFIG_FILE cannot be combined with MBEDTLS_CONFIG_BASE_FILE, "
|
||||||
|
"MBEDTLS_CONFIG_NAME, MBEDTLS_CONFIG_SET or MBEDTLS_CONFIG_UNSET.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_UNSET}" STREQUAL "")
|
||||||
|
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"MBEDTLS_CONFIG_BASE_FILE, MBEDTLS_CONFIG_NAME, "
|
||||||
|
"MBEDTLS_CONFIG_SET and MBEDTLS_CONFIG_UNSET are not supported "
|
||||||
|
"in an in-tree build.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if((NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_UNSET}" STREQUAL "") AND
|
||||||
|
"${MBEDTLS_PYTHON_EXECUTABLE}" STREQUAL "")
|
||||||
message(FATAL_ERROR "Python 3 is required to generate an Mbed TLS configuration file.")
|
message(FATAL_ERROR "Python 3 is required to generate an Mbed TLS configuration file.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MBEDTLS_CONFIG_FILE)
|
if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "")
|
||||||
set(MBEDTLS_BASE_CONFIG_FILE "${MBEDTLS_CONFIG_FILE}")
|
set(MBEDTLS_BASE_CONFIG_FILE "${MBEDTLS_CONFIG_BASE_FILE}")
|
||||||
if(NOT EXISTS "${MBEDTLS_BASE_CONFIG_FILE}")
|
if(NOT EXISTS "${MBEDTLS_BASE_CONFIG_FILE}")
|
||||||
file(RELATIVE_PATH MBEDTLS_CONFIG_FILE_RELATIVE
|
file(RELATIVE_PATH MBEDTLS_CONFIG_BASE_FILE_RELATIVE
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}" "${MBEDTLS_CONFIG_FILE}")
|
"${CMAKE_CURRENT_BINARY_DIR}" "${MBEDTLS_CONFIG_BASE_FILE}")
|
||||||
set(MBEDTLS_BASE_CONFIG_FILE
|
set(MBEDTLS_BASE_CONFIG_FILE
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${MBEDTLS_CONFIG_FILE_RELATIVE}")
|
"${CMAKE_CURRENT_SOURCE_DIR}/${MBEDTLS_CONFIG_BASE_FILE_RELATIVE}")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
set(MBEDTLS_BASE_CONFIG_FILE
|
set(MBEDTLS_BASE_CONFIG_FILE
|
||||||
@ -168,8 +192,9 @@ if(MBEDTLS_CONFIG_NAME OR MBEDTLS_CONFIG_SET OR MBEDTLS_CONFIG_UNSET)
|
|||||||
"${MBEDTLS_GENERATED_CONFIG_FILE}" COPYONLY)
|
"${MBEDTLS_GENERATED_CONFIG_FILE}" COPYONLY)
|
||||||
# config.py handles the Mbed TLS and PSA configurations together. Give it
|
# config.py handles the Mbed TLS and PSA configurations together. Give it
|
||||||
# a build-tree PSA configuration so that it never modifies the source tree.
|
# a build-tree PSA configuration so that it never modifies the source tree.
|
||||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/include/psa/crypto_config.h"
|
configure_file(
|
||||||
DESTINATION "${MBEDTLS_GENERATED_CONFIG_DIR}/psa")
|
"${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/include/psa/crypto_config.h"
|
||||||
|
"${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}" COPYONLY)
|
||||||
|
|
||||||
function(mbedtls_configure_generated_file)
|
function(mbedtls_configure_generated_file)
|
||||||
execute_process(
|
execute_process(
|
||||||
@ -186,7 +211,7 @@ if(MBEDTLS_CONFIG_NAME OR MBEDTLS_CONFIG_SET OR MBEDTLS_CONFIG_UNSET)
|
|||||||
endif()
|
endif()
|
||||||
endfunction(mbedtls_configure_generated_file)
|
endfunction(mbedtls_configure_generated_file)
|
||||||
|
|
||||||
if(MBEDTLS_CONFIG_NAME)
|
if(NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "")
|
||||||
mbedtls_configure_generated_file("${MBEDTLS_CONFIG_NAME}")
|
mbedtls_configure_generated_file("${MBEDTLS_CONFIG_NAME}")
|
||||||
endif()
|
endif()
|
||||||
foreach(option IN LISTS MBEDTLS_CONFIG_UNSET)
|
foreach(option IN LISTS MBEDTLS_CONFIG_UNSET)
|
||||||
@ -205,9 +230,11 @@ if(MBEDTLS_CONFIG_NAME OR MBEDTLS_CONFIG_SET OR MBEDTLS_CONFIG_UNSET)
|
|||||||
endforeach(option)
|
endforeach(option)
|
||||||
|
|
||||||
set(MBEDTLS_CONFIG_FILE "${MBEDTLS_GENERATED_CONFIG_FILE}")
|
set(MBEDTLS_CONFIG_FILE "${MBEDTLS_GENERATED_CONFIG_FILE}")
|
||||||
if(NOT TF_PSA_CRYPTO_CONFIG_FILE AND NOT TF_PSA_CRYPTO_CONFIG_NAME)
|
if("${TF_PSA_CRYPTO_CONFIG_FILE}" STREQUAL "" AND
|
||||||
|
"${TF_PSA_CRYPTO_CONFIG_NAME}" STREQUAL "")
|
||||||
# Named configurations can adjust both configuration files.
|
# Named configurations can adjust both configuration files.
|
||||||
set(TF_PSA_CRYPTO_CONFIG_FILE "${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}")
|
set(TF_PSA_CRYPTO_CONFIG_FILE "${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}"
|
||||||
|
CACHE FILEPATH "TF-PSA-Crypto config file (overrides default)." FORCE)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -383,19 +410,19 @@ endfunction(set_msvc_base_compile_options)
|
|||||||
function(set_config_files_compile_definitions target)
|
function(set_config_files_compile_definitions target)
|
||||||
# Pass-through MBEDTLS_CONFIG_FILE, MBEDTLS_USER_CONFIG_FILE,
|
# Pass-through MBEDTLS_CONFIG_FILE, MBEDTLS_USER_CONFIG_FILE,
|
||||||
# TF_PSA_CRYPTO_CONFIG_FILE and TF_PSA_CRYPTO_USER_CONFIG_FILE
|
# TF_PSA_CRYPTO_CONFIG_FILE and TF_PSA_CRYPTO_USER_CONFIG_FILE
|
||||||
if(MBEDTLS_CONFIG_FILE)
|
if(NOT "${MBEDTLS_CONFIG_FILE}" STREQUAL "")
|
||||||
target_compile_definitions(${target}
|
target_compile_definitions(${target}
|
||||||
PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
|
PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
|
||||||
endif()
|
endif()
|
||||||
if(MBEDTLS_USER_CONFIG_FILE)
|
if(NOT "${MBEDTLS_USER_CONFIG_FILE}" STREQUAL "")
|
||||||
target_compile_definitions(${target}
|
target_compile_definitions(${target}
|
||||||
PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
|
PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
|
||||||
endif()
|
endif()
|
||||||
if(TF_PSA_CRYPTO_CONFIG_FILE)
|
if(NOT "${TF_PSA_CRYPTO_CONFIG_FILE}" STREQUAL "")
|
||||||
target_compile_definitions(${target}
|
target_compile_definitions(${target}
|
||||||
PUBLIC TF_PSA_CRYPTO_CONFIG_FILE="${TF_PSA_CRYPTO_CONFIG_FILE}")
|
PUBLIC TF_PSA_CRYPTO_CONFIG_FILE="${TF_PSA_CRYPTO_CONFIG_FILE}")
|
||||||
endif()
|
endif()
|
||||||
if(TF_PSA_CRYPTO_USER_CONFIG_FILE)
|
if(NOT "${TF_PSA_CRYPTO_USER_CONFIG_FILE}" STREQUAL "")
|
||||||
target_compile_definitions(${target}
|
target_compile_definitions(${target}
|
||||||
PUBLIC TF_PSA_CRYPTO_USER_CONFIG_FILE="${TF_PSA_CRYPTO_USER_CONFIG_FILE}")
|
PUBLIC TF_PSA_CRYPTO_USER_CONFIG_FILE="${TF_PSA_CRYPTO_USER_CONFIG_FILE}")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
Features
|
Features
|
||||||
* Add the `MBEDTLS_CONFIG_NAME`, `MBEDTLS_CONFIG_SET` and
|
* Add the `MBEDTLS_CONFIG_BASE_FILE`, `MBEDTLS_CONFIG_NAME`,
|
||||||
`MBEDTLS_CONFIG_UNSET` CMake options for selecting and customizing
|
`MBEDTLS_CONFIG_SET` and `MBEDTLS_CONFIG_UNSET` CMake options for
|
||||||
compile-time configurations, including configurations based on a custom
|
selecting and customizing compile-time configurations. Fixes #10838.
|
||||||
`MBEDTLS_CONFIG_FILE`. Fixes #10838.
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user