Skip to content

Update CMake standard to reflect FIAT and OOPS#30

Merged
msleigh merged 2 commits intoadd-cmake-standardfrom
add-fiat-oops-to-cmake
Nov 19, 2025
Merged

Update CMake standard to reflect FIAT and OOPS#30
msleigh merged 2 commits intoadd-cmake-standardfrom
add-fiat-oops-to-cmake

Conversation

@msleigh
Copy link
Member

@msleigh msleigh commented Nov 18, 2025

After comment from Olivier I extended to cover OOPS and FIAT CMakeLists.txt. This is for those changes.

(In further comments Olivier suggested we remove the part about over-riding compiler flags altogether, as (a) not well done here, but also (b) we don't know what the standard should be anyway. But I will do this afterwards, as a separate PR.)

Some repositories (e.g. **FIAT**, **OOPS**) contain both Fortran and C or C++ sources.
For such projects:

- Declare all used languages in ``project()``.

Choose a reason for hiding this comment

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

This is already covered under the "Project Declaration" section - in contrast the phrasing here almost seems to (wrongly) imply that repositories using only one language don't need to declare it. Or is it just me that gets that impression? Maybe a rewording would help? E.g. "Ensure all languages used are declared in project()"


Dual Build Mode Support
-----------------------
Projects should support both embedded and standalone builds::

Choose a reason for hiding this comment

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

All projects?

Copy link

@awnawab awnawab Nov 19, 2025

Choose a reason for hiding this comment

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

What do we mean here by "embedded" builds? The example seems to suggest that we should support IFS builds via add_subdirectory, which doesn't apply to components already moved to the bundle.

Perhaps we could amend the above to: "Sub-components, i.e. projects built via add_subdirectory invocations rather than via a separate bundle entry, should support both embedded and standalone builds. Fully standalone projects, e.g. ecWAM, should not support embedded builds."


- Declare all used languages in ``project()``.
- Apply language-specific flags via ``ecbuild_add_c_flags`` and ``ecbuild_add_fortran_flags``.
- Avoid setting shared flags (``CMAKE_C_FLAGS`` etc.) globally; handle each language separately.
Copy link

Choose a reason for hiding this comment

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

This line seems a little off, CMAKE_C_FLAGS would also only set c flags so they are not global. Instead it should be:

- Avoid adding compiler flags to the native CMAKE flags lists, as these are missing some of the safety and correctness checks present in the above `ecbuild` macros

Choose a reason for hiding this comment

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

I took the 'global' to mean the difference between e.g. CMAKE_C_FLAGS and IFS_C_FLAGS, but from the second half of the sentence you're probably right. Perhaps this should be two distinct points?

Copy link

@awnawab awnawab Nov 19, 2025

Choose a reason for hiding this comment

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

Ah yes good point, we can give both reasons to not write to these lists:

  • Are applied across the entire build (i.e. the bundle CMake superspace) and not just the current cmake project, which is risky
  • We lose the configure time sanity checks that ecbuild provides

- Avoid setting shared flags (``CMAKE_C_FLAGS`` etc.) globally; handle each language separately.
- Keep hardening or safety-specific C flags (stack protection, warnings) in
``cmake/compile_flags.cmake`` with clear comments explaining their purpose.
- Use ``target_compile_options()`` to apply per-target options instead of directory-wide flags.
Copy link

Choose a reason for hiding this comment

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

... to add compiler flags only to a specific target; these get appended to the project-wide flags already in place.


- Be isolated in a dedicated module (``cmake/compile_flags.cmake``)
- Be documented with a comment stating their motivation (e.g. memory safety, API conformance)
- Not be applied unconditionally across all targets
Copy link

@awnawab awnawab Nov 19, 2025

Choose a reason for hiding this comment

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

The compile_flags macros in all of our projects other than ifs-source are invoked at a cmake scope above those that declare targets. They typically contain calls to ecbuild_add_<lang>_flags and so their contents will be applied across the repository to all targets.

There's no straightforward to remedy that (the same cmake design flaw also makes setting source-file specific flags a lot harder), so we should simply remove this last statement.

Copy link

@cresswellp cresswellp Nov 19, 2025

Choose a reason for hiding this comment

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

Again, I'm looking at this from a very IFS-centric perspective, but in the context of extra-stringent flags I took "unconditionally" to mean "not protected by e.g. if (IFS_CHECK_BOUNDS) (the dangers of AI-written text...). I agree with your point but perhaps this should be clarified if it's not mentioned elsewhere.

Copy link

Choose a reason for hiding this comment

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

Hmm yes. In that case this could be something like "the application of these safety related compiler flags should be togglable via an option or configure-time cmake flag".

Standalone components (e.g. **FIAT**, **ecTrans**, **OOPS**) must export
CMake package configuration files for downstream discovery::

ecbuild_pkgconfig(
Copy link

Choose a reason for hiding this comment

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

As I understand it, this is only needed to package cmake projects for export to other non-cmake projects. It was needed during our migration to cmake, but now we don't need it, is never used or tested and is very likely as a result broken.

I would say we should explicitly deprecate the ecbuild_pkgconfig functionality in the ifs components, eccodes and such might still use it.

Choose a reason for hiding this comment

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

Some ifs sub-projects call it, perhaps it's worth checking with the owners if we can remove these?

- Limit compiler-specific conditionals to dedicated modules
- Provide consistent packaging and installation metadata across all components
- Maintain strict compatibility with ecbuild and CMake ≥ 3.20
- Define common helper macros in a shared ECMWF CMake toolkit
Copy link

Choose a reason for hiding this comment

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

Isn't that what ecbuild is already 😄

Copy link

@cresswellp cresswellp Nov 19, 2025

Choose a reason for hiding this comment

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

Well, now that you've brought it up, do we need to emphasise the role of ecbuild more strongly somewhere in the doc? At the moment the most weighted statement on the subject (as opposed to guidance for a specific function) is "Follow ecbuild conventions where available", which is a bit wishy washy.

Assuming that's done, then perhaps this line should be something like "Identify commonalities where new ecbuild macros may be shared across projects."

@msleigh msleigh merged commit 91b17ca into add-cmake-standard Nov 19, 2025
4 checks passed
@msleigh msleigh deleted the add-fiat-oops-to-cmake branch November 19, 2025 17:04
msleigh added a commit that referenced this pull request Nov 19, 2025
Copy link
Contributor

@prgillies prgillies left a comment

Choose a reason for hiding this comment

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

Added some minor comments. I couldn't comment on lines without changes so adding them here:
Naive question about 'buildable directories' line 62/64, eg arpifs doesn't have a CMakeLists.txt and the source is added in cmake/arpifs.cmake. Do the guidelines here cover that method.
How does the version specified with ecbuild_find_package (line 220/263 for eccodes) interact with the version in the bundle.yml? Presumably the bundle.yml version must be greater or equal to the version specified here?

msleigh added a commit that referenced this pull request Nov 25, 2025
msleigh added a commit that referenced this pull request Nov 25, 2025
msleigh added a commit that referenced this pull request Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants