From acd25c80c860815d4ba66d18b48c933748d1d9b5 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Wed, 30 Oct 2024 23:46:46 -0700 Subject: [PATCH 1/5] Call Findminiupnpc.cmake directly to ensure find_package doesnt skip it --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 421738b57..b08209924 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) From b3d21dbe6dbe2ac90ccb321641e9af7109fd8f7b Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Thu, 31 Oct 2024 00:32:25 -0700 Subject: [PATCH 2/5] Link natpmp and miniupnpc directly to openomf_core --- CMakeLists.txt | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b08209924..cd865c9ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) @@ -172,7 +160,6 @@ 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 @@ -180,6 +167,22 @@ 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) From 5bff4abb55569c243acd46a6b106864dc66452de Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Thu, 31 Oct 2024 00:33:12 -0700 Subject: [PATCH 3/5] Add find_package(CONFIG) shim to natpmp and miniupnpc --- cmake-scripts/Findminiupnpc.cmake | 13 +++++++++++++ cmake-scripts/Findnatpmp.cmake | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/cmake-scripts/Findminiupnpc.cmake b/cmake-scripts/Findminiupnpc.cmake index 02a5a7158..3ac2cd8d9 100644 --- a/cmake-scripts/Findminiupnpc.cmake +++ b/cmake-scripts/Findminiupnpc.cmake @@ -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) SET(MINIUPNPC_SEARCH_PATHS /usr/local/ diff --git a/cmake-scripts/Findnatpmp.cmake b/cmake-scripts/Findnatpmp.cmake index f586c51e8..c1f82829e 100644 --- a/cmake-scripts/Findnatpmp.cmake +++ b/cmake-scripts/Findnatpmp.cmake @@ -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/ From 20e2ab05eade42563799b083b712de897f4fc73c Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Wed, 30 Oct 2024 22:31:05 -0700 Subject: [PATCH 4/5] Avoid deprecated vcpkg_configure_cmake command --- vcpkg-ports/libnatpmp/portfile.cmake | 6 ++---- vcpkg-ports/libnatpmp/vcpkg.json | 11 ++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/vcpkg-ports/libnatpmp/portfile.cmake b/vcpkg-ports/libnatpmp/portfile.cmake index 0f9d8387f..cbc3cce74 100644 --- a/vcpkg-ports/libnatpmp/portfile.cmake +++ b/vcpkg-ports/libnatpmp/portfile.cmake @@ -9,9 +9,8 @@ vcpkg_from_github( ) -vcpkg_configure_cmake( +vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" - PREFER_NINJA ) vcpkg_install_cmake() @@ -24,5 +23,4 @@ endif() file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") -# Handle copyright -file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/vcpkg-ports/libnatpmp/vcpkg.json b/vcpkg-ports/libnatpmp/vcpkg.json index 1e30bf3fd..08c3bdf2f 100644 --- a/vcpkg-ports/libnatpmp/vcpkg.json +++ b/vcpkg-ports/libnatpmp/vcpkg.json @@ -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" From af0cb04e88f9d10b2ecf9e7be7f9fa0bcdd800e5 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Wed, 30 Oct 2024 22:27:37 -0700 Subject: [PATCH 5/5] vcpkg-ports/libnatpmp: Export cmake target --- vcpkg-ports/libnatpmp/install-targets.patch | 50 +++++++++++++++++++ .../libnatpmp/libnatpmp-config.cmake.in | 5 ++ vcpkg-ports/libnatpmp/portfile.cmake | 10 ++-- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 vcpkg-ports/libnatpmp/install-targets.patch create mode 100644 vcpkg-ports/libnatpmp/libnatpmp-config.cmake.in diff --git a/vcpkg-ports/libnatpmp/install-targets.patch b/vcpkg-ports/libnatpmp/install-targets.patch new file mode 100644 index 000000000..30bada8b7 --- /dev/null +++ b/vcpkg-ports/libnatpmp/install-targets.patch @@ -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 $) + 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:: ++) diff --git a/vcpkg-ports/libnatpmp/libnatpmp-config.cmake.in b/vcpkg-ports/libnatpmp/libnatpmp-config.cmake.in new file mode 100644 index 000000000..350f53bad --- /dev/null +++ b/vcpkg-ports/libnatpmp/libnatpmp-config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/libnatpmp-targets.cmake") + +check_required_components(libnatpmp) diff --git a/vcpkg-ports/libnatpmp/portfile.cmake b/vcpkg-ports/libnatpmp/portfile.cmake index cbc3cce74..5ffe08f26 100644 --- a/vcpkg-ports/libnatpmp/portfile.cmake +++ b/vcpkg-ports/libnatpmp/portfile.cmake @@ -6,21 +6,25 @@ vcpkg_from_github( HEAD_REF master PATCHES "install-declspec-header.patch" - + "install-targets.patch" ) +file(COPY "${CMAKE_CURRENT_LIST_DIR}/libnatpmp-config.cmake.in" DESTINATION "${SOURCE_PATH}") + vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}" ) 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") - -vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")