Skip to content

Fix C++ module installation - #714

Open
justend29 wants to merge 6 commits into
boost-ext:masterfrom
justend29:fix-module-install
Open

justend29 wants to merge 6 commits into
boost-ext:masterfrom
justend29:fix-module-install

Conversation

@justend29

@justend29 justend29 commented Sep 15, 2026

Copy link
Copy Markdown

Problem

The project's CMake does not correctly install the Boost::ut_module target - it just installs the ut.cppm file. This prevents consumption via find_package(ut) and target_link_libraries(... Boost::ut_module). The module target was also missing some required properties

  • The target was not installed in a cmake install() command.
  • cxx_std_23 (or any compile feature) was not enabled on the target. This is a requirement of import std
  • the CXX_IMPORT_STD target property was not set. This is a requirement of import std
  • the target did not link to the main ut target. Although the relative include (#include "ut.hpp") that previously existed in ut.cppm found the header, this missing link didn't classify the header as a SYSTEM header, thereby emitting warnings in consuming projects

Solution

The main issues were fixed by appying the respective CMake commands in fa6b5d8.

Subsequent optional commits applied additional cleaning to the CMakeLists.txt.

  1. Correct typos in the BOOST_UT_USE_WARNINGS_AS_ERRORS option

  2. Consolidate the configuring of the ut and ut_module targets into one location, instead of having a smattering of if(BOOST_UT_DISABLE_MODULE) everywhere

    The targets are also now located after CMAKE_CXX_FLAGS is setup to initialize the target properties.

  3. ut.hpp is now recorded in a header file set of the ut target.

  4. ut.cppm now uses fully qualified #include <boost/ut.hpp>.

  5. A test of Boost::ut_module

Testing

Building, installing, and consuming Boost::ut_module from a separate project was tested on both fa6b5d8 and the tip of this branch using g++ 16.2.1 and cmake 4.4.3. It doesn't appear that the Bazel or Meson build systems consider the C++ module, and I don't know how to use them. It's also confirmed that consuming projects no longer report warnings from the installed ut.hpp file when using Boost::ut_module

CMake Configure
cmake -S . -B build  -G Ninja \
  -D  -DCMAKE_BUILD_TYPE=Debug \
  -D BOOST_UT_DISABLE_MODULE=OFF \
  -D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD=f35a9ac6-8463-4d38-8eec-5d6008153e7d

Reviewers:
@kris-jusiak

Even on origin/master, the ut_test test fails during the build with BOOST_UT_ENABLE_RUN_AFTER_BUILD=ON, even though it passes when running ctest directly. Since I didn't introduce this, I won't delve into a solution, but here's the output for reference:

build_test_fail.log

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.

1 participant