1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-22 15:54:57 +00:00
transmission/cmake/FindMINIUPNPC.cmake
Mike Gelfand bc380511db
Modernize CMake code (ongoing refactoring) (#4507)
* Reformat CMake code

* Bump minimum CMake version to 3.12

* Add target sources separately via `target_source()`

* Make `tr_win32_app_info()` add target sources on its own

* Don't use `include_directories()`

* Don't use `add_definitions()`

* Limit use of `add_compile_options()`

* Move VDKQueue target declaration to a subdirectory

* Add `tr_disable_source_files_compile()` helper

* Add `tr_target_glib_resources()` helper

* Add `tr_gettext_msgfmt()` helper

* Enable AUTOUIC for Qt client

* Enable AUTORCC for Qt client

* Remove AUTO{MOC,RCC,UIC} source group overrides

* Add `tr_target_idl_files()` helper

* Move source group setup to `tr_qt_add_translation()`

* Add `tr_target_xib_files()` helper

* Prefer `target_sources()` to intermediate variables

* Use explicit visibility versions of `target_*()` commands

* Prefer genexes to conditions in `target_*()` commands

* Add `tr_allow_compile_if()` helper

* Leave only top-level `project()`, remove the rest

* Minor fixups

* Fixup Mac QL plugin install

* Fixup IDE target folders and source groups
2023-01-01 19:49:48 +00:00

135 lines
5.3 KiB
CMake

if(MINIUPNPC_PREFER_STATIC_LIB)
set(MINIUPNPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
endif()
if(UNIX)
find_package(PkgConfig QUIET)
pkg_check_modules(_MINIUPNPC QUIET libminiupnpc)
endif()
find_path(MINIUPNPC_INCLUDE_DIR
NAMES miniupnpc/miniupnpc.h
HINTS ${_MINIUPNPC_INCLUDEDIR})
find_library(MINIUPNPC_LIBRARY
NAMES
miniupnpc
libminiupnpc
HINTS ${_MINIUPNPC_LIBDIR})
if(MINIUPNPC_INCLUDE_DIR)
if(_MINIUPNPC_VERSION)
set(MINIUPNPC_VERSION ${_MINIUPNPC_VERSION})
else()
file(STRINGS "${MINIUPNPC_INCLUDE_DIR}/miniupnpc/miniupnpc.h" MINIUPNPC_VERSION_STR
REGEX "^#define[\t ]+MINIUPNPC_VERSION[\t ]+\"[^\"]+\"")
if(MINIUPNPC_VERSION_STR MATCHES "\"([^\"]+)\"")
set(MINIUPNPC_VERSION "${CMAKE_MATCH_1}")
endif()
# Let's hope it's 1.7 or higher, since it provides
# MINIUPNPC_API_VERSION and we won't have to figure
# it out on our own
file(STRINGS "${MINIUPNPC_INCLUDE_DIR}/miniupnpc/miniupnpc.h" MINIUPNPC_API_VERSION_STR
REGEX "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+[0-9]+")
if(MINIUPNPC_API_VERSION_STR MATCHES "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+([0-9]+)")
set(MINIUPNPC_API_VERSION "${CMAKE_MATCH_1}")
endif()
endif()
if(MINIUPNPC_LIBRARY)
# Or maybe it's miniupnp 1.6
if(NOT DEFINED MINIUPNPC_API_VERSION)
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckMiniUPnPC_1.6.c
"#include <stdlib.h>
#include <errno.h>
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/upnpcommands.h>
int main()
{
struct UPNPDev * devlist;
struct UPNPUrls urls;
struct IGDdatas data;
char lanaddr[16];
char portStr[8];
char intPort[8];
char intClient[16];
upnpDiscover( 2000, NULL, NULL, 0, 0, &errno );
UPNP_GetValidIGD( devlist, &urls, &data, lanaddr, sizeof( lanaddr ) );
UPNP_GetSpecificPortMappingEntry( urls.controlURL, data.first.servicetype,
portStr, \"TCP\", intClient, intPort, NULL, NULL, NULL );
return 0;
}")
try_compile(_MINIUPNPC_HAVE_VERSION_1_6
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckMiniUPnPC_1.6.c
COMPILE_DEFINITIONS -DINCLUDE_DIRECTORIES=${MINIUPNPC_INCLUDE_DIR}
LINK_LIBRARIES ${MINIUPNPC_LIBRARY}
OUTPUT_VARIABLE OUTPUT)
if(_MINIUPNPC_HAVE_VERSION_1_6)
if(NOT DEFINED MINIUPNPC_VERSION)
set(MINIUPNPC_VERSION 1.6)
endif()
set(MINIUPNPC_API_VERSION 8)
endif()
endif()
# Or maybe it's miniupnp 1.5
if(NOT DEFINED MINIUPNPC_API_VERSION)
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckMiniUPnPC_1.5.c
"#include <stdlib.h>
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/upnpcommands.h>
int main()
{
struct UPNPDev * devlist;
struct UPNPUrls urls;
struct IGDdatas data;
char lanaddr[16];
char portStr[8];
char intPort[8];
char intClient[16];
upnpDiscover( 2000, NULL, NULL, 0 );
UPNP_GetValidIGD( devlist, &urls, &data, lanaddr, sizeof( lanaddr ) );
UPNP_GetSpecificPortMappingEntry( urls.controlURL, data.first.servicetype,
portStr, \"TCP\", intClient, intPort );
return 0;
}")
try_compile(_MINIUPNPC_HAVE_VERSION_1_5
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckMiniUPnPC_1.5.c
COMPILE_DEFINITIONS -DINCLUDE_DIRECTORIES=${MlINIUPNPC_INCLUDE_DIR}
LINK_LIBRARIES ${MINIUPNPC_LIBRARY}
OUTPUT_VARIABLE OUTPUT)
if(_MINIUPNPC_HAVE_VERSION_1_5)
if(NOT DEFINED MINIUPNPC_VERSION)
set(MINIUPNPC_VERSION 1.5)
endif()
set(MINIUPNPC_API_VERSION 5)
endif()
endif()
endif()
endif()
set(MINIUPNPC_INCLUDE_DIRS ${MINIUPNPC_INCLUDE_DIR})
set(MINIUPNPC_LIBRARIES ${MINIUPNPC_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MINIUPNPC
REQUIRED_VARS
MINIUPNPC_LIBRARY
MINIUPNPC_INCLUDE_DIR
MINIUPNPC_API_VERSION
VERSION_VAR MINIUPNPC_VERSION)
mark_as_advanced(MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY)
if(MINIUPNPC_PREFER_STATIC_LIB)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${MINIUPNPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
unset(MINIUPNPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
endif()