Skip to content

Commit eee6798

Browse files
committed
Feat: Prepare CXX_MODULES tests
1 parent 6a0bc94 commit eee6798

File tree

12 files changed

+90
-51
lines changed

12 files changed

+90
-51
lines changed

CMakeLists.txt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME})
3434
set(TARGET_LIBRARY ${PROJECT_NAME})
3535
set(TARGET_ALIAS ${TARGET_NAMESPACE}::${TARGET_NAME})
3636
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
37-
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-config-targets)
37+
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)
3838

3939
#========================== post project settings ==============================
4040
# Tell CMake that we explicitly want `import std`.
@@ -45,13 +45,29 @@ if(${CMAKE_CXX_STANDARD} IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD)
4545
message(STATUS "CMAKE_CXX_MODULE_STD=${CMAKE_CXX_MODULE_STD}")
4646
endif()
4747

48+
add_library(${TARGET_NAME} STATIC)
49+
50+
# CMake requires the language standard to be specified as compile feature
51+
# when a target provides C++23 modules and the target will be installed
52+
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_23)
53+
4854
if(CMAKE_CXX_SCAN_FOR_MODULES AND ${CMAKE_GENERATOR} STREQUAL Ninja)
4955
set(BEMAN_USE_MODULES ON)
5056
message(STATUS "BEMAN_USE_MODULES=${BEMAN_USE_MODULES}")
57+
target_compile_definitions(${TARGET_NAME} PUBLIC BEMAN_USE_MODULES)
5158
else()
5259
message(WARNING "Missing support for CMAKE_CXX_SCAN_FOR_MODULES!")
5360
endif()
5461

62+
if(BEMAN_USE_MODULES AND CMAKE_CXX_MODULE_STD)
63+
set(BEMAN_HAS_IMPORT_STD ON)
64+
message(STATUS "BEMAN_HAS_IMPORT_STD=${BEMAN_HAS_IMPORT_STD}")
65+
target_compile_definitions(${TARGET_NAME} PUBLIC BEMAN_HAS_IMPORT_STD)
66+
else()
67+
set(CMAKE_CXX_MODULE_STD OFF)
68+
message(WARNING "Missing support for CMAKE_CXX_MODULE_STD!")
69+
endif()
70+
5571
# gersemi: off
5672
if(CMAKE_EXPORT_COMPILE_COMMANDS)
5773
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
@@ -61,17 +77,6 @@ if(CMAKE_EXPORT_COMPILE_COMMANDS)
6177
)
6278
endif()
6379
# gersemi: on
64-
65-
# CMake requires the language standard to be specified as compile feature
66-
# when a target provides C++23 modules and the target will be installed
67-
add_library(${TARGET_NAME} STATIC)
68-
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_23)
69-
70-
if(BEMAN_USE_MODULES AND CMAKE_CXX_MODULE_STD)
71-
target_compile_definitions(${TARGET_NAME} PUBLIC BEMAN_HAS_IMPORT_STD)
72-
else()
73-
message(WARNING "Missing support for CMAKE_CXX_MODULE_STD!")
74-
endif()
7580
#===============================================================================
7681

7782
option(

Makefile

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ endif
3131
LDFLAGS ?=
3232
SAN_FLAGS ?=
3333
CXX_FLAGS ?= -g
34-
# TODO: SANITIZER := release
35-
SANITIZER ?= default
34+
SANITIZER := release
35+
SANITIZER ?= RelWithDebInfo
3636
SOURCEDIR = $(CURDIR)
3737
BUILDROOT = build
3838
export hostSystemName:=$(shell uname -s)
39-
# TODO BUILD := $(BUILDROOT)/$(SANITIZER)
39+
BUILD := $(BUILDROOT)/$(SANITIZER)
4040
BUILD ?= $(BUILDROOT)/$(hostSystemName)/$(SANITIZER)
4141
EXAMPLE = beman.execution.examples.stop_token
4242

@@ -46,19 +46,19 @@ ifeq (${hostSystemName},Darwin)
4646
export LLVM_DIR:=$(shell realpath ${LLVM_PREFIX})
4747
export PATH:=${LLVM_DIR}/bin:${PATH}
4848

49-
# export CMAKE_CXX_STDLIB_MODULES_JSON=${LLVM_DIR}/lib/c++/libc++.modules.json
50-
# export CXX=clang++
51-
# export LDFLAGS=-L$(LLVM_DIR)/lib/c++ -lc++abi -lc++ # -lc++experimental
52-
# export GCOV="llvm-cov gcov"
49+
export CMAKE_CXX_STDLIB_MODULES_JSON=${LLVM_DIR}/lib/c++/libc++.modules.json
50+
export CXX=clang++
51+
export LDFLAGS=-L$(LLVM_DIR)/lib/c++ -lc++abi # NO! -lc++ -lc++experimental
52+
export GCOV="llvm-cov gcov"
5353

5454
### TODO: to test g++-15:
5555
export GCC_PREFIX:=$(shell brew --prefix gcc)
5656
export GCC_DIR:=$(shell realpath ${GCC_PREFIX})
5757

58-
export CMAKE_CXX_STDLIB_MODULES_JSON=${GCC_DIR}/lib/gcc/current/libstdc++.modules.json
59-
export CXX:=g++-15
60-
export CXXFLAGS:=-stdlib=libstdc++
61-
export GCOV="gcov"
58+
# export CMAKE_CXX_STDLIB_MODULES_JSON=${GCC_DIR}/lib/gcc/current/libstdc++.modules.json
59+
# export CXX:=g++-15
60+
# export CXXFLAGS:=-stdlib=libstdc++
61+
# export GCOV="gcov"
6262
else ifeq (${hostSystemName},Linux)
6363
export LLVM_DIR=/usr/lib/llvm-20
6464
export PATH:=${LLVM_DIR}/bin:${PATH}
@@ -95,9 +95,9 @@ ifeq ($(SANITIZER),lsan)
9595
endif
9696

9797
# TODO: beman.execution.examples.modules
98-
# FIXME: beman.execution.execution-module.test beman.execution.stop-token-module.test
98+
FIXME: beman.execution.execution-module.test beman.execution.stop-token-module.test
9999

100-
default: test
100+
# XXX: NO! $(SANITIZER): test
101101

102102
all: $(SANITIZERS)
103103

@@ -111,16 +111,19 @@ doc:
111111
# $(MAKE) SANITIZER=$@
112112

113113
build:
114-
cmake --fresh -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
114+
cmake -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
115115
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
116116
-D CMAKE_SKIP_INSTALL_RULES=ON \
117117
-D CMAKE_CXX_STANDARD=23 \
118118
-D CMAKE_CXX_EXTENSIONS=ON \
119119
-D CMAKE_CXX_STANDARD_REQUIRED=ON \
120-
-D CMAKE_CXX_COMPILER=$(CXX) # XXX -D CMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
120+
-D CMAKE_CXX_SCAN_FOR_MODULES=ON \
121+
-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=OFF \
122+
-D CMAKE_BUILD_TYPE=$(SANITIZER) \
123+
-D CMAKE_CXX_COMPILER=$(CXX) # XXX --fresh -D CMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
121124
cmake --build $(BUILD)
122125

123-
# NOTE: without install, see CMAKE_SKIP_INSTALL_RULES! CK
126+
# NOTE: may w/o enabled install, see CMAKE_SKIP_INSTALL_RULES! CK
124127
test: build
125128
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure
126129

cmake/CMakeUserPresets.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@
2222
"configurePreset": "release",
2323
"configuration": "Release",
2424
"targets": [
25-
"all_verify_interface_header_sets",
2625
"all"
2726
]
27+
},
28+
{
29+
"name": "verify",
30+
"configurePreset": "release",
31+
"configuration": "Release",
32+
"targets": [
33+
"all_verify_interface_header_sets"
34+
]
2835
}
2936
],
3037
"testPresets": [

cmake/presets/CMakeGenericPresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 6,
2+
"version": 9,
33
"configurePresets": [
44
{
55
"name": "root-config",

cmake/presets/CMakeLinuxPresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 6,
2+
"version": 9,
33
"include": [
44
"CMakeGenericPresets.json"
55
],

cmake/presets/CMakeWindowsPresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": 6,
2+
"version": 9,
33
"include": [
44
"CMakeGenericPresets.json"
55
],

examples/modules.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import std;
1111

1212
#endif
1313

14-
#if __cpp_modules < 201907L
15-
#include <beman/execution/execution.hpp>
16-
#else
1714
import beman_execution;
18-
#endif
1915

2016
namespace ex = beman::execution;
2117

2218
int main() {
19+
#ifdef USE_THIS_CODE
2320
auto [result] = ex::sync_wait(ex::when_all(ex::just(std::string("hello, ")), ex::just(std::string("world"))) |
2421
ex::then([](const auto& s1, const auto& s2) { return s1 + s2; }))
2522
.value_or(std::tuple(std::string("oops")));
2623
std::cout << "result='" << result << "'\n";
24+
#else
25+
std::println("ex::version = {}", ex::version);
26+
#endif
2727
}

src/beman/execution/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ if(BEMAN_USE_MODULES)
200200
BASE_DIRS ${PROJECT_SOURCE_DIR}/src/beman/execution
201201
FILES ${PROJECT_SOURCE_DIR}/src/beman/execution/execution.cppm
202202
)
203+
else()
204+
set_target_properties(
205+
${TARGET_NAME}
206+
PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON
207+
)
203208
endif()
204209

205210
get_property(
@@ -209,8 +214,6 @@ get_property(
209214
)
210215
source_group("Header Files\\detail" FILES ${DETAIL_HEADER_FILES})
211216

212-
set_target_properties(${TARGET_NAME} PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)
213-
214217
if(NOT BEMAN_EXECUTION_ENABLE_INSTALL OR CMAKE_SKIP_INSTALL_RULES)
215218
return()
216219
endif()
@@ -221,7 +224,7 @@ install(
221224
ARCHIVE DESTINATION lib/$<CONFIG>
222225
FILE_SET ${TARGET_NAME}_public_headers
223226
FILE_SET ${TARGET_NAME}_detail_headers
224-
FILE_SET CXX_MODULES DESTINATION ${INSTALL_CONFIGDIR}/module
227+
FILE_SET CXX_MODULES DESTINATION ${INSTALL_CONFIGDIR}/cxx-modules
225228
# There's currently no convention for this location
226229
CXX_MODULES_BMI
227230
DESTINATION ${INSTALL_CONFIGDIR}/bmi-${CMAKE_CXX_COMPILER_ID}_$<CONFIG>

src/beman/execution/execution.cppm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@
33
// ----------------------------------------------------------------------------
44

55
module;
6+
7+
#ifndef BEMAN_HAS_IMPORT_STD
68
#include <execution>
79
#include <stop_token>
8-
#include <beman/execution/execution.hpp>
10+
#endif
11+
12+
// FIXME: #include <beman/execution/execution.hpp>
913
#include <beman/execution/stop_token.hpp>
1014

1115
export module beman_execution;
1216

17+
#ifdef BEMAN_HAS_IMPORT_STD
18+
import std;
19+
#endif
20+
1321
namespace beman::execution {
1422
export int version(0);
23+
1524
// [stoptoken.concepts], stop token concepts
1625
export using ::beman::execution::stoppable_token;
1726
export using ::beman::execution::unstoppable_token;
1827

1928
// [stoptoken], class stop_token
2029
export using ::beman::execution::stop_token;
2130

31+
#ifdef USE_THIS_CODE
2232
// [stopsource], class stop_source
2333
export using ::beman::execution::stop_source;
2434

@@ -218,5 +228,6 @@ export using ::beman::execution::sync_wait;
218228

219229
// [exec.with.awaitable.senders]
220230
//-dk:TODO export using ::beman::execution::with_awaitable_senders;
231+
#endif
221232

222233
} // namespace beman::execution

tests/beman/execution/execution-module.test.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
#include <test/execution.hpp>
5-
#if 1
6-
#include <beman/execution/execution.hpp>
5+
6+
#ifdef BEMAN_HAS_IMPORT_STD
7+
import std;
78
#else
8-
import beman_execution;
9+
#include <execution>
910
#endif
1011

12+
import beman_execution;
13+
1114
// ----------------------------------------------------------------------------
1215

1316
namespace {
@@ -22,11 +25,11 @@ using error_types_of_t = test_stdex::error_types_of_t<S>;
2225

2326
TEST(execution_modules) {
2427
#if 0
25-
//-dk:TOD enable execution policies
26-
test::use_type<test_std::sequenced_policy>();
27-
test::use_type<test_std::parallel_policy>();
28-
test::use_type<test_std::parallel_unsequenced_policy>();
29-
test::use_type<test_std::unsequenced_policy>();
28+
//-dk:TODO enable execution policies
29+
test::check_type<test_std::sequenced_policy>();
30+
test::check_type<test_std::parallel_policy>();
31+
test::check_type<test_std::parallel_unsequenced_policy>();
32+
test::check_type<test_std::unsequenced_policy>();
3033

3134
test::use(test_std::seq);
3235
test::use(test_std::par);

0 commit comments

Comments
 (0)