【问题标题】:Poco::Foundation Target Not found with conanPoco::Foundation Target Not found with conan
【发布时间】:2021-11-12 20:56:09
【问题描述】:

我想建立一个小图书馆并将其与 Poco 基金会图书馆链接。 我使用 Conan 来安装 Poco 和 cmake_find_package 生成器。

这是我的conanfile.py:

from conans import ConanFile

class ExamplePluginConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    requires = "poco/1.11.0"
    generators = "cmake_find_package"
    default_options = {
        "poco:shared": True, 
        "poco:enable_active_record": False,
        "poco:enable_crypto": False,
        "poco:enable_data": False,
        "poco:enable_data_mysql": False,
        "poco:enable_data_postgresql": False,
        "poco:enable_data_sqlite": False,
        "poco:enable_jwt": False,
        "poco:enable_mongodb": False,
        "poco:enable_net": False,
        "poco:enable_netssl": False,
        "poco:enable_redis": False,
        "poco:enable_zip": False,
        }

    def imports(self):
        if self.settings.build_type == "Debug":
            self.copy("*.dll", dst="bin/Debug", src="bin", root_package="poco")
        elif self.settings.build_type == "Release":
            if self.settings.os == "Windows":
                self.copy("*.dll", dst="bin/Release", src="bin", root_package="poco")
            elif self.settings.os == "Linux":
                self.copy("*.so*", dst="bin", src="lib", root_package="poco")

这是我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
    message(FATAL_ERROR "Do not build in-source. Please remove CMakeCache.txt and the CMakeFiles/ directory. Then build out-of-source")
endif()

project("ExamplePlugin" VERSION 1.0.0 LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(GLOBAL PROPERTY USE_FOLDERS ON)

option(BUILD_SHARED_LIBS "Build shared (dynamic) libraries." ON)


add_library(ExamplePlugin)
add_library("jd::ExamplePlugin" ALIAS ExamplePlugin)

target_sources(ExamplePlugin
                    PUBLIC
                    include/ExamplePlugin/ExamplePlugin.hpp
                    PRIVATE
                    src/ExamplePlugin.cpp
)

find_package(Poco)

if(NOT TARGET Poco::Poco)
    message(FATAL_ERROR "Target  Not Found ")
endif()

target_link_libraries(ExamplePlugin PUBLIC jd::Core Poco::Foundation)

target_include_directories(ExamplePlugin PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
                            "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>"
                            PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
)               

if(NOT BUILD_SHARED_LIBS)
    string(TOUPPER ExamplePlugin PROJECT_NAME_UPPER)
    set_target_properties(ExamplePlugin PROPERTIES COMPILE_FLAGS -D${PROJECT_NAME_UPPER}_STATIC)
endif()


set_target_properties(ExamplePlugin PROPERTIES SOVERSION 1 VERSION 1.0.0)
set_target_properties(ExamplePlugin PROPERTIES 
                    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
                    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
                    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
set_target_properties(ExamplePlugin PROPERTIES DEBUG_POSTFIX "d")

include(GenerateExportHeader)
string(TOUPPER ExamplePlugin PROJECT_NAME_UPPER)
generate_export_header(ExamplePlugin
    EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/ExamplePlugin/export.hpp
    EXPORT_MACRO_NAME ${PROJECT_NAME_UPPER}_EXPORT
    STATIC_DEFINE ${PROJECT_NAME_UPPER}_STATIC
)

这总是给我找不到目标Poco::Foundation 的错误:

ExamplePlugin/CMakeLists.txt:20 (add_library) 处的 CMake 错误: 目标“ExamplePlugin”链接到目标“Poco::Foundation”,但目标 没有找到。 IMPORTED 可能缺少 find_package() 调用 目标,还是缺少 ALIAS 目标?

仅当我指定 Poco::Poco 目标时才有效。但这会将我的图书馆与所有 Poco 图书馆联系起来(如 Net、Utils、JSON 等)

有没有办法只链接到Poco::Foundation 部分?

【问题讨论】:

    标签: c++ cmake poco-libraries conan


    【解决方案1】:

    在我发布问题时,这是不可能的。但是柯南中心的 Poco 包有更新,现在可以只链接到特定目标,如 poco::foundation

    【讨论】:

    猜你喜欢
    • 2019-05-12
    • 2022-01-08
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 2016-09-10
    • 2015-01-21
    • 1970-01-01
    相关资源
    最近更新 更多