vcpkg 添加新库但找不到

vcpkg add new library but it cannot be found

我试图在 vcpkg 添加一个新库,所以我写了一个 CONTROL 文件和 portfile.cmake 文件。当我运行安装成功时:

./vcpkg.exe install gf:x64-windows
Computing installation plan...
The following packages will be built and installed:
    gf[core]:x64-windows
Starting package 1/1: gf:x64-windows
Building package gf[core]:x64-windows...
-- SOURCE_PATH: C:/path/to/vcpkg/buildtrees/gf/src/v0.15.0
-- Dynamic build
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
-- Installing: C:/path/to/vcpkg/packages/gf_x64-windows/share/gf/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package gf[core]:x64-windows... done
Installing package gf[core]:x64-windows...
Installing package gf[core]:x64-windows... done
Elapsed time for package gf:x64-windows: 52.05 s

Total elapsed time: 52.1 s

The package gf:x64-windows provides CMake targets:

    find_package(gf CONFIG REQUIRED)
    target_link_libraries(main PRIVATE gf::gf0)

    find_package(gfcore CONFIG REQUIRED)
    target_link_libraries(main PRIVATE gf::gfcore0)

    find_package(gfnet CONFIG REQUIRED)
    target_link_libraries(main PRIVATE gf::gfnet0)

但是当我想在另一个项目中使用这个库时,出现了这个错误:

cmake -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake ..
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- CMAKE_MODULE_PATH: C:/path/to/project/pax_et_mors/modules
CMake Error at C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake:405 (_find_package):
  By not providing "Findgf.cmake" in CMAKE_MODULE_PATH this project has asked
  CMake to find a package configuration file provided by "gf", but CMake did
  not find one.

  Could not find a package configuration file provided by "gf" with any of
  the following names:

    gfConfig.cmake
    gf-config.cmake

  Add the installation prefix of "gf" to CMAKE_PREFIX_PATH or set "gf_DIR" to
  a directory containing one of the above files.  If "gf" provides a separate
  development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
  CMakeLists.txt:12 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/path/to/project/pax_et_mors/build/CMakeFiles/CMakeOutput.log".

我的错误在哪里?

图书馆可以在这里找到:https://github.com/GamedevFramework/gf

这里的项目:https://github.com/Hatunruna/ggj2020

这是 gf 的控制文件:

Source: gf
Version: 0.15
Description: Gamedev Framework (gf) is a framework to build 2D games in C++14. 

和 portfile.cmake:

find_program(GIT git)

set(GIT_URL "https://github.com/GamedevFramework/gf")
set(GIT_TAG "loading_thread")

set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/${GIT_TAG})
message(STATUS "SOURCE_PATH: ${SOURCE_PATH}")

if(NOT EXISTS "${SOURCE_PATH}/.git")
    message(STATUS "Cloning and fetching submodules")
    vcpkg_execute_required_process(
      COMMAND ${GIT} clone -b ${GIT_TAG} --recurse-submodules ${GIT_URL} ${SOURCE_PATH}
      WORKING_DIRECTORY ${SOURCE_PATH}
      LOGNAME clone
    )

    message(STATUS "Checkout tag ${GIT_TAG}")
    vcpkg_execute_required_process(
      COMMAND ${GIT} checkout ${GIT_TAG}
      WORKING_DIRECTORY ${SOURCE_PATH}
      LOGNAME checkout
    )
endif()

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)
if(${BUILD_SHARED})
    message(STATUS "Dynamic build")
    set(BUILD_SHARED_OPTION "ON")
else()
    message(STATUS "Static build")
    set(BUILD_SHARED_OPTION "OFF")
endif()

vcpkg_configure_cmake(
    SOURCE_PATH ${SOURCE_PATH}
    PREFER_NINJA
    OPTIONS -DGF_BUILD_GAMES=OFF -DGF_BUILD_TOOLS=OFF -DGF_BUILD_EXAMPLES=OFF -DGF_BUILD_TESTS=OFF -DGF_BUILD_DOCUMENTATION=OFF -DGF_SINGLE_COMPILTATION_UNIT=ON -DGF_SHARED=${BUILD_SHARED_OPTION}
    OPTIONS_RELEASE -DGF_DEBUG=OFF
    OPTIONS_DEBUG -DGF_DEBUG=ON 
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake)
vcpkg_copy_pdbs()

file(REMOVE_RECURSE 
    "${CURRENT_PACKAGES_DIR}/debug/share"
    "${CURRENT_PACKAGES_DIR}/debug/include"
    "${CURRENT_PACKAGES_DIR}/share/doc"
)

file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/gf RENAME copyright)

终于找到问题了。 vcpkg 需要为每个目标有一个单独的文件夹。

所以我改变了 portfile.cmake:

find_program(GIT git)

# Same as previous...

vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake TARGET_PATH "share/gf_tmp")
vcpkg_copy_pdbs()

file(RENAME "${CURRENT_PACKAGES_DIR}/share/gf_tmp/gfcore" "${CURRENT_PACKAGES_DIR}/share/gfcore")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/gf_tmp/gf" "${CURRENT_PACKAGES_DIR}/share/gf")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/gf_tmp/gfnet" "${CURRENT_PACKAGES_DIR}/share/gfnet")

file(REMOVE_RECURSE 
    "${CURRENT_PACKAGES_DIR}/debug/share"
    "${CURRENT_PACKAGES_DIR}/debug/include"
    "${CURRENT_PACKAGES_DIR}/share/doc"
    "${CURRENT_PACKAGES_DIR}/share/gf_tmp"
)

file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/gf RENAME copyright)