2018-04-26 14:53:32 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
project (miniupnpc C)
|
2018-04-26 14:53:32 +00:00
|
|
|
|
2016-04-19 21:17:29 +00:00
|
|
|
set (MINIUPNPC_VERSION 2.0)
|
2018-04-06 10:48:24 +00:00
|
|
|
set (MINIUPNPC_API_VERSION 17)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
option (UPNPC_BUILD_STATIC "Build static library" TRUE)
|
|
|
|
option (UPNPC_BUILD_SHARED "Build shared library" TRUE)
|
2018-04-26 14:53:32 +00:00
|
|
|
option (UPNPC_BUILD_TESTS "Build test executables" TRUE)
|
|
|
|
option (UPNPC_BUILD_SAMPLE "Build sample executables" TRUE)
|
2011-09-27 20:25:35 +00:00
|
|
|
option (NO_GETADDRINFO "Define NO_GETADDRINFO" FALSE)
|
|
|
|
|
2018-04-26 14:53:32 +00:00
|
|
|
if (NOT UPNPC_BUILD_STATIC AND NOT UPNPC_BUILD_SHARED)
|
|
|
|
message (FATAL "Both shared and static libraries are disabled!")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Interface library for compile definitions, flags and option
|
|
|
|
add_library(miniupnpc-private INTERFACE)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
if (NO_GETADDRINFO)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_compile_definitions(miniupnpc-private INTERFACE NO_GETADDRINFO)
|
|
|
|
endif ()
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
if (NOT WIN32)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_compile_definitions(miniupnpc-private INTERFACE
|
|
|
|
MINIUPNPC_SET_SOCKET_TIMEOUT
|
|
|
|
_BSD_SOURCE _DEFAULT_SOURCE)
|
2016-06-26 08:51:07 +00:00
|
|
|
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
2016-06-26 12:19:18 +00:00
|
|
|
# add_definitions (-D_POSIX_C_SOURCE=200112L)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_compile_definitions(miniupnpc-private INTERFACE _XOPEN_SOURCE=600)
|
|
|
|
endif ()
|
|
|
|
else ()
|
|
|
|
target_compile_definitions(miniupnpc-private INTERFACE _WIN32_WINNT=0x0501) # XP or higher for getnameinfo and friends
|
|
|
|
endif ()
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
2018-04-26 14:53:32 +00:00
|
|
|
target_compile_definitions(miniupnpc-private INTERFACE _DARWIN_C_SOURCE)
|
2011-09-27 20:25:35 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Set compiler specific build flags
|
2018-04-26 14:53:32 +00:00
|
|
|
if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
target_compile_options(miniupnpc-private INTERFACE -Wall)
|
2011-09-27 20:25:35 +00:00
|
|
|
endif ()
|
|
|
|
|
2018-04-26 14:53:32 +00:00
|
|
|
# Suppress noise warnings
|
|
|
|
if (MSVC)
|
|
|
|
target_compile_definitions(miniupnpc-private INTERFACE _CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif()
|
|
|
|
|
2016-08-25 22:12:19 +00:00
|
|
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/miniupnpcstrings.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/miniupnpcstrings.h)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_include_directories(miniupnpc-private INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
set (MINIUPNPC_SOURCES
|
|
|
|
igd_desc_parse.c
|
|
|
|
miniupnpc.c
|
|
|
|
minixml.c
|
|
|
|
minisoap.c
|
2015-09-18 23:12:19 +00:00
|
|
|
minissdpc.c
|
2011-09-27 20:25:35 +00:00
|
|
|
miniwget.c
|
|
|
|
upnpcommands.c
|
2015-09-18 23:12:19 +00:00
|
|
|
upnpdev.c
|
2011-09-27 20:25:35 +00:00
|
|
|
upnpreplyparse.c
|
|
|
|
upnperrors.c
|
|
|
|
connecthostport.c
|
|
|
|
portlistingparse.c
|
2012-06-20 21:13:03 +00:00
|
|
|
receivedata.c
|
2018-04-26 14:53:32 +00:00
|
|
|
connecthostport.h
|
|
|
|
igd_desc_parse.h
|
|
|
|
minisoap.h
|
|
|
|
minissdpc.h
|
|
|
|
miniupnpc.h
|
|
|
|
miniupnpctypes.h
|
|
|
|
miniwget.h
|
|
|
|
minixml.h
|
|
|
|
portlistingparse.h
|
|
|
|
receivedata.h
|
|
|
|
upnpcommands.h
|
|
|
|
upnpdev.h
|
|
|
|
upnperrors.h
|
|
|
|
upnpreplyparse.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/miniupnpcstrings.h
|
2011-09-27 20:25:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
|
|
|
|
set (MINIUPNPC_SOURCES ${MINIUPNPC_SOURCES} minissdpc.c)
|
2018-04-26 14:53:32 +00:00
|
|
|
endif ()
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
if (WIN32)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries(miniupnpc-private INTERFACE ws2_32 iphlpapi)
|
2011-09-27 20:25:35 +00:00
|
|
|
#elseif (CMAKE_SYSTEM_NAME STREQUAL "Solaris")
|
|
|
|
# find_library (SOCKET_LIBRARY NAMES socket)
|
|
|
|
# find_library (NSL_LIBRARY NAMES nsl)
|
|
|
|
# find_library (RESOLV_LIBRARY NAMES resolv)
|
|
|
|
# set (LDLIBS ${SOCKET_LIBRARY} ${NSL_LIBRARY} ${RESOLV_LIBRARY} ${LDLIBS})
|
2018-04-26 14:53:32 +00:00
|
|
|
endif ()
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (UPNPC_BUILD_STATIC)
|
2016-06-26 12:19:38 +00:00
|
|
|
add_library (libminiupnpc-static STATIC ${MINIUPNPC_SOURCES})
|
|
|
|
set_target_properties (libminiupnpc-static PROPERTIES OUTPUT_NAME "miniupnpc")
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries (libminiupnpc-static PRIVATE miniupnpc-private)
|
|
|
|
target_include_directories(libminiupnpc-static INTERFACE ../${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
target_compile_definitions(libminiupnpc-static PUBLIC MINIUPNP_STATICLIB)
|
|
|
|
|
|
|
|
install (TARGETS libminiupnpc-static
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib${LIB_SUFFIX}
|
|
|
|
ARCHIVE DESTINATION lib${LIB_SUFFIX})
|
|
|
|
|
|
|
|
if (UPNPC_BUILD_SAMPLE)
|
|
|
|
add_executable (upnpc-static upnpc.c)
|
|
|
|
target_link_libraries (upnpc-static PRIVATE libminiupnpc-static)
|
|
|
|
target_include_directories(upnpc-static PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
if (UPNPC_BUILD_SHARED)
|
2016-06-26 12:19:38 +00:00
|
|
|
add_library (libminiupnpc-shared SHARED ${MINIUPNPC_SOURCES})
|
|
|
|
set_target_properties (libminiupnpc-shared PROPERTIES OUTPUT_NAME "miniupnpc")
|
|
|
|
set_target_properties (libminiupnpc-shared PROPERTIES VERSION ${MINIUPNPC_VERSION})
|
|
|
|
set_target_properties (libminiupnpc-shared PROPERTIES SOVERSION ${MINIUPNPC_API_VERSION})
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries (libminiupnpc-shared PRIVATE miniupnpc-private)
|
|
|
|
target_compile_definitions(libminiupnpc-shared PRIVATE MINIUPNP_EXPORTS)
|
|
|
|
|
|
|
|
target_include_directories(libminiupnpc-static INTERFACE ../${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
if (WIN32)
|
|
|
|
target_link_libraries(libminiupnpc-shared INTERFACE ws2_32 iphlpapi)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
install (TARGETS libminiupnpc-shared
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib${LIB_SUFFIX}
|
|
|
|
ARCHIVE DESTINATION lib${LIB_SUFFIX})
|
|
|
|
|
|
|
|
if (UPNPC_BUILD_SAMPLE)
|
|
|
|
add_executable (upnpc-shared upnpc.c)
|
|
|
|
target_link_libraries (upnpc-shared PRIVATE libminiupnpc-shared)
|
|
|
|
target_include_directories(upnpc-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
if (UPNPC_BUILD_TESTS)
|
2018-04-26 14:53:32 +00:00
|
|
|
add_library(miniupnpc-tests INTERFACE)
|
|
|
|
target_link_libraries(miniupnpc-tests INTERFACE miniupnpc-private)
|
|
|
|
target_compile_definitions(miniupnpc-tests INTERFACE MINIUPNP_STATICLIB)
|
|
|
|
|
2011-09-27 20:25:35 +00:00
|
|
|
add_executable (testminixml testminixml.c minixml.c igd_desc_parse.c)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries (testminixml PRIVATE miniupnpc-tests)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
add_executable (minixmlvalid minixmlvalid.c minixml.c)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries (minixmlvalid PRIVATE miniupnpc-tests)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
add_executable (testupnpreplyparse testupnpreplyparse.c
|
|
|
|
minixml.c upnpreplyparse.c)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries (testupnpreplyparse PRIVATE miniupnpc-tests)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
add_executable (testigddescparse testigddescparse.c
|
|
|
|
igd_desc_parse.c minixml.c miniupnpc.c miniwget.c minissdpc.c
|
|
|
|
upnpcommands.c upnpreplyparse.c minisoap.c connecthostport.c
|
2012-06-20 21:13:03 +00:00
|
|
|
portlistingparse.c receivedata.c
|
2011-09-27 20:25:35 +00:00
|
|
|
)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries (testigddescparse PRIVATE miniupnpc-tests)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
add_executable (testminiwget testminiwget.c
|
|
|
|
miniwget.c miniupnpc.c minisoap.c upnpcommands.c minissdpc.c
|
|
|
|
upnpreplyparse.c minixml.c igd_desc_parse.c connecthostport.c
|
2012-06-20 21:13:03 +00:00
|
|
|
portlistingparse.c receivedata.c
|
2011-09-27 20:25:35 +00:00
|
|
|
)
|
2018-04-26 14:53:32 +00:00
|
|
|
target_link_libraries (testminiwget PRIVATE miniupnpc-tests)
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
# set (UPNPC_INSTALL_TARGETS ${UPNPC_INSTALL_TARGETS} testminixml minixmlvalid testupnpreplyparse testigddescparse testminiwget)
|
2018-04-26 14:53:32 +00:00
|
|
|
endif ()
|
2011-09-27 20:25:35 +00:00
|
|
|
|
|
|
|
install (FILES
|
|
|
|
miniupnpc.h
|
|
|
|
miniwget.h
|
|
|
|
upnpcommands.h
|
|
|
|
igd_desc_parse.h
|
|
|
|
upnpreplyparse.h
|
|
|
|
upnperrors.h
|
2015-09-18 01:20:37 +00:00
|
|
|
upnpdev.h
|
2014-04-17 10:53:11 +00:00
|
|
|
miniupnpctypes.h
|
|
|
|
portlistingparse.h
|
2015-09-16 15:59:12 +00:00
|
|
|
miniupnpc_declspec.h
|
2011-09-27 20:25:35 +00:00
|
|
|
DESTINATION include/miniupnpc
|
|
|
|
)
|
|
|
|
|
|
|
|
# vim: ts=2:sw=2
|