'CMake can not find Boost Python

I'm trying to build 3d party application using CMake 3.17.5.

I have boost installed by vcpkg (on Windows). I checked I have boost-python installed by vcpkg.

I got the following error in CMake GUI:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find Boost (missing: python) (found version "1.75.0")
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/CMake/share/cmake-3.17/Modules/FindBoost.cmake:2166 (find_package_handle_standard_args)
  cmake/modules/FindUSDMonolithic.cmake:71 (find_package)
  cmake/defaults/Packages.cmake:34 (find_package)
  CMakeLists.txt:11 (include)

I tried setting CMAKE_TOOLCHAIN_FILE to vcpkg.cmake but it didn't hepled.

NOTE: CMake DOES find boost after I set Boost_INCLUDE_DIR to vcpkg/installed/x64-windows/include/ but it still have this weird error. Without setting this variable CMake can not find boost at all and error is different



Solution 1:[1]

You should find Python first:

find_package(Python3 REQUIRED COMPONENTS Development)
target_include_directories(MyTarget SYSTEM PRIVATE ${Python3_INCLUDE_DIRS})

find_package(Boost REQUIRED COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})
target_link_libraries(MyTarget PRIVATE Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1