Skip to content

Commit c9f385d

Browse files
committed
explicit changes to module support based on compiler versions
1 parent 9639523 commit c9f385d

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

CMakeLists.txt

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,54 @@ option(
3131
${PROJECT_IS_TOP_LEVEL}
3232
)
3333

34-
add_library(beman.scope)
35-
add_library(beman::scope ALIAS beman.scope)
36-
3734
# gersemi: off
3835

36+
message(
37+
"Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}"
38+
)
39+
40+
# Modules opt in only on compilers that support g++-15 and clang-20
41+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20)
42+
set(CMAKE_CXX_SCAN_FOR_MODULES 1)
43+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
44+
set(CMAKE_CXX_SCAN_FOR_MODULES 1)
45+
endif()
46+
47+
if(CMAKE_CXX_SCAN_FOR_MODULES)
48+
add_library(beman.scope)
49+
# target_compile_features(beman.scope PRIVATE cxx_std_23)
50+
target_sources(
51+
beman.scope
52+
PUBLIC
53+
FILE_SET HEADERS
54+
BASE_DIRS include
55+
FILES include/beman/scope/scope.hpp
56+
PUBLIC
57+
FILE_SET CXX_MODULES
58+
BASE_DIRS include
59+
FILES include/beman/scope/beman.scope.cppm
60+
)
61+
else()
62+
add_library(beman.scope INTERFACE)
63+
# target_compile_features(beman.scope INTERFACE cxx_std_20)
64+
target_sources(
65+
beman.scope
66+
INTERFACE
67+
FILE_SET HEADERS
68+
BASE_DIRS include
69+
FILES include/beman/scope/scope.hpp
70+
)
71+
endif()
72+
73+
add_library(beman::scope ALIAS beman.scope)
74+
3975
set_target_properties(
4076
beman.scope
4177
PROPERTIES
4278
VERIFY_INTERFACE_HEADER_SETS ON
4379
EXPORT_NAME scope
4480
)
4581

46-
target_sources(
47-
beman.scope
48-
PUBLIC
49-
FILE_SET HEADERS
50-
BASE_DIRS include
51-
FILES include/beman/scope/scope.hpp
52-
PUBLIC
53-
FILE_SET CXX_MODULES
54-
BASE_DIRS include
55-
FILES include/beman/scope/beman.scope.cppm
56-
)
57-
5882
include(GNUInstallDirs)
5983

6084
install(

tests/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@ FetchContent_Declare(
99
)
1010
FetchContent_MakeAvailable(Catch2)
1111

12-
message(
13-
"Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION}"
14-
)
1512

1613
# module tests will only compile with gcc15 or clang20 and above
17-
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20)
18-
set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module)
19-
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
14+
if(CMAKE_CXX_SCAN_FOR_MODULES)
2015
set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource module)
2116
else()
2217
set(ALL_TESTNAMES scope_success scope_exit scope_fail unique_resource)

0 commit comments

Comments
 (0)