Fix build error when using CMake find_package config search mode for Boost #321
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When searching for Boost, CMake can use CMake's built-in
FindBoostmodule or it can use the CMake config package provided by Boost itself. Boost provides this CMake config package since Boost 1.70. Note that theFindBoostmodule is deprecated, see here.If you define the environment variables
BOOSTandBOOST_LIB64and build as suggested, CMake'sFindBoostmodule is used.If you do not define
BOOSTandBOOST_LIB64and instead pass-DDBOOST_DIR=/path/to/dir/with/BoostConfig.cmaketo the CMake configure step, CMake will use the Boost CMake config package. If you are using a CMake version of 3.30 or above andCMAKE_POLICY_DEFAULT_CMP0167is not set, you get a warning. To avoid the warning, you should set it toNEWvia-DCMAKE_POLICY_DEFAULT_CMP0167=NEWas 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:
and for the ORE-SWIG:
The build works fine with module search mode.
Because
BOOST_ALL_NO_LIBis not defined, Boost auto-linking is still on. For QuantExt test suite for example, we have the lineEngine/QuantExt/test/testsuite.cpp
Line 44 in 1c7fb03
boost/log/detail/setup_config.hppand thenboost/config/auto_link.hppbeing included. This leads to/DEFAULTLIB:libboost_log_setup-<pattern>.libgetting written into thetestsuite.cpp.objfile and hence the build fails if the Boostlog_setuplibrary is not provided at the link step. It is not requested explicitly atEngine/QuantExt/CMakeLists.txt
Line 17 in 1c7fb03
loglibrary is requested.When the
FindBoostmodule is used, it has a list of dependencies that are pulled in. The dependencies for Boostlogfor CMake version 4.1 and Boost versions 1.83 to 1.86 for example are here.loghaslog_setupas a dependency. The path tolibboost_log_setup-<pattern>.libis then present at the link step and the link step works.With Boost CMake config package mode, the path to
libboost_log_setup-<pattern>.libis 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.jsonto.gitignore, is standard to allow each user create their own CMake presets.