Update Check for module support to include compiler versions#4709
Update Check for module support to include compiler versions#4709vitaut merged 1 commit intofmtlib:masterfrom
Conversation
- 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
| 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) | ||
| ) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
Merged, thanks! |
target_sourcescommandcloses #4707