Skip to content

Conversation

@francisduffy
Copy link

When searching for Boost, CMake can use CMake's built-in FindBoost module or it can use the CMake config package provided by Boost itself. Boost provides this CMake config package since Boost 1.70. Note that the FindBoost module is deprecated, see here.

If you define the environment variables BOOST and BOOST_LIB64 and build as suggested, CMake's FindBoost module is used.

If you do not define BOOST and BOOST_LIB64 and instead pass -DDBOOST_DIR=/path/to/dir/with/BoostConfig.cmake to the CMake configure step, CMake will use the Boost CMake config package. If you are using a CMake version of 3.30 or above and CMAKE_POLICY_DEFAULT_CMP0167 is not set, you get a warning. To avoid the warning, you should set it to NEW via -DCMAKE_POLICY_DEFAULT_CMP0167=NEW as outlined here to prefer the Boost CMake package configuration.

The issue is that the build fails on Windows with this latter approach. There are link errors in QuantExt test suite and OREData test suite of the form:

LINK : fatal error LNK1104: cannot open file 'libboost_log_setup-vc143-mt-gd-x64-1_86.lib'

and for the ORE-SWIG:

LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc143-mt-gd-x64-1_86.lib'

The build works fine with module search mode.

Because BOOST_ALL_NO_LIB is not defined, Boost auto-linking is still on. For QuantExt test suite for example, we have the line

#include <boost/log/utility/setup/console.hpp>
which leads to boost/log/detail/setup_config.hpp and then boost/config/auto_link.hpp being included. This leads to /DEFAULTLIB:libboost_log_setup-<pattern>.lib getting written into the testsuite.cpp.obj file and hence the build fails if the Boost log_setup library is not provided at the link step. It is not requested explicitly at
find_package (Boost REQUIRED COMPONENTS ${COMPONENTS_CONDITIONAL} date_time thread serialization timer log filesystem OPTIONAL_COMPONENTS system chrono)
and only the Boost log library is requested.

When the FindBoost module is used, it has a list of dependencies that are pulled in. The dependencies for Boost log for CMake version 4.1 and Boost versions 1.83 to 1.86 for example are here. log has log_setup as a dependency. The path to libboost_log_setup-<pattern>.lib is then present at the link step and the link step works.

With Boost CMake config package mode, the path to libboost_log_setup-<pattern>.lib is not present at the link step because it was not explicitly requested above and the link step fails with the error above.

This PR fixes this in a minimal way. I will open another related PR that has other changes building on this but that may need more discussion.

The other change, i.e. addition of CMakeUserPresets.json to .gitignore, is standard to allow each user create their own CMake presets.

When find_package uses config search mode for Boost instead of the old
module search mode, there are Boost libraries missing in the link step:
- Boost::log_setup missing for QLE and ORED test suites.
- Boost::regex missing in ORE-SWIG build.

To build using the CMake config file provided by Boost, you do not
create the BOOST and BOOST_LIB64 environment variables and hence
BOOST_INCLUDEDIR and BOOST_LIBRARYDIR are not set in the presets.
You instead supply the path to BoostConfig.cmake in the variable
Boost_DIR. Also, if you are using CMake 3.30 and above, you should
set the variable CMAKE_POLICY_DEFAULT_CMP0167 to NEW to avoid
warnings about the policy not being set.

This issue is not apparent when you create the BOOST and BOOST_LIB64
environment variables because CMake uses the module mode search and the
CMake FindBoost.cmake module has entries of the form:
  set(_Boost_LOG_DEPENDENCIES log_setup regex ...)
so the dependencies on log_setup and regex are pulled in.

Note: to see the difference in the link commands, you need to keep the
.rsp files that are used to store the .obj and .lib file arguments. If
building with Ninja, you can do this by passing `-d keeprsp` to the
build step. From command line, something like this for example:
  cmake --build --preset=windows-ninja-x64-debug
    --target quantext-test-suite.exe --verbose -- -d keeprsp
or if you want to add it to the preset file for VS to pick up:
  "nativeToolOptions": [ "-d keeprsp" ]
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