Skip to content

CMake and mbedtls-prepare-build user guide #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented May 26, 2025

As requested, here is a description of how the kinds of builds that I typically do as an Mbed TLS maintainer, and how to do them with CMake and with mbedtls-prepare-build.

My main annoyances with CMake are:

  • No convenient way to tweak the configuration in each directory. Using a named config or a custom config should not require editing a file. This may be doable with a wrapper over CMake, but it would need to tweak CFLAGS in order to inject a directory early in the include path.
  • A straightforward way to reproduce a build directory. This is an indirect requirement on the build setup tool: basically everything should be doable with a single command.
  • Inconsistent and incomplete targets. This requires intervention in CMakeLists.txt.


#### Build in the full configuration

With CMake: ???
Copy link
Contributor Author

@gilles-peskine-arm gilles-peskine-arm May 26, 2025

Choose a reason for hiding this comment

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

Pending in Mbed-TLS/mbedtls#10038.

A build directory in the full configuration is something I do very often. It's currently broken with mbedtls-prepare-build in Mbed TLS, because mbedtls-prepare-build needs some refactoring to handle more than one config file. I expect I'll fix that soonish.


### Set and unset individual options

CMake doesn't have a direct way to tweak individual config options. You can write `#define` and `#undef` directives in a header file and pass that as the [user config file](#use-a-configuration-file-extension). To run `config.py`, ???
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A build directory with a tweaked configuration is something I do very often. I don't know how to do it with CMake.


Suppose that `source1/build-foo` contains a build tree with settings that you like, and you want to set up a similar build tree in a different directory `source2`. This is common when making backports, or to share how to reproduce an issue.

With CMake: ???
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ability to reproduce a build directory is very useful: to share how to reproduce an issue, to run the same tests on backports or a different approach to a patch, to make some tweaks such as one directory with debug symbols and one with Asan, etc. This has an impact on the design of the build directory generator: everything should end up being a single command (even if it contains &&). It doesn't work nearly as well if the reproduction steps have to include directory changes and version-dependent considerations, or worse, editing a file manually.


After changing branches, or rebasing an existing branch, the build scripts may have changed.

With CMake, ???
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re-running cmake .. in the build directory sometimes works, sometimes not. I'm not sure what to suggest other than removing and re-creating the build directory, but that requires the ability to reproduce a build directory.


#### Build with all drivers

CMake: ???
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a known missing feature which we'll resolve eventually for the sake of all.sh.


#### Enumerate build targets

With CMake, `make help` lists all available targets. Note that some target files must be given by their full path, while others must be given by their base name only, and some files can only be built via other targets.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The inconsistency and incompleteness of targets is an annoyance with our CMake scripts. Fortunately I don't think it's conceptually hard to solve, we just need some grunt work.


(Note that the test programs are in the `tests` subdirectories, but the name of the build target is just the base name.)

With mbedtls-prepare-build, append `.run` to build and run the program.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make test_suite_xxx.run and the associated conveniences in the next sections are something I use a lot. They could be implemented with an auxiliary script, but it's more convenient to have them right there in the build system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Development
Development

Successfully merging this pull request may close these issues.

1 participant