diff --git a/CMakeLists.txt b/CMakeLists.txt index 421738b57..cd865c9ee 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) @@ -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) 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/ 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 0f9d8387f..5ffe08f26 100644 --- a/vcpkg-ports/libnatpmp/portfile.cmake +++ b/vcpkg-ports/libnatpmp/portfile.cmake @@ -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) 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"