Skip to content

Commit 2b4eb7d

Browse files
Update Check for module support to include compiler versions (#4709)
- 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 Co-authored-by: Mathew Benson <mathew@benson.co.ke>
1 parent c29b64d commit 2b4eb7d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,28 @@ endif ()
5050

5151
project(FMT CXX)
5252

53-
# Determine support for the C++ module scanning.
54-
# Requires C++20, CMake >= 3.28 and (Ninja >= 1.11 OR Visual Studio >= 17.4).
55-
set(FMT_USE_CMAKE_MODULES FALSE)
53+
# Determine support for the C++ module scanning and CXX_MODULE File_Sets
54+
# Requires C++20, CMake >= 3.28 and
55+
# Generators(Ninja >= 1.11 OR Visual Studio >= 17.4).
56+
# Compilers GCC>=14, Clang>=16 or MSVC >= 17.4
57+
# Source: https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html
58+
Set(FMT_USE_CMAKE_MODULES FALSE)
5659
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND CMAKE_CXX_STANDARD
5760
GREATER_EQUAL 20)
5861
if (CMAKE_GENERATOR STREQUAL "Ninja")
5962
execute_process(COMMAND "${CMAKE_MAKE_PROGRAM}" "--version"
6063
OUTPUT_VARIABLE NINJA_VERSION)
6164
if (NINJA_VERSION VERSION_GREATER_EQUAL 1.11)
65+
if (
66+
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
67+
AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 14)
68+
OR(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
69+
AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 16)
70+
OR(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
71+
AND MSVC_VERSION GREATER_EQUAL 1934)
72+
)
6273
set(FMT_USE_CMAKE_MODULES TRUE)
74+
endif ()
6375
endif ()
6476
elseif (CMAKE_GENERATOR MATCHES "^Visual Studio" AND MSVC_VERSION
6577
GREATER_EQUAL 1934)

0 commit comments

Comments
 (0)