使用cmake生成构建目标时找不到CONAN_PKG :: <PKG-NAME>

时间:2019-11-07 12:56:47

标签: cmake conan

使用CMake生成构建配置时找不到

CONAN_PKG::spdlog

我使用的柯南包是 spdlog/1.3.1@bincrafters/stable 。 我有一个CMake可执行目标,该目标引用一个柯南软件包spdlog。我收到此错误消息:

[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?

我的CMakeLists.txt中有这些行。

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

ADD_EXECUTABLE(ResultObserver src/ResultObserver.cpp)

TARGET_LINK_LIBRARIES(ResultObserver CONAN_PKG::spdlog)

此外,在安装柯南软件包之后,会在构建目录中生成 conanbuildinfo.cmake 文件。

我检查了文件内部。它包含这些行。

    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 .........

有人知道原因吗?

1 个答案:

答案 0 :(得分:1)

您正在寻找TARGETS方法。您需要将TARGETS传递给conan_basic_setup()才能生成CONAN_PKG::。否则,只有${CONAN_LIBS}可用。

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

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

有关CMake目标生成器的更多信息在这里: https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#targets-approach