CMake未能链接消费者项目

时间:2018-06-16 08:04:57

标签: c++ cmake

我正在构建一个动态库供其他项目使用。为了更容易,我在构建过程中创建了LibraryConfig.cmake文件。我已成功设法让消费者项目包含项目的标题,但他们无法链接到库。为了让消费者项目正确链接到我的库,我缺少什么?

具体来说错误如下: 忍者:错误:'My-Dynamic-Lib-NOTFOUND','Consumer Project.so'需要,缺少并没有已知的规则来实现它

# Contents of My-Dynamic-LibConfig.cmake.in
if (NOT @PROJECT_NAME@_FOUND)
    set(@PROJECT_NAME@_LIBRARY_DIR "@LIBRARY_INSTALL_LIB_DIR@")
    set(PACKAGE_VERSION "@My-Dynamic-Lib_VERSION@")

    if (NOT EXISTS "@CMAKE_INSTALL_PREFIX@/include/my-dynamic/MyLib.hpp")
        MESSAGE(AUTHOR_WARNING "Failed to find the library header directory.")
    endif (NOT EXISTS "@CMAKE_INSTALL_PREFIX@/include/my-dynamic/MyLib.hpp")

    if (NOT WIN32)
        if (EXISTS "${@PROJECT_NAME@_LIBRARY_DIR}/libmy-dynamic.@DYN_LIB_EXT@")
            set(@PROJECT_NAME@_LIBRARIES "${@PROJECT_NAME@_LIBRARY_DIR}/libmy-dynamic.@DYN_LIB_EXT@")
        elseif (EXISTS "${@PROJECT_NAME@_LIBRARY_DIR}/libmy-dynamicd.@DYN_LIB_EXT@")
            set(@PROJECT_NAME@_LIBRARIES "${@PROJECT_NAME@_LIBRARY_DIR}/libmy-dynamicd.@DYN_LIB_EXT@")
        endif (EXISTS "${@PROJECT_NAME@_LIBRARY_DIR}/libmy-dynamic.@DYN_LIB_EXT@")
    else ()
        if (EXISTS "${@PROJECT_NAME@_LIBRARY_DIR}/my-dynamic.@STA_LIB_EXT@")
            set(@PROJECT_NAME@_LIBRARIES "${@PROJECT_NAME@_LIBRARY_DIR}/my-dynamic.@STA_LIB_EXT@")
        elseif (EXISTS "${@PROJECT_NAME@_LIBRARY_DIR}/my-dynamicd.@STA_LIB_EXT@")
            set(@PROJECT_NAME@_LIBRARIES "${@PROJECT_NAME@_LIBRARY_DIR}/my-dynamicd.@STA_LIB_EXT@")
        endif (EXISTS "${@PROJECT_NAME@_LIBRARY_DIR}/my-dynamic.@STA_LIB_EXT@")
    endif (NOT WIN32)

    add_library(@PROJECT_NAME@ SHARED IMPORTED ${@PROJECT_NAME@_LIBRARIES})
    set_target_properties(@PROJECT_NAME@ PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/include"
        INTERFACE_LINK_LIBRARIES "${@PROJECT_NAME@_LIBRARIES}"
    )

    if (@PROJECT_NAME@_LIBRARIES)
        set(@PROJECT_NAME@_FOUND TRUE)
    else ()
        MESSAGE(AUTHOR_WARNING "Failed to find the library.")
        set(@PROJECT_NAME@_FOUND FALSE)
    endif (@PROJECT_NAME@_LIBRARIES)

    unset(@PROJECT_NAME@_LIBRARY_DIR)
endif (NOT @PROJECT_NAME@_FOUND)

0 个答案:

没有答案