Skip to content

Update Check for module support to include compiler versions#4709

Merged
vitaut merged 1 commit intofmtlib:masterfrom
MathewBensonCode:cmake_compiler_check
Mar 9, 2026
Merged

Update Check for module support to include compiler versions#4709
vitaut merged 1 commit intofmtlib:masterfrom
MathewBensonCode:cmake_compiler_check

Conversation

@MathewBensonCode
Copy link
Contributor

  • We need to confirm compiler support for module scanning before creating the CXX_MODULE FILE_SET using the target_sources command
  • This is especially relevant for compilers that have module support but do not support the module scanning such as g++13, clang15. For these we can use the older way of creating the fmt-module target

closes #4707

- We need to confirm compiler support for module scanning before
  creating the CXX_MODULE FILE_SET using the `target_sources` command
- This is especially relevant for compilers that have module support but
  do not support the module scanning such as g++13, clang15. For these
    we can use the older way of creating the fmt-module target
Comment on lines +65 to +72
if (
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 14)
OR(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 16)
OR(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
AND MSVC_VERSION GREATER_EQUAL 1934)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there is a more robust way than listing all the compiler versions? CMake should have all this information already. Don't they provide any way to check if module scanning is supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CMake does have this information, but it is only triggered automatically if we are using a minimum of CMake Version 3.28, i.e. set by the `cmake_minimum_required(VERSION 3.28[...4.2.3]) command. i.e. the first version number sets the policy.

As we have currently have the minimum set to 3.5 for backwards compatibility, we have to do the checks ourselves for the purpose of determining how we will be constructing the module target.

There is the CMAKE_CXX_SCAN_FOR_MODULES variable which has a related but different role. It simply triggers the scanning for modules and is not a reliable source of information for whether module support is available or not.

This is based on my understanding of the documentation.

Also based on testing, if you try g++-13 with the previous checks, i.e. cmake above 3.28 and Using Ninja as the generator, it throws an error stating that the compiler supports modules but not scanning.

@vitaut vitaut merged commit 2b4eb7d into fmtlib:master Mar 9, 2026
42 of 56 checks passed
@vitaut
Copy link
Contributor

vitaut commented Mar 9, 2026

Merged, thanks!

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.

CMake check for CXX_MODULEs does not factor in all compilers supported

3 participants