From 677e0db63649ad2aeb536783eb745c651f2fd5c2 Mon Sep 17 00:00:00 2001 From: Cristian Morales Vega Date: Wed, 25 Nov 2020 12:56:27 +0000 Subject: [PATCH] Install cmake config file miniupnpc::miniupnpc becomes an ALIAS for the shared library, if available, and the static library otherwise. Users of the installed library can use MINIUPNPC_USE_STATIC_LIBS to force the use of the static library. --- miniupnpc/CMakeLists.txt | 30 +++++++++++++++++++++++++++++- miniupnpc/miniupnpc-config.cmake | 6 ++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 miniupnpc/miniupnpc-config.cmake diff --git a/miniupnpc/CMakeLists.txt b/miniupnpc/CMakeLists.txt index 64bbac1..5323862 100644 --- a/miniupnpc/CMakeLists.txt +++ b/miniupnpc/CMakeLists.txt @@ -53,7 +53,7 @@ if (MSVC) endif() configure_file (${CMAKE_CURRENT_SOURCE_DIR}/miniupnpcstrings.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/miniupnpcstrings.h) -target_include_directories(miniupnpc-private INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(miniupnpc-private INTERFACE $) set (MINIUPNPC_SOURCES igd_desc_parse.c @@ -112,19 +112,35 @@ endif () if (UPNPC_BUILD_STATIC) add_library (libminiupnpc-static STATIC ${MINIUPNPC_SOURCES}) + if (NOT UPNPC_BUILD_SHARED) + add_library (miniupnpc::miniupnpc ALIAS libminiupnpc-static) + endif() + set_target_properties (libminiupnpc-static PROPERTIES EXPORT_NAME miniupnpc) if (WIN32) set_target_properties (libminiupnpc-static PROPERTIES OUTPUT_NAME "libminiupnpc") else() set_target_properties (libminiupnpc-static PROPERTIES OUTPUT_NAME "miniupnpc") endif() target_link_libraries (libminiupnpc-static PRIVATE miniupnpc-private) + target_include_directories(libminiupnpc-static INTERFACE $) target_compile_definitions(libminiupnpc-static PUBLIC MINIUPNP_STATICLIB) if (NOT UPNPC_NO_INSTALL) + install (TARGETS miniupnpc-private EXPORT miniupnpc-private) + + install (EXPORT miniupnpc-private + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/miniupnpc" + NAMESPACE miniupnpc::) + install (TARGETS libminiupnpc-static + EXPORT libminiupnpc-static RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + install (EXPORT libminiupnpc-static + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/miniupnpc" + NAMESPACE miniupnpc::) endif() if (UPNPC_BUILD_SAMPLE) @@ -136,21 +152,29 @@ endif () if (UPNPC_BUILD_SHARED) add_library (libminiupnpc-shared SHARED ${MINIUPNPC_SOURCES}) + add_library (miniupnpc::miniupnpc ALIAS libminiupnpc-shared) + set_target_properties (libminiupnpc-shared PROPERTIES EXPORT_NAME miniupnpc) 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}) target_link_libraries (libminiupnpc-shared PRIVATE miniupnpc-private) target_compile_definitions(libminiupnpc-shared PRIVATE MINIUPNP_EXPORTS) + target_include_directories(libminiupnpc-shared INTERFACE $) if (WIN32) target_link_libraries(libminiupnpc-shared INTERFACE ws2_32 iphlpapi) endif() if (NOT UPNPC_NO_INSTALL) install (TARGETS libminiupnpc-shared + EXPORT libminiupnpc-shared RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + install (EXPORT libminiupnpc-shared + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/miniupnpc" + NAMESPACE miniupnpc::) endif() if (UPNPC_BUILD_SAMPLE) @@ -215,6 +239,10 @@ if (NOT UPNPC_NO_INSTALL) miniupnpc_declspec.h DESTINATION include/miniupnpc ) + + install(FILES miniupnpc-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/miniupnpc + ) endif() # vim: ts=2:sw=2 diff --git a/miniupnpc/miniupnpc-config.cmake b/miniupnpc/miniupnpc-config.cmake new file mode 100644 index 0000000..116876a --- /dev/null +++ b/miniupnpc/miniupnpc-config.cmake @@ -0,0 +1,6 @@ +if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/libminiupnpc-shared.cmake" OR MINIUPNPC_USE_STATIC_LIBS) + include("${CMAKE_CURRENT_LIST_DIR}/miniupnpc-private.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/libminiupnpc-static.cmake") +else() + include("${CMAKE_CURRENT_LIST_DIR}/libminiupnpc-shared.cmake") +endif()