boostorg / cmake

CMake support infrastructure Boost submodule
94 stars 27 forks source link

Cannot find `BoostRoot.cmake` when using CMake to compile source codes. #24

Closed hwhsu1231 closed 1 year ago

hwhsu1231 commented 2 years ago

Descriptions

I tried to use CMake to compile the source codes. However, it failed with the following errors:

CMake Error at CMakeLists.txt:20 (include):
  include could not find requested file:

    BoostRoot

-- Configuring incomplete, errors occurred!

Therefore, I went to check the project folder, but didn't find BoostRoot.cmake.

Besides, I found that all of folders inside the tools folder are EMPTY, too.

What happened? What do I miss?

Steps of Installation

Click to expand 1. Download and unzip the source code. [boost-1.79.0.zip](https://github.com/boostorg/boost/archive/refs/tags/boost-1.79.0.zip) 2. Open Windows Terminal (`cmd.exe`) and change to the project folder. ``` cd boost-1.79.0 ``` 3. call `vcvarsall.bat x64` to preload the MSVC environment. ``` vcvarsall x64 ``` 4. Create the build folder and change into it. ``` md build-msvc16-x64 cd build-msvc16-x64 ``` 5. Configure the project with the generator `Ninja Multi-Config`. ``` cmake ../cmake -G"Ninja Multi-Config" ```

Logs

Click to expand ```cmd C:\ccxxpkgs\source\boost-1.79.0>md build-msvc16-x64 C:\ccxxpkgs\source\boost-1.79.0>cd build-msvc16-x64 C:\ccxxpkgs\source\boost-1.79.0\build-msvc16-x64>vcvarsall x64 ********************************************************************** ** Visual Studio 2019 Developer Command Prompt v16.11.16 ** Copyright (c) 2021 Microsoft Corporation ********************************************************************** [vcvarsall.bat] Environment initialized for: 'x64' C:\ccxxpkgs\source\boost-1.79.0\build-msvc16-x64>cmake .. -G"Ninja Multi-Config" -- The CXX compiler identification is MSVC 19.29.30145.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Error at CMakeLists.txt:20 (include): include could not find requested file: BoostRoot -- Configuring incomplete, errors occurred! See also "C:/ccxxpkgs/source/boost-1.79.0/build-msvc16-x64/CMakeFiles/CMakeOutput.log". ```

Screenshots

image

pdimov commented 2 years ago

Your step 1 only downloads the "boostorg/boost" repository, but not its submodules. You have to use git clone -b boost-1.79.0 --recurse-submodules https://github.com/boostorg/boost instead.

In addition, step 5 needs to be cmake .. instead of cmake ../cmake.

hwhsu1231 commented 2 years ago

@pdimov

I followed what you said to git clone the repository, and then use CMake to compile the source code. It WORKED.

Steps of Installation

Click to expand 1. git clone the source code. ``` git clone -b boost-1.79.0 --recurse-submodules https://github.com/boostorg/boost ``` 2. Open Windows Terminal (`cmd.exe`) and change to the project folder. ``` cd boost ``` 3. call `vcvarsall.bat x64` to preload the MSVC environment. ``` vcvarsall x64 ``` 4. Create the build folder and change into it. ``` md build-msvc16-x64 cd build-msvc16-x64 ``` 5. Configure the project with the generator `Ninja Multi-Config`. ``` cmake .. -G"Ninja Multi-Config" ``` 6. Open `cmake-gui` to edit some Cache Variables. After editing, press **Configure** and **Generate** buttons. Then, close it. ``` cmake-gui . BUILD_SHARED_LIBS=ON CMAKE_INSTALL_PREFIX=C:/ccxxpkgs/install/msvc16-x64/boost-1.79.0 ``` 7. Build the project with `Debug` and `Release` configurations. ``` cmake --build . --config Debug cmake --build . --config Release ``` 8. Install the project with `Debug` and `Release` configurations. ``` cmake --install . --config Debug cmake --install . --config Release ```

How to find_package() in CONFIG mode?

However, how do I use it with find_package() command in CONFIG mode?

The followings are my example code of CMakeLists.txt and the error messages:

My opinions

I think the reason why find_package() failed is because there didn't exist the boost-config.cmake file.

Take Qt for reference. There is a C:/Qt/6.3.1/msvc2019_64/lib/cmake/Qt6/Qt6Config.cmake. Therefore, we can use it with:

find_package(Qt6 CONFIG REQUIRED
  COMPONENTS Core Widget Gui
)
pdimov commented 2 years ago

Our CMake build does not have a master BoostConfig, so instead of find_package(Boost 1.79.0 CONFIG REQUIRED COMPONENTS filesystem regex asio) you will need

find_package(boost_filesystem 1.79.0 CONFIG REQUIRED)
find_package(boost_regex 1.79.0 CONFIG REQUIRED)
find_package(boost_asio 1.79.0 CONFIG REQUIRED)

We may add support for find_package(Boost) at some later date.

hwhsu1231 commented 2 years ago

@pdimov

Moreover, after downloading and unzipping the boost_1_79_0.zip provided in the Download page, I found that there doesn't exist CMakeLists.txt in the root directory. Does Boost official miss it?

Screenshots

image

hwhsu1231 commented 2 years ago

We may add support for find_package(Boost) at some later date.

I hope this feature supported as soon as possible.

pdimov commented 2 years ago

The Boost release archive has a slightly different layout - all headers from libs/<libname>/include/boost/ are moved into boost/ and deleted from their original location - so the CMake build doesn't support it, which is why we remove CMakeLists.txt from the release archive in order to not mislead people that it works.

hwhsu1231 commented 2 years ago

Why not use the same layout?

For me, I prefer to download the zipped source codes of the specific version. Therefore, I hope that Boost can be compiled with CMake and be used with find_package() in CONFIG mode, instead of MODULE mode.

pdimov commented 1 year ago

We now provide CMake-compatible archives on Github: https://github.com/boostorg/boost/releases. Release 1.81 does not support find_package(Boost) yet, but 1.82 will.

felixf4xu commented 1 year ago

just for information:

BoostRoot.cmake is in folder of tools/cmake, after git submodule is initialized.