Skip to content

Conversation

@ClausKlein
Copy link

@ClausKlein ClausKlein commented Jan 16, 2026

This is a prototype only to evaluate some concepts how we can work with CXX_MODULES

I added 3 cmake modules which can be included before and after project() call.

  • include(cmake/prelude.cmake)
  • project(...)
  • include(cxx-modules-rules)
  • if(BEMAN_HAS_MODULES)

    Require C++20 or newer with extensions for modules!

    target_compile_definitions(beman.exemplar PUBLIC BEMAN_HAS_MODULES)
    target_compile_features(beman.exemplar PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
  • endif()
  • include(beman-install-library-config) # Local fix only to install modules right!

All 3 are prepared to be integrated / merged into infra/cmake repo

They add 3 new global options:

  • BEMAN_HAS_MODULES:BOOL=ON
  • BEMAN_USE_STD_MODULE:BOOL=OFF
  • BEMAN_HAS_IMPORT_STD::BOOL=${CMAKE_CXX_SCAN_FOR_MODULES} # only if toolchain supports it.

Create a self contained CXX_MODULE

Add module usage example too that will be tested after staged install to build directory

8fbd480 Set BEMAN_USE_STD_MODULE=1 on gcc presets
76afe1e Disable BEMAN_USE_STD_MODULE for now
bb7b274 Add option BEMAN_USE_STD_MODULE
a77018c Disable CI tests with clang and libstdc++ for now
eb59178 Disable CI tests with gcc-13 for now
f1e4627 Add generic cmake modules to work with import std;
5afc6ca On UNIX Ninja is required to build CXX_MODULES
f0cb4e7 Require C++20 or newer with extensions for modules
83ddc05 Try to handle CI matrix complexity
fcd47ab Update googletest to v1.17.0 (reverted again)
0abf4a9 Modules opt in only on compilers that support it
0768b67 Use ctest --build-and-test to check the installed version
a4f2313 rm CMakeUserPresets.json (accidentally added)
18d3e51 Prepare CXX_MODULE usage

  • Local fix only to install modules right!
  • Need to define the default / minimum CMAKE_CXX_STANDARD value (17 or 20)!
  • some historic compiler should not longer used / supported!
  • install test on CI should not longer needed?
  • Cookiecutter is a nightmare, next week I will start to try

It depends on following PR:

fix #287 too

Add module usage example too

Create a self contained CXX_MODULE

Fix modules install path
@coveralls
Copy link

coveralls commented Jan 16, 2026

Coverage Status

coverage: 100.0%. remained the same
when pulling 802d221 on ClausKlein:feature/add_cxx_module
into 57fd7e9 on bemanproject:main.

@ClausKlein ClausKlein marked this pull request as draft January 16, 2026 21:18
@ClausKlein
Copy link
Author

ClausKlein commented Jan 18, 2026

@ednolan Please help, I can't fix some of the CI problems caused by infra structure

I disabled on CI C++26 tests with historic appleclang, gcc-13, clang-17, clang-18

@ClausKlein
Copy link
Author

ClausKlein commented Jan 21, 2026

@ednolan I disable the gcc-13 tests on CI for now

see ticket #290

and C++26 is not usable with apple clang, see #289

eb59178

@ClausKlein
Copy link
Author

How it works internally:

/Users/clausklein/Workspace/cpp/beman-project/exemplar/build/gcc-release
bash-5.3$ tree stagedir/
stagedir/
├── bin
│   ├── beman.exemplar.examples.identity_as_default_projection
│   ├── beman.exemplar.examples.identity_direct_usage
│   ├── beman.exemplar.examples.identity_module_usage
│   └── beman.exemplar.tests.identity
├── include
│   └── beman
│       └── exemplar
│           └── identity.hpp
└── lib
    ├── cmake
    │   └── beman.exemplar
    │       ├── beman.exemplar-config-version.cmake
    │       ├── beman.exemplar-config.cmake
    │       ├── beman.exemplar-targets-relwithdebinfo.cmake
    │       ├── beman.exemplar-targets.cmake
    │       ├── cxx-modules
    │       │   ├── cxx-modules-beman.exemplar-RelWithDebInfo.cmake
    │       │   ├── cxx-modules-beman.exemplar.cmake
    │       │   └── target-exemplar-RelWithDebInfo.cmake
    │       └── modules
    │           └── identity.cppm
    └── libbeman.exemplar.a

10 directories, 14 files
bash-5.3$ ninja
[4/4] Linking CXX executable stagedir/bin/beman.exemplar.tests.identity
ld: warning: ignoring duplicate libraries: 'lib/libgtest.a'
bash-5.3$ ctest
Test project /Users/clausklein/Workspace/cpp/beman-project/exemplar/build/gcc-release
    Start 1: IdentityTest.call_identity_with_int
1/9 Test #1: IdentityTest.call_identity_with_int ......................   Passed    0.01 sec
    Start 2: IdentityTest.call_identity_with_custom_type
2/9 Test #2: IdentityTest.call_identity_with_custom_type ..............   Passed    0.01 sec
    Start 3: IdentityTest.compare_std_vs_beman
3/9 Test #3: IdentityTest.compare_std_vs_beman ........................   Passed    0.01 sec
    Start 4: IdentityTest.check_is_transparent
4/9 Test #4: IdentityTest.check_is_transparent ........................   Passed    0.01 sec
    Start 5: install-to-stagedir
5/9 Test #5: install-to-stagedir ......................................   Passed    0.05 sec
    Start 6: find-package-test
6/9 Test #6: find-package-test ........................................   Passed    2.74 sec
    Start 7: beman.exemplar.examples.identity_direct_usage
7/9 Test #7: beman.exemplar.examples.identity_direct_usage ............   Passed    0.30 sec
    Start 8: beman.exemplar.examples.identity_module_usage
8/9 Test #8: beman.exemplar.examples.identity_module_usage ............   Passed    0.24 sec
    Start 9: beman.exemplar.examples.identity_as_default_projection
9/9 Test #9: beman.exemplar.examples.identity_as_default_projection ...   Passed    0.24 sec

100% tests passed, 0 tests failed out of 9

Total Test time (real) =   3.62 sec
bash-5.3$ !tree
tree stagedir/
stagedir/
├── bin
│   ├── beman.exemplar.examples.identity_as_default_projection
│   ├── beman.exemplar.examples.identity_direct_usage
│   ├── beman.exemplar.examples.identity_module_usage
│   └── beman.exemplar.tests.identity
├── include
│   └── beman
│       └── exemplar
│           └── identity.hpp
└── lib
    ├── cmake
    │   └── beman.exemplar
    │       ├── beman.exemplar-config-version.cmake
    │       ├── beman.exemplar-config.cmake
    │       ├── beman.exemplar-targets-relwithdebinfo.cmake
    │       ├── beman.exemplar-targets.cmake
    │       ├── cxx-modules
    │       │   ├── cxx-modules-beman.exemplar-RelWithDebInfo.cmake
    │       │   ├── cxx-modules-beman.exemplar.cmake
    │       │   └── target-exemplar-RelWithDebInfo.cmake
    │       └── modules
    │           └── identity.cppm
    └── libbeman.exemplar.a

10 directories, 14 files
bash-5.3$ cd -
/Users/clausklein/Workspace/cpp/beman-project/exemplar/build/gcc-release/tests/beman/exemplar/find-package-test
bash-5.3$ ninja
ninja: no work to do.
bash-5.3$ ctest
Test project /Users/clausklein/Workspace/cpp/beman-project/exemplar/build/gcc-release/tests/beman/exemplar/find-package-test
    Start 1: beman.exemplar.examples.identity_direct_usage
1/3 Test #1: beman.exemplar.examples.identity_direct_usage ............   Passed    0.23 sec
    Start 2: beman.exemplar.examples.identity_module_usage
2/3 Test #2: beman.exemplar.examples.identity_module_usage ............   Passed    0.23 sec
    Start 3: beman.exemplar.examples.identity_as_default_projection
3/3 Test #3: beman.exemplar.examples.identity_as_default_projection ...   Passed    0.28 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   0.75 sec
bash-5.3$ cmake -L .
-- use ccache
CMake Warning at /Users/clausklein/Workspace/cpp/beman-project/exemplar/cmake/prelude.cmake:46 (message):
  $CXX is not set
Call Stack (most recent call first):
  CMakeLists.txt:5 (include)


-- CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES=/usr/local/Cellar/gcc/15.2.0/include/c++/15;/usr/local/Cellar/gcc/15.2.0/include/c++/15/x86_64-apple-darwin23;/usr/local/Cellar/gcc/15.2.0/include/c++/15/backward;/usr/local/Cellar/gcc/15.2.0/lib/gcc/current/gcc/x86_64-apple-darwin23/15/include;/usr/local/Cellar/gcc/15.2.0/lib/gcc/current/gcc/x86_64-apple-darwin23/15/include-fixed;/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include;/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks
-- CMAKE_CXX_SCAN_FOR_MODULES=ON
Examples to be built: identity_direct_usage;identity_module_usage;identity_as_default_projection
-- Configuring done (0.1s)
CMake Warning (dev) in CMakeLists.txt:
  CMake's support for `import std;` in C++23 and newer is experimental.  It
  is meant only for experimentation and feedback to CMake developers.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/beman-project/exemplar/build/gcc-release/tests/beman/exemplar/find-package-test
-- Cache values
BEMAN_HAS_MODULES:BOOL=ON
BEMAN_USE_STD_MODULE:BOOL=OFF
CCACHE_EXECUTABLE:FILEPATH=/usr/local/bin/ccache
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
CMAKE_CXX_COMPILER_LAUNCHER:PATH=/usr/local/bin/ccache
CMAKE_C_COMPILER_LAUNCHER:PATH=/usr/local/bin/ccache
CMAKE_INSTALL_PREFIX:PATH=/Users/clausklein/.local
CMAKE_MAKE_PROGRAM:FILEPATH=/Users/clausklein/.local/bin/ninja
CMAKE_OSX_ARCHITECTURES:STRING=
CMAKE_OSX_DEPLOYMENT_TARGET:STRING=
CMAKE_OSX_SYSROOT:STRING=
beman.exemplar_DIR:PATH=/Users/clausklein/Workspace/cpp/beman-project/exemplar/build/gcc-release/stagedir/lib/cmake/beman.exemplar
bash-5.3$ 

@ClausKlein ClausKlein self-assigned this Jan 21, 2026
@ClausKlein ClausKlein marked this pull request as ready for review January 22, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The exported cmake config packages must be checked to be usable

2 participants