--- external/CMakeLists.txt.orig 2018-10-12 11:58:33.398503000 +0200 +++ external/CMakeLists.txt 2018-10-12 12:01:52.063061000 +0200 @@ -31,25 +31,28 @@ # This is broken up into two parts: first we check for miniupnp, compile it if we can't # find it, and thereafter we check for libunbound, and compile it if we can't find it. -# We always compile if we are building statically to reduce static dependency issues... -# ...except for FreeBSD, because FreeBSD is a special case that doesn't play well with -# others. find_package(Miniupnpc REQUIRED) -message(STATUS "Using in-tree miniupnpc") -add_subdirectory(miniupnp/miniupnpc) -set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") -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(CMAKE_SYSTEM_NAME MATCHES "NetBSD") - set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -D_NETBSD_SOURCE") -endif() +if(NOT MINIUPNPC_FOUND OR STATIC) + message(STATUS "Using in-tree miniupnpc") + add_subdirectory(miniupnp/miniupnpc) + set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external") + 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(CMAKE_SYSTEM_NAME MATCHES "NetBSD") + set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -D_NETBSD_SOURCE") + endif() -set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) + set(UPNP_LIBRARIES "libminiupnpc-static" PARENT_SCOPE) +else() + message(STATUS "Found miniupnpc shared library (${MINIUPNP_LIBRARY})") + set(UPNP_LIBRARIES ${MINIUPNP_LIBRARY} PARENT_SCOPE) + set(UPNP_INCLUDE_DIR ${MINIUPNP_INCLUDE_DIR} PARENT_SCOPE) +endif() find_package(Unbound)