libnatpmp: Switch to CMake

Allows simplifying the Makefile. CMake patch is from upstream.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-06-15 14:20:09 -07:00
parent 71c42f1c8b
commit a5b63c14c5
3 changed files with 63 additions and 30 deletions

View File

@ -9,22 +9,25 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=libnatpmp
PKG_VERSION:=20150609
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://miniupnp.tuxfamily.org/files
PKG_HASH:=e1aa9c4c4219bc06943d6b2130f664daee213fb262fcb94dd355815b8f4536b0
PKG_MAINTAINER:=Hauke Mehrtens <hauke@hauke-m.de>
PKG_LICENSE:=BSD-3c
PKG_MAINTAINER:=Rosen Penev <rosenp@gmail.com>
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
CMAKE_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk
define Package/libnatpmp/Default
TITLE:=NAT Port Mapping Protocol (NAT-PMP)
URL:=http://miniupnp.free.fr/libnatpmp.html
URL:=https://miniupnp.tuxfamily.org/libnatpmp.html
endef
define Package/libnatpmp/Default/description
@ -39,6 +42,7 @@ define Package/libnatpmp
SECTION:=libs
CATEGORY:=Libraries
TITLE+= library
ABI_VERSION:=1
endef
define Package/libnatpmp/description
@ -60,22 +64,9 @@ define Package/natpmpc/description
This package contains the natpmp client.
endef
MAKE_FLAGS += \
COPTS="$(TARGET_CFLAGS)" \
PREFIX="$(PKG_INSTALL_DIR)" \
OS="Linux"
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
$(CP) $(PKG_INSTALL_DIR)/usr/include/declspec.h $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/natpmp.h $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libnatpmp*.{so*,a} $(1)/usr/lib/
endef
define Package/libnatpmp/install
$(INSTALL_DIR) $(1)/usr/lib
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/libnatpmp.so.* $(1)/usr/lib/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libnatpmp.so.* $(1)/usr/lib/
endef
define Package/natpmpc/install

View File

@ -1,11 +0,0 @@
--- a/Makefile
+++ b/Makefile
@@ -56,7 +56,7 @@ else
endif
endif
-HEADERS = natpmp.h
+HEADERS = natpmp.h declspec.h
EXECUTABLES = testgetgateway natpmpc-shared natpmpc-static

View File

@ -0,0 +1,53 @@
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,50 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+if(POLICY CMP0048)
+ cmake_policy(SET CMP0048 NEW)
+endif()
+
+project(natpmp C)
+
+set (NATPMP_VERSION 20150609)
+set (NATPMP_API_VERSION 1)
+
+set (NATPMP_SOURCES
+ natpmp.c
+ getgateway.c
+)
+
+if (WIN32)
+ set (NATPMP_SOURCES ${NATPMP_SOURCES} wingettimeofday.c)
+endif (WIN32)
+
+# Library itself
+add_library(natpmp SHARED ${NATPMP_SOURCES})
+set_target_properties (natpmp PROPERTIES OUTPUT_NAME "natpmp")
+set_target_properties (natpmp PROPERTIES VERSION ${NATPMP_VERSION})
+set_target_properties (natpmp PROPERTIES SOVERSION ${NATPMP_API_VERSION})
+target_compile_definitions(natpmp PRIVATE -DENABLE_STRNATPMPERR)
+target_include_directories(natpmp PUBLIC ${CMAKE_CURRENT_LIST_DIR})
+
+if (WIN32)
+ target_link_libraries(natpmp PUBLIC ws2_32 Iphlpapi)
+ target_compile_definitions(natpmp PUBLIC -DNATPMP_STATICLIB)
+endif (WIN32)
+
+install(TARGETS natpmp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
+ ARCHIVE DESTINATION lib${LIB_SUFFIX})
+
+# Executables
+add_executable(natpmpc natpmpc.c)
+target_link_libraries(natpmpc natpmp)
+
+install(FILES natpmpc DESTINATION bin)
+
+add_executable(testgetgateway
+ testgetgateway.c
+ getgateway.c)
+target_link_libraries(testgetgateway natpmp)
+
+install(FILES natpmp.h DESTINATION include)