]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: Fix b2 build with postfixed compiler versions 62899/head
authorKefu Chai <tchaikov@gmail.com>
Mon, 21 Apr 2025 11:42:58 +0000 (19:42 +0800)
committerKefu Chai <tchaikov@gmail.com>
Tue, 22 Apr 2025 03:35:34 +0000 (11:35 +0800)
Previously, the build process used `bootstrap.sh` to build the b2 tool,
which automatically selected the compiler based on the specified toolset.
This failed when the compiler executable had a version postfix (e.g.,
/usr/bin/clang++-19) without a symlink at the expected name, producing
errors like:

```
A C++11 capable compiler is required for building the B2 engine.
Toolset 'clang' does not appear to support C++11.

> clang++ -x c++ -std=c++11 -pthread  check_clib.cpp check_cxx11.cpp
./tools/build/src/engine/build.sh: 120: clang++: not found
> clang++ -x c++ -std=c++11  check_clib.cpp check_cxx11.cpp
./tools/build/src/engine/build.sh: 120: clang++: not found

** Note, the C++11 capable compiler is _only_ required for building the B2
** engine. The B2 build system allows for using any C++ level and any other
** supported language and resource in your projects.

You can specify the toolset as the argument, i.e.:
    ./build.sh [options] gcc
```

The issue occurred because `bootstrap.sh` hardcodes the compiler name
based on the toolset (e.g., `clang++` for Clang) without supporting
postfixed versions.

This commit replaces the `bootstrap.sh` approach with an explicit build
command using Boost's `build.sh` script. We now:
1. Directly specify the full compiler path from CMake variables
2. Manually configure the build with `--cxx=...` and `--toolset=...`
3. Avoid reliance on symlinks or `bootstrap.sh`'s internal detection

This ensures the B2 engine is always built with the user-specified
compiler, even when installed with version postfixes.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
cmake/modules/BuildBoost.cmake

index b9c4a7ba8ba2f6c32d5dede7b66c4f69fc15b22d..a662591fbf9c37f5a43c9a3a6aa5a253e1346c56 100644 (file)
@@ -93,13 +93,15 @@ function(do_build_boost root_dir version)
     message(SEND_ERROR "unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
   endif()
 
-  # build b2 and prepare the project-config.jam for boost
+  # prepare the project-config.jam for boost
+  set(bjam <SOURCE_DIR>/b2)
   set(configure_command
     ./bootstrap.sh --prefix=<INSTALL_DIR>
     --with-libraries=${boost_with_libs}
-    --with-toolset=${toolset})
+    --with-toolset=${toolset}
+    --with-bjam=${bjam})
 
-  set(b2 ./b2)
+  set(b2 ${bjam})
   if(BOOST_J)
     message(STATUS "BUILDING Boost Libraries at j ${BOOST_J}")
     list(APPEND b2 -j${BOOST_J})
@@ -183,6 +185,13 @@ function(do_build_boost root_dir version)
     BUILD_BYPRODUCTS ${Boost_LIBRARIES}
     INSTALL_COMMAND ${install_command}
     PREFIX "${root_dir}")
+  ExternalProject_Add_Step(Boost build-bjam
+    COMMAND ./tools/build/src/engine/build.sh --cxx=${CMAKE_CXX_COMPILER} ${toolset}
+    COMMAND ${CMAKE_COMMAND} -E copy ./tools/build/src/engine/b2 ${bjam}
+    DEPENDEES download
+    DEPENDERS configure
+    COMMENT "Building B2 engine.."
+    WORKING_DIRECTORY <SOURCE_DIR>)
 endfunction()
 
 set(Boost_context_DEPENDENCIES thread chrono system date_time)