Skip to content

Commit e143e4b

Browse files
committed
Prepare use of CMAKE_CXX_MODULE_STD
We need at least cmake v3.28! We need to set CMAKE_CXX_SCAN_FOR_MODULES too! cleanup after review
1 parent 451ce8e commit e143e4b

File tree

4 files changed

+70
-40
lines changed

4 files changed

+70
-40
lines changed

.github/workflows/ci_tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup build environment
2828
uses: lukka/get-cmake@latest
2929
with:
30-
cmakeVersion: "~3.25.0"
30+
cmakeVersion: "~3.28.0"
3131
ninjaVersion: "^1.11.1"
3232
- name: Setup MSVC
3333
if: startsWith(matrix.presets.platform, 'windows')
@@ -80,7 +80,7 @@ jobs:
8080
- name: Install Ninja
8181
uses: lukka/get-cmake@latest
8282
with:
83-
cmakeVersion: "~3.25.0"
83+
cmakeVersion: "~4.0.0"
8484
ninjaVersion: "^1.11.1"
8585
- name: Setup MSVC
8686
if: startsWith(matrix.platform.os, 'windows')
@@ -139,7 +139,7 @@ jobs:
139139
- name: Setup build environment
140140
uses: lukka/get-cmake@latest
141141
with:
142-
cmakeVersion: "~3.25.0"
142+
cmakeVersion: "~3.28.0"
143143
ninjaVersion: "^1.11.1"
144144
- name: Print installed softwares
145145
run: |
@@ -166,10 +166,10 @@ jobs:
166166
matrix:
167167
compilers:
168168
- class: GNU
169-
version: 14
169+
version: 15
170170
toolchain: "cmake/gnu-toolchain.cmake"
171171
- class: GNU
172-
version: 13
172+
version: 14
173173
toolchain: "cmake/gnu-toolchain.cmake"
174174
- class: LLVM
175175
version: 20
@@ -183,7 +183,7 @@ jobs:
183183
- name: Setup build environment
184184
uses: lukka/get-cmake@latest
185185
with:
186-
cmakeVersion: "~3.25.0"
186+
cmakeVersion: "~4.0.0"
187187
ninjaVersion: "^1.11.1"
188188
- name: Install Compiler
189189
id: install-compiler

CMakeLists.txt

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
cmake_minimum_required(VERSION 3.28)
3+
if(CMAKE_CXX_STANDARD STREQUAL 26)
4+
set(CMAKE_CXX_SCAN_FOR_MODULES 1)
5+
set(CMAKE_CXX_MODULE_STD 1)
6+
if(CMAKE_CXX_MODULE_STD)
7+
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
8+
"d0edc3af-4c50-42ea-a356-e2862fe7a444"
9+
)
10+
endif()
11+
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
12+
endif()
13+
14+
cmake_minimum_required(VERSION 3.28...4.0)
415

516
project(
617
beman.scope
@@ -31,7 +42,7 @@ option(
3142
${PROJECT_IS_TOP_LEVEL}
3243
)
3344

34-
add_library(beman.scope)
45+
add_library(beman.scope INTERFACE)
3546
add_library(beman::scope ALIAS beman.scope)
3647

3748
# gersemi: off
@@ -43,17 +54,29 @@ set_target_properties(
4354
EXPORT_NAME scope
4455
)
4556

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+
if(CMAKE_CXX_SCAN_FOR_MODULES)
58+
target_compile_features(beman.scope PRIVATE cxx_std_23)
59+
target_sources(
60+
beman.scope
61+
PUBLIC
62+
FILE_SET HEADERS
63+
BASE_DIRS include
64+
FILES include/beman/scope/scope.hpp
65+
PUBLIC
66+
FILE_SET CXX_MODULES
67+
BASE_DIRS include
68+
FILES include/beman/scope/beman.scope.cppm
69+
)
70+
else()
71+
target_compile_features(beman.scope INTERFACE cxx_std_20)
72+
target_sources(
73+
beman.scope
74+
INTERFACE
75+
FILE_SET HEADERS
76+
BASE_DIRS include
77+
FILES include/beman/scope/scope.hpp
78+
)
79+
endif()
5780

5881
include(GNUInstallDirs)
5982

@@ -63,7 +86,6 @@ install(
6386
EXPORT beman.scope-targets
6487

6588
FILE_SET CXX_MODULES
66-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
6789
FILE_SET HEADERS
6890
)
6991

tests/CMakeLists.txt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ include(FetchContent)
55
FetchContent_Declare(
66
Catch2
77
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
8-
GIT_TAG v3.8.0
8+
GIT_TAG v3.8.1
9+
SYSTEM
10+
# FIXME: FIND_PACKAGE_ARGS 3.8.1
911
)
1012
FetchContent_MakeAvailable(Catch2)
1113

@@ -15,18 +17,21 @@ message("Tests to be built: ${ALL_TESTNAMES}")
1517

1618
include(Catch)
1719

18-
add_executable(test.module)
19-
target_sources(test.module PRIVATE module.test.cpp)
20-
target_link_libraries(test.module PRIVATE beman::scope)
21-
add_test(NAME test.module COMMAND test.module)
22-
23-
# todo: gc++15 module and catch incompatiblity?
24-
# target_link_libraries(
25-
# test.module
26-
# PUBLIC FILE_SET TYPE CXX_MODULES include/beman/scope/beman.scope.cppm
27-
# PRIVATE Catch2::Catch2WithMain beman::scope
28-
# )
29-
# catch_discover_tests(test.module)
20+
if(CMAKE_CXX_SCAN_FOR_MODULES)
21+
add_executable(test.module)
22+
target_sources(test.module PRIVATE module.test.cpp)
23+
target_compile_features(test.module PRIVATE cxx_std_23)
24+
target_link_libraries(test.module PRIVATE beman::scope)
25+
add_test(NAME test.module COMMAND test.module)
26+
27+
# XXX NO! target_compile_options(test.module PRIVATE "-fmodules")
28+
# target_link_libraries(
29+
# test.module
30+
# PUBLIC FILE_SET TYPE CXX_MODULES include/beman/scope/beman.scope.cppm
31+
# PRIVATE Catch2::Catch2WithMain beman::scope
32+
# )
33+
# catch_discover_tests(test.module)
34+
endif()
3035

3136
foreach(testname ${ALL_TESTNAMES})
3237
add_executable(test.${testname})

tests/module.test.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3+
// TODO(CK): import std;
4+
35
import beman.scope;
46
// #include <stdexcept>
57
// #include <string>
8+
// FIXME: #include <print>
69
#include <cassert>
710

811
// #define CATCH_CONFIG_MAIN
@@ -13,15 +16,16 @@ import beman.scope;
1316
// noisy_resource() { std::print( "construct noisy\n" ); }
1417
// ~noisy_resource() { std::print( "destroy noisy\n" ); }
1518
// };
19+
// clang-format on
1620

17-
//TEST_CASE("module-test", "[scope_module_test]") {
18-
int main()
19-
{
21+
// TEST_CASE("module-test", "[scope_module_test]") {
22+
int main() {
2023
bool exit_ran, success_ran, fail_ran = false;
2124
{
22-
beman::scope::scope_exit _([&exit_ran] { exit_ran = true; });
25+
beman::scope::scope_exit _([&exit_ran] { exit_ran = true; });
2326
beman::scope::scope_success _([&success_ran] { success_ran = true; });
24-
beman::scope::scope_fail _([&fail_ran] { fail_ran = true; });
27+
beman::scope::scope_fail _([&fail_ran] { fail_ran = true; });
28+
// FIXME:
2529
// auto resource_ptr = beman::scope::unique_resource(new noisy_resource(),
2630
// // Cleanup function
2731
// [](noisy_resource* ptr) { delete ptr; });
@@ -30,5 +34,4 @@ int main()
3034
assert(exit_ran == true);
3135
assert(success_ran == true);
3236
assert(fail_ran == false);
33-
34-
}
37+
}

0 commit comments

Comments
 (0)