4

CONAN_PKG::spdlog is not found when using CMake to generate build configurations.

The conan package I use is spdlog/1.3.1@bincrafters/stable. I have a CMake executable target which references a conan package spdlog. I am getting this error message:

[build] CMake Error at src/apps/ResultObserver/CMakeLists.txt:10 (ADD_EXECUTABLE):
[build]   Target "ResultObserver" links to target "CONAN_PKG::spdlog" but the target
[build]   was not found.  Perhaps a find_package() call is missing for an IMPORTED
[build]   target, or an ALIAS target is missing?

I have these lines in my CMakeLists.txt.

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

ADD_EXECUTABLE(ResultObserver src/ResultObserver.cpp)

TARGET_LINK_LIBRARIES(ResultObserver CONAN_PKG::spdlog)

Also, after installing the conan package, the conanbuildinfo.cmake file is generated in the build directory.

I checked inside the file. It contains these lines.

    add_library(CONAN_PKG::spdlog INTERFACE IMPORTED)

    # Property INTERFACE_LINK_FLAGS do not work, necessary to add to INTERFACE_LINK_LIBRARIES
    set_property(TARGET CONAN_PKG::spdlog PROPERTY INTERFACE_LINK_LIBRARIES .........

Anyone know the reason?

Kevin
  • 16,549
  • 8
  • 60
  • 74
user3691191
  • 547
  • 1
  • 10
  • 20

1 Answers1

11

You are looking for the TARGETS approach. You need to pass TARGETS to conan_basic_setup() to generate CONAN_PKG::. Otherwise, only ${CONAN_LIBS} will be available.

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

ADD_EXECUTABLE(ResultObserver src/ResultObserver.cpp)
TARGET_LINK_LIBRARIES(ResultObserver CONAN_PKG::spdlog)

More info about the CMake target generator is here: https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#targets-approach

Kevin
  • 16,549
  • 8
  • 60
  • 74
uilianries
  • 3,363
  • 15
  • 28