简体   繁体   中英

vcpkg add new library but it cannot be found

I tries to add a new library at vcpkg, so I have wrote a CONTROL file and portfile.cmake file. When I run the installation, it's successful:

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

But when I want use this library into another project, I have this error:

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

Where is my error?

The library can be found here: https://github.com/GamedevFramework/gf

The project here: https://github.com/Hatunruna/ggj2020

This is the CONTROL file for gf:

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

And the 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)

Finally, I found the problem. vcpkg needs to have a separated folder for each targets.

So I have change the 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM