Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libnatpmp vcpkg port #709

Merged
merged 5 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ find_package(argtable2)
find_package(Argtable3 CONFIG)
find_package(PNG)
find_package(ZLIB)
find_package(miniupnpc)
include(cmake-scripts/Findminiupnpc.cmake)
find_package(natpmp)


Expand Down Expand Up @@ -139,18 +139,6 @@ elseif(ARGTABLE3_FOUND)
set(CORELIBS ${CORELIBS} ${ARGTABLE3_LIBRARY})
endif()

if(MINIUPNPC_FOUND)
set(CORELIBS ${CORELIBS} ${MINIUPNPC_LIBRARY})
set(COREINCS ${COREINCS} ${MINIUPNPC_INCLUDE_DIR})
add_compile_definitions(MINIUPNPC_FOUND)
endif()

if(LIBNATPMP_FOUND)
set(CORELIBS ${CORELIBS} ${LIBNATPMP_LIBRARY})
set(COREINCS ${COREINCS} ${LIBNATPMP_INCLUDE_DIR})
add_compile_definitions(NATPMP_FOUND)
endif()

# MingW build should add mingw32 lib
if(MINGW)
set(CORELIBS mingw32 ${CORELIBS})
Expand All @@ -172,14 +160,29 @@ include_directories(${COREINCS})
# Build core sources first as an object library
# this can then be reused in tests and main executable to speed things up
add_library(openomf_core OBJECT ${OPENOMF_SRC})
target_link_libraries(openomf_core PRIVATE ${XMP_LIBRARY})
set(CORELIBS openomf_core ${CORELIBS})

# Set icon for windows executable
if(WIN32)
SET(ICON_RESOURCE "resources/icons/openomf.rc")
endif()

# Link openomf_core to libraries directly, so their defines are present
target_link_libraries(openomf_core PUBLIC ${XMP_LIBRARY})
if(MINIUPNPC_FOUND)
target_link_libraries(openomf_core PUBLIC ${MINIUPNPC_LIBRARY})
target_include_directories(openomf_core PUBLIC ${MINIUPNPC_INCLUDE_DIR})
target_compile_definitions(openomf_core PUBLIC MINIUPNPC_FOUND)
endif()

if(LIBNATPMP_FOUND)
target_link_libraries(openomf_core PUBLIC ${LIBNATPMP_LIBRARY})
target_include_directories(openomf_core PUBLIC ${LIBNATPMP_INCLUDE_DIR})
target_compile_definitions(openomf_core PUBLIC NATPMP_FOUND)
endif()



# Build the game binary
add_executable(openomf src/main.c src/engine.c ${ICON_RESOURCE})
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT openomf)
Expand Down
13 changes: 13 additions & 0 deletions cmake-scripts/Findminiupnpc.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
if(VCPKG_TOOLCHAIN)
if(TARGET miniupnpc::miniupnpc)
return()
endif()
find_package(miniupnpc CONFIG)
if(TARGET miniupnpc::miniupnpc)
MESSAGE(STATUS "Found miniupnp in vcpkg")
set(MINIUPNPC_LIBRARY miniupnpc::miniupnpc)
SET(MINIUPNPC_FOUND TRUE)
set(MINIUPNPC_INCLUDE_DIR)
return()
endif()
endif(VCPKG_TOOLCHAIN)
Nopey marked this conversation as resolved.
Show resolved Hide resolved

SET(MINIUPNPC_SEARCH_PATHS
/usr/local/
Expand Down
13 changes: 13 additions & 0 deletions cmake-scripts/Findnatpmp.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
if(VCPKG_TOOLCHAIN)
if(TARGET libnatpmp::natpmp)
return()
endif()
find_package(libnatpmp CONFIG)
if(TARGET libnatpmp::natpmp)
MESSAGE(STATUS "Found libnatpmp in vcpkg")
set(LIBNATPMP_LIBRARY libnatpmp::natpmp)
SET(LIBNATPMP_FOUND TRUE)
set(LIBNATPMP_INCLUDE_DIR)
return()
endif()
endif(VCPKG_TOOLCHAIN)

SET(LIBNATPMP_SEARCH_PATHS
/usr/local/
Expand Down
50 changes: 50 additions & 0 deletions vcpkg-ports/libnatpmp/install-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5df1be2..bfc7492 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,7 +22,8 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)

# Library itself
add_library(natpmp ${NATPMP_SOURCES})
-target_include_directories(natpmp PUBLIC ${CMAKE_CURRENT_LIST_DIR})
+target_include_directories(natpmp PRIVATE ${CMAKE_CURRENT_LIST_DIR})
+target_include_directories(natpmp INTERFACE $<INSTALL_INTERFACE:include>)
target_compile_definitions(natpmp PRIVATE -DENABLE_STRNATPMPERR)

if (WIN32)
@@ -52,7 +53,14 @@ include(GNUInstallDirs)
configure_file(natpmp.pc.in natpmp.pc @ONLY)

# install
-install(TARGETS natpmp natpmpc
+install(TARGETS natpmp
+ EXPORT libnatpmp-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+# undone: natpmpc export target
+install(TARGETS natpmpc
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
@@ -63,3 +71,19 @@ install(FILES natpmp.h
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/natpmp.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

+include(CMakePackageConfigHelpers)
+configure_package_config_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/libnatpmp-config.cmake.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/libnatpmp-config.cmake"
+ INSTALL_DESTINATION "share/libnatpmp"
+)
+install(
+ FILES "${CMAKE_CURRENT_BINARY_DIR}/libnatpmp-config.cmake"
+ DESTINATION "share/libnatpmp"
+)
+
+install(
+ EXPORT libnatpmp-targets
+ DESTINATION share/libnatpmp
+ NAMESPACE libnatpmp::
+)
5 changes: 5 additions & 0 deletions vcpkg-ports/libnatpmp/libnatpmp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/libnatpmp-targets.cmake")

check_required_components(libnatpmp)
14 changes: 8 additions & 6 deletions vcpkg-ports/libnatpmp/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ vcpkg_from_github(
HEAD_REF master
PATCHES
"install-declspec-header.patch"

"install-targets.patch"
)

vcpkg_configure_cmake(
file(COPY "${CMAKE_CURRENT_LIST_DIR}/libnatpmp-config.cmake.in" DESTINATION "${SOURCE_PATH}")

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
PREFER_NINJA
)

vcpkg_install_cmake()
vcpkg_copy_pdbs()

vcpkg_fixup_pkgconfig()
vcpkg_cmake_config_fixup()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin" "${CURRENT_PACKAGES_DIR}/bin")
endif()

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

# Handle copyright
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
11 changes: 10 additions & 1 deletion vcpkg-ports/libnatpmp/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
"description": "NAT-PMP client library",
"homepage": "https://github.com/miniupnp/libnatpmp",
"license": "BSD-3-Clause",
"dependencies": [],
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"tool": {
"description": "Build natpmpc tool"
Expand Down
Loading