0

I'm writing a CMakeLists.txt, and it needs boost library. So I plan to download boost and run bootstrap_sh and b2.

But the problem is that it fails every first time I run cmake. After that, it succeeds every time. I don't know why.

Below is the CMakeLists.txt

cmake_minimum_required(VERSION 3.14)

project(example)

include(FetchContent)
FetchContent_Declare(
    boost
    URL https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz
    DOWNLOAD_EXTRACT_TIMESTAMP YES
)
FetchContent_MakeAvailable(boost)

execute_process(
    COMMAND sh bootstrap.sh
    WORKING_DIRECTORY ${boost_SOURCE_DIR}
)

And I execute like below.

mkdir build && cd build && cmake ..

Then I get this.

-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Building B2 engine..


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

** 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 gcc

Toolsets supported by this script are:
    acc, clang, como, gcc, intel-darwin, intel-linux, kcc, kylix, mipspro,
    pathscale, pgi, qcc, sun, sunpro, tru64cxx, vacpp

For any toolset you can override the path to the compiler with the CXX
environment variable. You can also use additional flags for the compiler
with the CXXFLAGS environment variable.

A special toolset; cxx, is available which is used as a fallback when a more
specific toolset is not found and the cxx command is detected. The 'cxx'
toolset will use the CXX, CXXFLAGS, and LIBS environment variables, if present.

Similarly, the cross-cxx toolset is available for cross-compiling by using the
BUILD_CXX, BUILD_CXXFLAGS, and BUILD_LDFLAGS environment variables to compile
binaries that will be executed on the build system. This allows CXX etc. to be
set for cross-compilers to be propagated to subprocesses.


Failed to build B2 build engine
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/weareff/workspace/cmake/example/build

After that, if I run cmake again, I get this, and it will finally succeed.

Building B2 engine..

###
###
### Using 'clang' toolset.
###
###

> clang++ --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I don't really get this behavior. Please give me any advice on this.

I checked the ${boost_SOURCE_DIR}, but I couldn't find anything helpful.

weareff
  • 1
  • 2
  • 1
    The call to `FetchContent_MakeAvailable(boost)` is effectively `add_subdirectory()`. That is, in such way you are building Boost with CMake and don't need bootstrapping. – Tsyvarev Feb 24 '23 at 12:48
  • @Tsyvarev Mmm, after FetchContent_MakeAvailable, there are only source files of boost. It seems like bootstrap.sh doesn't run at all. So I need the built binaries as static or dynamic ones and should run bootstrap.sh. What should I do better here? – weareff Feb 27 '23 at 05:22
  • "after FetchContent_MakeAvailable, there are only source files of boost." - You probably checked that after **configuration** (`cmake` running). But following **building** (`make` running) will produce Boost binaries. – Tsyvarev Feb 27 '23 at 06:44

0 Answers0