11# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22
3- cmake_minimum_required (VERSION 3.25 )
3+ cmake_minimum_required (VERSION 3.28 )
44
55project (
66 beman.scope
@@ -9,6 +9,19 @@ project(
99 VERSION 0.0.1
1010)
1111
12+ # gersemi: off
13+
14+ # Modules opt in only on compilers that support g++-15 and clang-20+
15+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20)
16+ set (CMAKE_CXX_SCAN_FOR_MODULES 1)
17+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
18+ set (CMAKE_CXX_SCAN_FOR_MODULES 1)
19+ elseif ()
20+ set (CMAKE_CXX_SCAN_FOR_MODULES 0)
21+ endif ()
22+
23+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
24+
1225# [CMAKE.SKIP_TESTS]
1326option (
1427 BEMAN_SCOPE_BUILD_TESTS
@@ -29,35 +42,61 @@ option(
2942 ${PROJECT_IS_TOP_LEVEL}
3043)
3144
32- add_library (beman.scope INTERFACE )
45+ message (
46+ "Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION} "
47+ )
48+ message (
49+ "cmake is: ${CMAKE_VERSION} modules scan : ${CMAKE_CXX_SCAN_FOR_MODULES} "
50+ )
51+
52+ if (CMAKE_CXX_SCAN_FOR_MODULES)
53+ add_library (beman.scope)
54+ target_sources (
55+ beman.scope
56+ PUBLIC
57+ FILE_SET HEADERS
58+ BASE_DIRS include
59+ FILES include /beman/scope/scope.hpp
60+ PUBLIC
61+ FILE_SET CXX_MODULES
62+ BASE_DIRS include
63+ FILES include /beman/scope/beman.scope.cppm
64+ )
65+ else ()
66+ add_library (beman.scope INTERFACE )
67+ target_sources (
68+ beman.scope
69+ INTERFACE
70+ FILE_SET HEADERS
71+ BASE_DIRS include
72+ FILES include /beman/scope/scope.hpp
73+ )
74+ endif ()
75+
3376add_library (beman::scope ALIAS beman.scope)
3477
35- # gersemi: off
3678set_target_properties (
3779 beman.scope
3880 PROPERTIES
3981 VERIFY_INTERFACE_HEADER_SETS ON
4082 EXPORT_NAME scope
4183)
4284
43- target_sources (
44- beman.scope
45- INTERFACE
46- FILE_SET HEADERS
47- BASE_DIRS include
48- FILES include /beman/scope/scope.hpp
49- )
85+ include (GNUInstallDirs)
5086
5187install (
5288 TARGETS beman.scope
53- EXPORT beman.scope-targets
5489 COMPONENT beman.scope
90+ EXPORT beman.scope-targets
91+
92+ FILE_SET CXX_MODULES
93+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
5594 FILE_SET HEADERS
5695)
96+
5797# gersemi: on
5898
5999if (BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE)
60- include (GNUInstallDirs)
61100 include (CMakePackageConfigHelpers)
62101
63102 write_basic_package_version_file(
@@ -77,6 +116,7 @@ if(BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE)
77116 EXPORT beman.scope-targets
78117 DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/beman.scope
79118 NAMESPACE beman::
119+ CXX_MODULES_DIRECTORY cxx-modules
80120 COMPONENT beman.scope
81121 )
82122endif ()
0 commit comments