3

I am attempting to create a CMake project with Visual Studio 2017. I want to add Boost to the project. While I can find Boost, it is unable to find the required components. My CMake looks like so.

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.10)

project ("FirstProject")

#This project heavily uses C++ 17
set (CMAKE_CXX_STANDARD 17)

#TESTING various flags to try and get it to work.
set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)

#Error calls for setting this, but doesn't work regardless.
set(BOOST_LIBRARYDIR "${BOOST_ROOT}/stage/lib")
find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem)
if(Boost_FOUND)
    message(WARNING "HERE!!")
endif()


# Include sub-projects.
add_subdirectory ("TestSubProject")

Given that I am Visual Studio it is compiling it like so.

cmake.exe  -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\User\CMakeBuilds\Hash\install\x86-Debug" \
-DBOOST_ROOT="D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0" \
-DBoost_COMPILER="vc141" \
-DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe" \
-DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe" \
-DCMAKE_BUILD_TYPE="Debug" \
-DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\Programming_Projects\C++\Dir\ProjectDir"

My Boost Library directory looks like enter image description here

The output from Visual Studio CMake is:

 CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
   New Boost version may have incorrect or missing dependencies and imported
   targets
 Call Stack (most recent call first):
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(902): (_Boost_COMPONENT_DEPENDENCIES)
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(1537): (_Boost_MISSING_DEPENDENCIES)
   CMakeLists.txt(20): (find_package)


 CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
   New Boost version may have incorrect or missing dependencies and imported
   targets
 Call Stack (most recent call first):
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(902): (_Boost_COMPONENT_DEPENDENCIES)
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(1537): (_Boost_MISSING_DEPENDENCIES)
   CMakeLists.txt(20): (find_package)


 CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1923 (message):
   Unable to find the requested Boost libraries.

   Boost version: 1.66.0

   Boost include path:
   D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0


   Could not find the following static Boost libraries:

           boost_filesystem

   Some (but not all) of the required Boost libraries were found.  You may
   need to install these additional Boost libraries.  Alternatively, set
   BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
   to the location of Boost.
Call Stack (most recent call first):
  CMakeLists.txt(20): (find_package)

-- Configuring incomplete, errors occurred!
See also "C:/Users/User/CMakeBuilds/57d076a1-4dfa-ba3f-98a5-b87b55e6d381/build/x86-Debug/CMakeFiles/CMakeOutput.log".
 C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe  -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\Christopher\CMakeBuilds\57d076a1-4dfa-ba3f-98a5-b87b55e6d381\install\x86-Debug"  -DBOOST_ROOT="D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0"  -DBoost_COMPILER="vc141"  -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe"  -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe"  -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\Programming_Projects\C++\Dir\ProjectDir" returned with exit code: 1
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:902 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1537 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:20 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:902 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1537 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:20 (find_package)
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1923 (message):
  Unable to find the requested Boost libraries.
  Boost version: 1.66.0
  Boost include path:
  D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0
  Could not find the following static Boost libraries:
          boost_filesystem
  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
  to the location of Boost.
Call Stack (most recent call first):
  CMakeLists.txt:20 (find_package)
cogle
  • 997
  • 1
  • 12
  • 25
  • 1
    Before `find_package(Boost)` additionally `set (Boost_DEBUG ON)` and see which library files are actually searched. – Tsyvarev Apr 25 '18 at 19:53
  • 3
    Please identify the CMake version you are using. Boost 1.66.0 does not work on pre 3.11.0 versions because of changes in the naming scheme. If you have to use this specific version then install the last published CMake version (3.11.1) and generate the solution with it. Visual Studio 2017 will open it too but you should avoid to update your CMakeLists.txt from VS2017 then. Otherwise Boost 1.65.1 is the last known version to work flawlessly with CMake 3.10. – vre Apr 25 '18 at 20:03
  • Your CMake version is not recent enough for your Boost version, cf. https://stackoverflow.com/a/42124857/2799037 – usr1234567 Apr 25 '18 at 20:10
  • Thanks, for that link. I was unaware that CMake 3.10 did not support what I was wanting. Is there a website, besides the stackoverflow link, with the current status of what Boost is supported by CMake? Just for possible future reference. – cogle Apr 25 '18 at 20:38
  • I am not aware of one. But you can always have a look into `FindBoost.cmake` and search for `_Boost_KNOWN_VERSIONS` to find out what versions your CMake supports. – vre Apr 25 '18 at 21:01
  • If you want to make it an answer I will gladly upvote and accept it. Upgrading my CMake version rectified my problem. – cogle Apr 25 '18 at 21:32
  • Glad it worked :) – vre Apr 25 '18 at 22:24

1 Answers1

4

Reformulating my previous comments as answer:

Boost 1.66.0 does not work on pre 3.11.0 CMake versions because of changes in the naming scheme. If you have to use this specific version then you need to install a suitable CMake version (3.11.0 or newer) and generate the solution with it. Otherwise Boost 1.65.1 is the last known version to work out of the box and flawlessly with CMake 3.10.

To find out what Boost versions your CMake can handle please have a look into FindBoost.cmake in Modules directory and search for _Boost_KNOWN_VERSIONS variable.

vre
  • 6,041
  • 1
  • 25
  • 39
  • 3
    You can also check the Git log of FindBoost.cmake to see which version has been added last.https://gitlab.kitware.com/cmake/cmake/commits/master/Modules/FindBoost.cmake – usr1234567 Apr 25 '18 at 22:26