Unverified Commit d1f205d1 authored by anonimal's avatar anonimal

Deps: miniupnp build update/fixes

parent b31435a3
......@@ -57,6 +57,12 @@ option(WITH_TESTS "Build unit tests" OFF)
option(WITH_FUZZ_TESTS "Build fuzz tests" OFF)
option(WITH_INTEGRATION_TESTS "Build integration tests" OFF)
option(WITH_COTIRE "Enable cotire (compile time reducer) - precompiled header and single compilation unit builds" ${MSVC})
# The miniupnp project has, historically, be unreliable in providing timely releases after security patches.
# Use this option to build your own miniupnpc (using Kovri's mindful fork) to be used in kovri-core lib.
# You may also need to keep this option off if your system *must* rely on using a system installation.
option(BUILD_MINIUPNPC "Build in-tree miniupnpc" OFF)
# Verbosity enabled by default, but can be disabled from cli by adding -DCMAKE_VERBOSE_MAKEFILE=OFF
# https://github.com/monero-project/kovri/pull/867#discussion_r184359361
option(CMAKE_VERBOSE_MAKEFILE "Enable verbose build output" ON)
......@@ -401,6 +407,7 @@ message(STATUS " TESTS : ${WITH_TESTS}")
message(STATUS " FUZZ TESTS : ${WITH_FUZZ_TESTS}")
message(STATUS " INTEGRATION TESTS: ${WITH_INTEGRATION_TESTS}")
message(STATUS " Cotire : ${WITH_COTIRE}")
message(STATUS " BUILD MINIUPNPC : ${BUILD_MINIUPNPC}")
message(STATUS "---------------------------------------")
add_subdirectory(src)
......@@ -421,18 +428,35 @@ endif()
# TODO(unassigned): multiple components?
add_library(kovri INTERFACE)
target_link_libraries(kovri INTERFACE kovri-core kovri-client kovri-internal libminiupnpc-static ${OPENSSL_LIBRARIES} ${CryptoPP_LIBRARIES})
target_link_libraries(kovri INTERFACE kovri-core kovri-client kovri-internal libminiupnpc ${OPENSSL_LIBRARIES} ${CryptoPP_LIBRARIES})
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME kovri)
include(GNUInstallDirs)
install(TARGETS kovri kovri-internal libminiupnpc-static miniupnpc-private
install(TARGETS kovri kovri-internal libminiupnpc
EXPORT KovriTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (MINIUPNPC_BUILT)
install(TARGETS miniupnpc-private
EXPORT KovriTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (WITH_STATIC)
install(TARGETS libminiupnpc-static
EXPORT KovriTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
install(TARGETS libminiupnpc-shared
EXPORT KovriTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()
install(TARGETS kovri-core
EXPORT KovriTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
......
# Copyright (c) 2015-2019, The Kovri I2P Router Project
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Parts of this file are originally copyright (c) 2014-2018 The Monero Project
#
# Locate miniupnp library
# This module defines
# MINIUPNP_FOUND, if false, do not try to link to miniupnp
# MINIUPNP_LIBRARY, the miniupnp variant
# MINIUPNP_INCLUDE_DIR, where to find miniupnpc.h and family)
# MINIUPNPC_VERSION_1_7_OR_HIGHER, set if we detect the version of miniupnpc is 1.7 or higher
#
# NOTE: If you wish to use a non-system-default miniupnp installation location, pass
#
# MINIUPNP_INCLUDE_DIR=<path to miniupnpc include>
# MINIUPNP_LIBRARY=<path to miniupnpc lib>
#
# directly to `make` or export into your shell environment. Otherwise, this should find your install.
#
find_path(MINIUPNP_INCLUDE_DIR miniupnpc.h
HINTS $ENV{MINIUPNP_INCLUDE_DIR}
PATH_SUFFIXES miniupnpc)
set(MINIUPNP_SHORT_LIB libminiupnpc.a)
if (NOT WITH_STATIC)
set(MINIUPNP_SHORT_LIB miniupnpc)
endif()
find_library(MINIUPNP_LIBRARY ${MINIUPNP_SHORT_LIB}
HINTS $ENV{MINIUPNP_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
MiniUPnPc DEFAULT_MSG
MINIUPNP_INCLUDE_DIR
MINIUPNP_LIBRARY)
# TODO(unassigned): outdated, higher requisite to match API changes
if (MINIUPNPC_FOUND)
file(STRINGS "${MINIUPNP_INCLUDE_DIR}/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}")
if (${MINIUPNPC_API_VERSION} GREATER "10" OR ${MINIUPNPC_API_VERSION} EQUAL "10")
message(STATUS "Found miniupnpc API version " ${MINIUPNPC_API_VERSION})
set(MINIUPNP_FOUND true)
set(MINIUPNPC_VERSION_1_7_OR_HIGHER true)
endif()
endif()
endif()
mark_as_advanced(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY)
......@@ -28,26 +28,66 @@
#
# Parts of this file are originally copyright (c) 2014-2018 The Monero Project
message(STATUS "Using in-tree miniupnpc")
find_package(Miniupnpc REQUIRED)
add_library(libminiupnpc INTERFACE)
add_subdirectory(miniupnp/miniupnpc)
# In addition to allowing optional local building of miniupnpc, the following will require that
# the build is built locally if a system package only provides a shared library (like on Arch)
# even though we have chosen to build statically. NOTE: do *not* distribute a local dynamic-build
# when building in-tree dynamic (must build statically).
if (NOT MINIUPNP_INCLUDE_DIR OR NOT MINIUPNP_LIBRARY)
set(BUILD_MINIUPNPC ON)
endif()
# It is better to setup these options inside miniupnp/miniupnpc/CMakeLists.txt
# But the following line allow us to do it here
set_property(TARGET libminiupnpc-static PROPERTY FOLDER "deps")
if (BUILD_MINIUPNPC)
if (NOT WITH_STATIC)
set(UPNPC_BUILD_STATIC OFF CACHE BOOL "Disable static lib target" FORCE)
set(UPNPC_BUILD_SHARED ON CACHE BOOL "Enable shared lib target" FORCE)
endif()
# Suppress noise warnings
if(MSVC)
set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267")
elseif(NOT MSVC)
set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value")
endif()
if (MINIUPNP_FOUND)
message(WARNING "Ignoring system miniupnpc, forcing a local build")
endif()
message(STATUS "Using " ${CMAKE_CURRENT_SOURCE_DIR}/miniupnp/miniupnpc)
add_subdirectory(miniupnp/miniupnpc)
if (NOT WITH_STATIC)
set(MINIUPNPC_TARGET libminiupnpc-shared)
else()
set(MINIUPNPC_TARGET libminiupnpc-static)
endif()
# https://github.com/monero-project/kovri/pull/865#discussion_r184370624
set_property(TARGET libminiupnpc-static APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS MINIUPNP_STATICLIB)
set(MINIUPNPC_FLAGS "")
if(MSVC)
list(APPEND MINIUPNPC_FLAGS "-wd4244 -wd4267")
elseif(NOT MSVC)
list(APPEND MINIUPNPC_FLAGS "-Wno-undef -Wno-unused-result -Wno-unused-value")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
list(APPEND MINIUPNPC_FLAGS "-D_NETBSD_SOURCE")
endif()
# Use #include <miniupnp/miniupnpc/miniupnpc.h>
set_property(TARGET libminiupnpc-static APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
string(REPLACE ";" " " MINIUPNPC_FLAGS "${MINIUPNPC_FLAGS}" )
set_property(TARGET ${MINIUPNPC_TARGET} APPEND_STRING PROPERTY COMPILE_FLAGS "${MINIUPNPC_FLAGS}")
set_property(TARGET ${MINIUPNPC_TARGET} PROPERTY FOLDER "deps")
# Suppress warnings from miniupnpc headers
set_property(TARGET libminiupnpc-static APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
if (WITH_STATIC)
set_property(TARGET ${MINIUPNPC_TARGET} APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS MINIUPNP_STATICLIB)
endif()
# Use #include <miniupnp/miniupnpc/miniupnpc.h>
set_property(TARGET ${MINIUPNPC_TARGET} APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
# Suppress warnings from miniupnpc headers
set_property(TARGET ${MINIUPNPC_TARGET} APPEND PROPERTY
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(libminiupnpc INTERFACE ${MINIUPNPC_TARGET})
set(MINIUPNPC_BUILT ON PARENT_SCOPE) # TODO(unassigned): HACK for install
else()
target_include_directories(libminiupnpc INTERFACE ${MINIUPNP_INCLUDE_DIR})
target_link_libraries(libminiupnpc INTERFACE ${MINIUPNP_LIBRARY})
endif()
......@@ -83,7 +83,7 @@ target_include_directories(kovri-core
set_target_properties(kovri-core PROPERTIES
PUBLIC_HEADER $<TARGET_PROPERTY:kovri-core,INTERFACE_SOURCES>)
target_link_libraries(kovri-core PUBLIC kovri-internal ${Boost_LIBRARIES})
target_link_libraries(kovri-core PUBLIC kovri-internal libminiupnpc ${Boost_LIBRARIES})
if(MINGW)
target_link_libraries(kovri-core PUBLIC iphlpapi)
......@@ -130,9 +130,6 @@ if(WITH_CRYPTOPP)
${CRYPTOPP_DIR}/crypto_const.h)
endif()
# Add definition for our implementation (must be here or in root recipe)
target_link_libraries(kovri-core PRIVATE libminiupnpc-static)
if (ARM)
target_link_libraries(kovri-core PRIVATE atomic)
endif()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment