Skip to content

Commit 327ef3c

Browse files
authored
fixed #13822 - added hack to use header-only Boost with Visual Studio (danmar#7541)
1 parent 12b7eff commit 327ef3c

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

TUNING.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ Boost.Container (https://www.boost.org/doc/libs/release/libs/container) is being
2828

2929
As the used library is header-only implementation you only need to install the package on the system you build the binary on but not on the system you run the analysis on.
3030

31-
The official Windows binary is currently not using this (TODO: file ticket).
31+
The official Windows binary is currently not using this - see https://trac.cppcheck.net/ticket/13823 for details.
3232

33-
(TODO: enable usage by default / bail out when it is enforced)
33+
This will be used by default if Boost is detected in CMake. If you want to enforce the usage, you can use the CMake option `-DUSE_BOOST=On` which will cause the build to fail if no Boost was detected.
34+
35+
Using Visual Studio you need to provide a full Boost release (i.e. including binaries) for it to be detected by CMake. If you are not able to do this you can specify the CMake option `-DBOOST_INCLUDEDIR=<in>` (pointing to the directory which *contains* the `boost` include directory) to work around this (this is a Cppcheck specific hack) - see https://trac.cppcheck.net/ticket/13822 for more details.
36+
37+
If you are using `make` instead you need to specify `-DHAVE_BOOST` in the flags.
38+
39+
(TODO: document how to use with provided Visual Studio project)
3440

3541
### Use A Different Compiler
3642

cmake/findDependencies.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,21 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
8484
endif()
8585

8686
if(USE_BOOST)
87-
if(USE_BOOST STREQUAL "Auto")
87+
# with Visual Studio Boost is not detected by CMake unless you provide a full release even if only used header-only.
88+
# to work around this we allow to externally set BOOST_INCLUDEDIR.
89+
# see https://trac.cppcheck.net/ticket/13822 for more details.
90+
if(BOOST_INCLUDEDIR)
91+
if(NOT MSVC)
92+
message(FATAL_ERROR "BOOST_INCLUDEDIR hack only allowed for Visual Studio")
93+
endif()
94+
message(STATUS "Using BOOST_INCLUDEDIR hack for Visual Studio")
95+
if(NOT IS_READABLE "${BOOST_INCLUDEDIR}/boost/container/small_vector.hpp")
96+
message(FATAL_ERROR "Provided BOOST_INCLUDEDIR does not appear to contain Boost includes")
97+
endif()
98+
set(Boost_FOUND ON)
99+
set(Boost_INCLUDE_DIRS "${BOOST_INCLUDEDIR}")
100+
# TODO: set Boost_VERSION_STRING
101+
elseif(USE_BOOST STREQUAL "Auto")
88102
find_package(Boost)
89103
else()
90104
find_package(Boost REQUIRED)

0 commit comments

Comments
 (0)