Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:

# CMake linting and formatting
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.23.2
rev: 0.24.0
hooks:
- id: gersemi
name: CMake linting
Expand All @@ -55,7 +55,7 @@ repos:
# Config file: pyproject.toml
# second Python code formatting
- repo: https://github.com/psf/black
rev: 25.11.0
rev: 25.12.0
hooks:
- id: black

Expand Down
29 changes: 17 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME})
set(TARGET_LIBRARY ${PROJECT_NAME})
set(TARGET_ALIAS ${TARGET_NAMESPACE}::${TARGET_NAME})
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-config-targets)
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)

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

add_library(${TARGET_NAME} STATIC)

# CMake requires the language standard to be specified as compile feature
# when a target provides C++23 modules and the target will be installed
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_23)

Comment on lines +48 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should/could this section be conditional on whether modules are available/enabled? It looks as if this is unconditionally set up. I believe beman::execution is currently build with multiple C++ standards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a target to set target_compile_features()

if(CMAKE_CXX_SCAN_FOR_MODULES AND ${CMAKE_GENERATOR} STREQUAL Ninja)
set(BEMAN_USE_MODULES ON)
message(STATUS "BEMAN_USE_MODULES=${BEMAN_USE_MODULES}")
target_compile_definitions(${TARGET_NAME} PUBLIC BEMAN_USE_MODULES)
else()
message(WARNING "Missing support for CMAKE_CXX_SCAN_FOR_MODULES!")
endif()

if(BEMAN_USE_MODULES AND CMAKE_CXX_MODULE_STD)
set(BEMAN_HAS_IMPORT_STD ON)
message(STATUS "BEMAN_HAS_IMPORT_STD=${BEMAN_HAS_IMPORT_STD}")
target_compile_definitions(${TARGET_NAME} PUBLIC BEMAN_HAS_IMPORT_STD)
else()
set(CMAKE_CXX_MODULE_STD OFF)
message(WARNING "Missing support for CMAKE_CXX_MODULE_STD!")
endif()

# gersemi: off
if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
Expand All @@ -61,17 +77,6 @@ if(CMAKE_EXPORT_COMPILE_COMMANDS)
)
endif()
# gersemi: on

# CMake requires the language standard to be specified as compile feature
# when a target provides C++23 modules and the target will be installed
add_library(${TARGET_NAME} STATIC)
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_23)

if(BEMAN_USE_MODULES AND CMAKE_CXX_MODULE_STD)
target_compile_definitions(${TARGET_NAME} PUBLIC BEMAN_HAS_IMPORT_STD)
else()
message(WARNING "Missing support for CMAKE_CXX_MODULE_STD!")
endif()
#===============================================================================

option(
Expand Down
60 changes: 39 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,39 @@ endif
LDFLAGS ?=
SAN_FLAGS ?=
CXX_FLAGS ?= -g
# TODO: SANITIZER := release
SANITIZER ?= default
# Note: disabled while working on CXX_MODULES! CK
# XXX: NO! SANITIZER := release
SANITIZER ?= RelWithDebInfo
SOURCEDIR = $(CURDIR)
BUILDROOT = build
export hostSystemName:=$(shell uname -s)
# TODO BUILD := $(BUILDROOT)/$(SANITIZER)
BUILD := $(BUILDROOT)/$(SANITIZER)
BUILD ?= $(BUILDROOT)/$(hostSystemName)/$(SANITIZER)
EXAMPLE = beman.execution.examples.stop_token

################################################
ifeq (${hostSystemName},Darwin)
export LLVM_PREFIX:=$(shell brew --prefix llvm)
export LLVM_PREFIX:=$(shell brew --prefix llvm)
export LLVM_DIR:=$(shell realpath ${LLVM_PREFIX})
export PATH:=${LLVM_DIR}/bin:${PATH}

# export CMAKE_CXX_STDLIB_MODULES_JSON=${LLVM_DIR}/lib/c++/libc++.modules.json
# export CXX=clang++
# export LDFLAGS=-L$(LLVM_DIR)/lib/c++ -lc++abi -lc++ # -lc++experimental
# export GCOV="llvm-cov gcov"
export CMAKE_CXX_STDLIB_MODULES_JSON=${LLVM_DIR}/lib/c++/libc++.modules.json
export CXX=clang++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer if the compiler were not defaulted like this in the Makefile (although I actually don't even know what export does in Makefiles; it seems something similar to bash's export).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Collaborator Author

@ClausKlein ClausKlein Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer if the compiler were not defaulted like this in the Makefile

as long the cmake feature is experimental and the compiler have problems to find there own json files for stdc++ lib it is needed in that way at leas on OSX!

you my try it in cmake code like here: https://github.com/ClausKlein/cmake-init-modules/blob/develop/cmake/prelude.cmake

export LDFLAGS=-L$(LLVM_DIR)/lib/c++ -lc++abi # NO! -lc++ -lc++experimental
export GCOV="llvm-cov gcov"

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

export CMAKE_CXX_STDLIB_MODULES_JSON=${GCC_DIR}/lib/gcc/current/libstdc++.modules.json
export CXX:=g++-15
export CXXFLAGS:=-stdlib=libstdc++
export GCOV="gcov"
# export CMAKE_CXX_STDLIB_MODULES_JSON=${GCC_DIR}/lib/gcc/current/libstdc++.modules.json
# export CXX:=g++-15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least, I prefer clang++ over g++-15: I'm mostly using Mac's with Apple silicon and there is no released gcc for these (as far as I know; there is patch from Ian Sandoe I managed to build but even so the result would be named g++-15 for me).

Copy link
Collaborator Author

@ClausKlein ClausKlein Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an option you may change like you want, also the version may be changed a you need.

# export CXXFLAGS:=-stdlib=libstdc++
# export GCOV="gcov"
else ifeq (${hostSystemName},Linux)
export LLVM_DIR=/usr/lib/llvm-20
export LLVM_DIR=/usr/lib/llvm-22
export PATH:=${LLVM_DIR}/bin:${PATH}
export CXX=clang++-20
export CXX=clang++-22
else
export CXX=$(COMPILER)
endif
Expand Down Expand Up @@ -94,33 +95,50 @@ ifeq ($(SANITIZER),lsan)
LDFLAGS = $(SAN_FLAGS)
endif

# TODO: beman.execution.examples.modules
# FIXME: beman.execution.execution-module.test beman.execution.stop-token-module.test
.PHONY: help FIXME TODO
help:
@echo "Use one of the folling targets:"
@echo ""
@echo "build -> use CXX_MODULES if possible"
@echo "test -> build and test "
@echo "debug -> preset with 'import std;'"
@echo "release -> preset with 'import std;'"
@echo "doc"
@echo "clean"
@echo "format"
@echo "distclean"

default: test
# TODO: beman.execution.examples.modules
FIXME: beman.execution.execution-module.test beman.execution.stop-token-module.test

all: $(SANITIZERS)
# Note: disabled while working on CXX_MODULES! CK
# XXX: NO! $(SANITIZER): test
# XXX all: $(SANITIZERS)

run: test
./$(BUILD)/examples/$(EXAMPLE)

doc:
doxygen docs/Doxyfile

# Note: disabled while working on CXX_MODULES! CK
# $(SANITIZERS):
# $(MAKE) SANITIZER=$@

build:
cmake --fresh -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
cmake -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
-D CMAKE_SKIP_INSTALL_RULES=ON \
-D CMAKE_CXX_STANDARD=23 \
-D CMAKE_CXX_EXTENSIONS=ON \
-D CMAKE_CXX_STANDARD_REQUIRED=ON \
-D CMAKE_CXX_COMPILER=$(CXX) # XXX -D CMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
-D CMAKE_CXX_SCAN_FOR_MODULES=ON \
-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=OFF \
-D CMAKE_BUILD_TYPE=$(SANITIZER) \
-D CMAKE_CXX_COMPILER=$(CXX) # XXX --fresh -D CMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
cmake --build $(BUILD)

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

Expand Down
9 changes: 8 additions & 1 deletion cmake/CMakeUserPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@
"configurePreset": "release",
"configuration": "Release",
"targets": [
"all_verify_interface_header_sets",
"all"
]
},
{
"name": "verify",
"configurePreset": "release",
"configuration": "Release",
"targets": [
"all_verify_interface_header_sets"
]
}
],
"testPresets": [
Expand Down
2 changes: 1 addition & 1 deletion cmake/presets/CMakeDarwinPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"hidden": true,
"cacheVariables": {
"CMAKE_CXX_STDLIB_MODULES_JSON": "$env{CMAKE_CXX_STDLIB_MODULES_JSON}",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
"CMAKE_BUILD_TYPE": "Release"
},
"condition": {
"type": "equals",
Expand Down
2 changes: 1 addition & 1 deletion cmake/presets/CMakeGenericPresets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 6,
"version": 9,
"configurePresets": [
{
"name": "root-config",
Expand Down
4 changes: 2 additions & 2 deletions cmake/presets/CMakeLinuxPresets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 6,
"version": 9,
"include": [
"CMakeGenericPresets.json"
],
Expand All @@ -22,7 +22,7 @@
"hidden": true,
"cacheVariables": {
"CMAKE_CXX_STDLIB_MODULES_JSON": "$env{CMAKE_CXX_STDLIB_MODULES_JSON}",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
"CMAKE_BUILD_TYPE": "Release"
},
"condition": {
"type": "equals",
Expand Down
2 changes: 1 addition & 1 deletion cmake/presets/CMakeWindowsPresets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 6,
"version": 9,
"include": [
"CMakeGenericPresets.json"
],
Expand Down
Loading