Boost logo

Boost :

From: Dennis Luehring (dl.soluz_at_[hidden])
Date: 2021-07-16 07:01:23


Am 15.07.2021 um 13:52 schrieb Deniz Bahadir via Boost:
> One remark:
>
> Here you are explicitly depending on CMake's `FindBoost` script, because
> you neither use the `CONFIG` nor `NO_MODULE` argument (or any other
> argument not specified in the basic signature) for `find_package`. [1]
> Unless you explicitly set the `CMAKE_FIND_PACKAGE_PREFER_CONFIG`
> variable `find_package` always tries the "Module" mode first. And if it
> finds a suitable `Find*` script it will not try the "Config" mode (even
> if the `Find*` script is unable to find the package).
> That your `find_package(Boost ...)` call still tries the "Config" mode
> (if you again remove the `Boost_NO_BOOST_CMAKE` variable or set it to
> `FALSE`)is only due to the fact that the `FindBoost` script explicitly
> tries the `Config` mode first (unless you set the `Boost_NO_BOOST_CMAKE`
> variable to `TRUE`).
>
> So, in general I always recommend to explicitly use `find_package` in
> "Config" mode if one knows that the searched package was installed with
> a config-file for importing.
> For Boost this should be true since Boost 1.70.0. (Installing it without
> the config-file is not very sensible.)
>
>
> Happy cmaking,
> Deniz

i've reworked my CMakeLists.txt using that schema, using
CMAKE_PREFIX_PATH and CONFIG

works for linux, windows - includes and libraries correctly set to
make/VStudio project

-------------------

cmake_minimum_required(VERSION 3.14)

project (my_test)

if(UNIX AND NOT APPLE)
   set( MY_BOOST_DIR "/home/linux/temp/boost_1_75_0/_x64/lib/cmake" )
else()
   set( MY_BOOST_DIR "D:/temp/boost_1_75_0/_x64/lib/cmake" )
endif()

list(APPEND CMAKE_PREFIX_PATH ${MY_BOOST_DIR})

add_executable(test test.cpp)

find_package(Boost CONFIG REQUIRED COMPONENTS unit_test_framework)
message(STATUS "!! Boost_FOUND => ${Boost_FOUND}")

IF (Boost_FOUND)
   message(STATUS "!! Boost_INCLUDE_DIRS => ${Boost_INCLUDE_DIRS}")
   message(STATUS "!! BOOST_INCLUDE_DIR => ${BOOST_INCLUDE_DIR}")
   message(STATUS "!! BOOST_INCLUDEDIR => ${BOOST_INCLUDEDIR}")
   message(STATUS "!! Boost_LIBRARY_DIRS => ${Boost_LIBRARY_DIRS}")
   message(STATUS "!! BOOST_LIBRARYDIR => ${BOOST_LIBRARYDIR}")
   message(STATUS "!! Boost_LIBRARY_DIR => ${Boost_LIBRARY_DIR}")
   message(STATUS "!! Boost_LIBRARY_DIR_RELEASE =>
${Boost_LIBRARY_DIR_RELEASE}")
   message(STATUS "!! Boost_LIBRARY_DIR_DEBUG =>
${Boost_LIBRARY_DIR_DEBUG}")

   target_link_libraries(test ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
ENDIF()

------------------

the only thing i don't understand (after testing/working with serveral
"variants" of boost cmake integration) is

that not all of the find_package result-Vars are set - but this is the
first time that every CMake version or Platform returns absolute the
same results

but Boost_LIBRARY_DIRS is not set anymore - but maybe its just not needed

output: CMake 3.14,3.18,3.21 giving this output on windows and linux
(with a different path)

-- !! Boost_FOUND => 1
-- !! Boost_INCLUDE_DIRS => D:/temp/boost_1_75_0
-- !! BOOST_INCLUDE_DIR =>
-- !! BOOST_INCLUDEDIR =>
-- !! Boost_LIBRARY_DIRS =>
-- !! BOOST_LIBRARYDIR =>
-- !! Boost_LIBRARY_DIR =>
-- !! Boost_LIBRARY_DIR_RELEASE =>
-- !! Boost_LIBRARY_DIR_DEBUG =>

i know that some of these (nearly identical!!!) vars are
find_package-returns, cache-var or hints for finding the package - i
just print them all to understand whats happening

does that mean i've found the holy grail of clean boost cmake integration?

are the result correct that way (my co-worker said this "/lib/cmake" at
the end of CMAKE_PREFIX_PATH seems wrong - but Qt6 is it doing the same
way - so i think he is wrong)

thank for your help


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk