Skip to content

Commit c73cceb

Browse files
committed
Detect module support with compiler versions
1 parent 1a0454c commit c73cceb

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

cmake/Autoconfig.cmake

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,34 @@ else()
2727
endif()
2828

2929
if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
30-
# check_cxx_source_compiles doesn't support modules (yet?) so we need to drop
31-
# to a raw try_compile.
32-
try_compile(
33-
HAS_CXX20_MODULES
34-
SOURCES_TYPE CXX_MODULE
35-
SOURCES "${CMAKE_CURRENT_LIST_DIR}/has_modules.cpp"
36-
CXX_STANDARD 20
37-
CXX_STANDARD_REQUIRED Yes
38-
CXX_EXTENSIONS Yes
39-
)
30+
# # check_cxx_source_compiles doesn't support modules (yet?) so we need to drop
31+
# # to a raw try_compile.
32+
# try_compile(
33+
# HAS_CXX20_MODULES
34+
# SOURCES_TYPE CXX_MODULE
35+
# SOURCES "${CMAKE_CURRENT_LIST_DIR}/has_modules.cpp"
36+
# CXX_STANDARD 20
37+
# CXX_STANDARD_REQUIRED Yes
38+
# CXX_EXTENSIONS Yes
39+
# )
40+
# https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html#compiler-support
41+
# msvc 14.34+/19.34+
42+
# clang 16+
43+
# gcc 15 and newer
44+
set(HAS_CXX20_MODULES FALSE)
45+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
46+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.34)
47+
set(HAS_CXX20_MODULES TRUE)
48+
endif()
49+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
50+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
51+
set(HAS_CXX20_MODULES TRUE)
52+
endif()
53+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
54+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0)
55+
set(HAS_CXX20_MODULES TRUE)
56+
endif()
57+
endif()
4058
endif()
4159

4260
if(NOT WIN32 OR MINGW)

0 commit comments

Comments
 (0)