Skip to content

Cmake custom compile-time config support - #10860

Open
yiwu0b11 wants to merge 12 commits into
Mbed-TLS:developmentfrom
yiwu0b11:cmake-config
Open

Cmake custom compile-time config support#10860
yiwu0b11 wants to merge 12 commits into
Mbed-TLS:developmentfrom
yiwu0b11:cmake-config

Conversation

@yiwu0b11

@yiwu0b11 yiwu0b11 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #10838.

Add support for selecting and customizing compile-time configs in CMake with:

  • MBEDTLS_CONFIG_BASE_FILE
  • MBEDTLS_CONFIG_NAME
  • MBEDTLS_CONFIG_SET
  • MBEDTLS_CONFIG_UNSET

For example:

  cmake -S . -B build \
      -DMBEDTLS_CONFIG_BASE_FILE=configs/config-ccm-psk-tls1_2.h \
      -DMBEDTLS_CONFIG_UNSET=MBEDTLS_SSL_SRV_C \
      -DMBEDTLS_CONFIG_SET=MBEDTLS_SSL_RENEGOTIATION;MBEDTLS_DEBUG_C;MBEDTLS_ERROR_C

CMake copies the selected base config into the build tree before applying the transformations. The original file is not modified.

MBEDTLS_CONFIG_FILE still working as the config header passed and cannot be combined with the transformation options.

Generated Mbed TLS and PSA configs are also installed correctly, so installed CMake targets do not reference the producer build tree.

Depends on Mbed-TLS/TF-PSA-Crypto#868 for the PSA CMake config support.

PR checklist

Signed-off-by: Yi Wu <yi.wu2@arm.com>
Signed-off-by: Yi Wu <yi.wu2@arm.com>
@yiwu0b11 yiwu0b11 added enhancement needs-work needs-ci Needs to pass CI tests size-s Estimated task size: small (~2d) labels Aug 6, 2026
Comment thread CMakeLists.txt Outdated
Signed-off-by: Yi Wu <yi.wu2@arm.com>
@yiwu0b11 yiwu0b11 changed the title Cmake config Cmake custom compile-time config support Aug 7, 2026
@yiwu0b11 yiwu0b11 added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review and removed needs-work needs-ci Needs to pass CI tests labels Aug 10, 2026
@yiwu0b11
yiwu0b11 marked this pull request as ready for review August 10, 2026 08:32
@yiwu0b11 yiwu0b11 added the priority-medium Medium priority - this can be reviewed as time permits label Aug 10, 2026
@minosgalanakis
minosgalanakis self-requested a review August 11, 2026 15:09
@gilles-peskine-arm gilles-peskine-arm removed the needs-reviewer This PR needs someone to pick it up for review label Aug 12, 2026
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated

@minosgalanakis minosgalanakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good starting point but some minor comments to address

Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
Comment thread tests/scripts/components-build-system.sh

@gilles-peskine-arm gilles-peskine-arm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments from my review of the crypto PR apply here (with some variations for the test part). In addition, I'm not sure how to tweak the crypto configuration when setting up an Mbed TLS build tree.

Comment thread tests/scripts/components-build-system.sh Outdated
Comment thread tests/scripts/components-build-system.sh Outdated
Comment thread tests/scripts/components-build-system.sh
Comment thread CMakeLists.txt Outdated
@gilles-peskine-arm gilles-peskine-arm added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Aug 13, 2026
Signed-off-by: Yi Wu <yi.wu2@arm.com>
Signed-off-by: Yi Wu <yi.wu2@arm.com>
Signed-off-by: Yi Wu <yi.wu2@arm.com>
Signed-off-by: Yi Wu <yi.wu2@arm.com>
Signed-off-by: Yi Wu <yi.wu2@arm.com>
@yiwu0b11 yiwu0b11 added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Aug 19, 2026
Comment thread CMakeLists.txt

@gilles-peskine-arm gilles-peskine-arm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except I don't see why you couldn't set both mbedtls and TF-PSA-Crypto options. For example, the CI does builds with both a different mbedtls base file and a different crypto base file.

Comments from my review of the crypto PR also apply.

Comment thread CMakeLists.txt Outdated
@gilles-peskine-arm gilles-peskine-arm added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Aug 20, 2026
Signed-off-by: Yi Wu <yi.wu2@arm.com>

@gilles-peskine-arm gilles-peskine-arm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last commit broke MBEDTLS_CONFIG_BASE_FILE with a relative path (AFAICT it did work before). And one test seems ineffective. LGTM otherwise.


msg "configure: resolve a relative base config from the source tree"
cmake -H"$MBEDTLS_ROOT_DIR" -B"$OUT_OF_SOURCE_DIR" \
-DMBEDTLS_CONFIG_BASE_FILE=configs/config-ccm-psk-tls1_2.h \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong. I would expect MBEDTLS_CONFIG_BASE_FILE to be relative to the current directory. (MBEDTLS_CONFIG_FILE is less intuitive, because the C macro is eventually relative to the install path, and it's not obvious how that relates to the source tree or the build tree.)

Comment on lines +362 to +363
-DTF_PSA_CRYPTO_CONFIG_BASE_FILE="$MBEDTLS_ROOT_DIR/tf-psa-crypto/configs/crypto-config-symmetric-only.h" \
-DTF_PSA_CRYPTO_CONFIG_UNSET=PSA_WANT_ALG_RIPEMD160 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the designated crypto config file to use with configs/config-ccm-psk-tls1_2.h? E.g.

Suggested change
-DTF_PSA_CRYPTO_CONFIG_BASE_FILE="$MBEDTLS_ROOT_DIR/tf-psa-crypto/configs/crypto-config-symmetric-only.h" \
-DTF_PSA_CRYPTO_CONFIG_UNSET=PSA_WANT_ALG_RIPEMD160 \
-DTF_PSA_CRYPTO_CONFIG_BASE_FILE="$MBEDTLS_ROOT_DIR/tf-psa-crypto/configs/crypto-config-ccm-psk-tls1_2.h" \
-DTF_PSA_CRYPTO_CONFIG_UNSET=MBEDTLS_HAVE_TIME \

Comment thread CMakeLists.txt Outdated
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_CONFIG_BASE_FILE "" CACHE FILEPATH "Mbed TLS config to copy and optionally transform.")
set(MBEDTLS_CONFIG_BASE_FILE "" CACHE STRING "Mbed TLS config to copy and optionally transform.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MBEDTLS_CONFIG_BASE_FILE is definitely a FILEPATH. It's a file that gets consumed by CMake. (Unlike MBEDTLS_CONFIG_FILE which is consumed by the C compiler and also meaningful after installation — that one might actually be a STRING, but changing that is out of scope here.)

mkdir "$OUT_OF_SOURCE_DIR"
cd "$OUT_OF_SOURCE_DIR"

msg "build: combine Mbed TLS and TF-PSA-Crypto transformations"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test is ineffective. Surely having a TF-PSA-Crypto transformation can only work when tf-psa-crypto has Mbed-TLS/TF-PSA-Crypto#868 ?

(But combining does seem to work if I check out the crypto PR in the submodule. With the caveat that TF_PSA_CRYPTO_CONFIG_BASE_FILE needs to be an absolute path on the current head, but it works with a relative path on 34538973d123e1995acf691606475bea205f1e0f.)

@yiwu0b11 yiwu0b11 added the needs-preceding-pr Requires another PR to be merged first label Aug 21, 2026
Signed-off-by: Yi Wu <yi.wu2@arm.com>
@gilles-peskine-arm

Copy link
Copy Markdown
Contributor

The CI is unhappy

Signed-off-by: Yi Wu <yi.wu2@arm.com>
Signed-off-by: Yi Wu <yi.wu2@arm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement needs-preceding-pr Requires another PR to be merged first needs-work priority-medium Medium priority - this can be reviewed as time permits size-s Estimated task size: small (~2d)

Projects

Status: In Development

Development

Successfully merging this pull request may close these issues.

CMake: allow any compile-time config to be specified

4 participants