CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

The Boost example does not work with CPM_USE_LOCAL_PACKAGES=YES

Open ClausKlein opened this issue 2 years ago • 4 comments

If I try the CPM.cmake v0.37.0 this is the result if the Boost Libraries are already installed on my build system:

-- CPM: Using local package [email protected]
-- Configuring done
CMake Error at CMakeLists.txt:21 (target_link_libraries):
  Target "CPMExampleBoost" links to:

    Boost::asio

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.



-- Generating done

ClausKlein avatar Feb 18 '23 10:02 ClausKlein

I think this is an issue with the boost library as it is not defining the same targets for the source and installed configuration?

TheLartians avatar Feb 20 '23 19:02 TheLartians

https://github.com/cpm-cmake/CPM.cmake/issues/501 here's working example.

Arniiiii avatar Aug 28 '23 12:08 Arniiiii

cmake_minimum_required(VERSION 3.14...3.28)

project(CPMExampleBoost LANGUAGES CXX)

# ---- Create binary ----

add_executable(CPMExampleBoost main.cpp)
target_compile_features(CPMExampleBoost PRIVATE cxx_std_17)

# ---- Dependencies ----

include(cmake/CPM.cmake)

set(Boost_DEBUG ON)

CPMFindPackage(
  NAME Boost
  VERSION 1.84.0
  URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
  URL_HASH SHA256=2e64e5d79a738d0fa6fb546c6e5c2bd28f88d268a2a080546f74e5ff98f29d0e
  OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_INCLUDE_LIBRARIES container\\\;asio" # Note the escapes!
  FIND_PACKAGE_ARGUMENTS "REQUIRED COMPONENTS container\\\;asio"
)

target_link_libraries(CPMExampleBoost PRIVATE Boost::asio Boost::container)

generates the following errors:

-- Found Boost 1.84.0 at /usr/local/lib/cmake/Boost-1.84.0
--   Requested configuration: QUIET REQUIRED COMPONENTS container;asio
-- BoostConfig: find_package(boost_headers 1.84.0 EXACT CONFIG REQUIRED QUIET HINTS /usr/local/lib/cmake)
-- Found boost_headers 1.84.0 at /usr/local/lib/cmake/boost_headers-1.84.0
-- BoostConfig: find_package(boost_container 1.84.0 EXACT CONFIG REQUIRED QUIET HINTS /usr/local/lib/cmake)
-- Found boost_container 1.84.0 at /usr/local/lib/cmake/boost_container-1.84.0
-- Boost toolset is clang17 (Clang 17.0.6)
-- Scanning /usr/local/lib/cmake/boost_container-1.84.0/libboost_container-variant*.cmake
--   Including /usr/local/lib/cmake/boost_container-1.84.0/libboost_container-variant-mt-shared.cmake
--   [x] libboost_container-mt.dylib
--   Including /usr/local/lib/cmake/boost_container-1.84.0/libboost_container-variant-mt-static.cmake
--   [ ] libboost_container-mt.a
--   Including /usr/local/lib/cmake/boost_container-1.84.0/libboost_container-variant-shared.cmake
--   [ ] libboost_container.dylib
--   Including /usr/local/lib/cmake/boost_container-1.84.0/libboost_container-variant-static.cmake
--   [ ] libboost_container.a
-- Adding boost_container dependencies: headers
-- BoostConfig: find_package(boost_asio 1.84.0 EXACT CONFIG REQUIRED QUIET HINTS /usr/local/lib/cmake)
CMake Error at /usr/local/lib/cmake/Boost-1.84.0/BoostConfig.cmake:141 (find_package):
  Could not find a package configuration file provided by "boost_asio"
  (requested version 1.84.0) with any of the following names:

    boost_asioConfig.cmake
    boost_asio-config.cmake

  Add the installation prefix of "boost_asio" to CMAKE_PREFIX_PATH or set
  "boost_asio_DIR" to a directory containing one of the above files.  If
  "boost_asio" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  /usr/local/lib/cmake/Boost-1.84.0/BoostConfig.cmake:262 (boost_find_component)
  /usr/local/lib/python3.11/site-packages/cmake/data/share/cmake-3.28/Modules/FindBoost.cmake:594 (find_package)
  cmake/CPM.cmake:249 (find_package)
  cmake/CPM.cmake:309 (cpm_find_package)
  CMakeLists.txt:16 (CPMFindPackage)

ClausKlein avatar Feb 07 '24 21:02 ClausKlein

I think this is an issue with the boost library as it is not defining the same targets for the source and installed configuration?

NO! it is an usage error. There exists only Boost::boost as header only lib and an alias Boost::headers.

see https://cmake.org/cmake/help/v3.28/module/FindBoost.html#findboost

ClausKlein avatar Feb 07 '24 21:02 ClausKlein