diff --git a/cmake/compile_definitions/common.cmake b/cmake/compile_definitions/common.cmake index f10b2006cf6..c096920a06b 100644 --- a/cmake/compile_definitions/common.cmake +++ b/cmake/compile_definitions/common.cmake @@ -118,7 +118,7 @@ else() endif() list(APPEND SUNSHINE_EXTERNAL_LIBRARIES - libminiupnpc-static + ${MINIUPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} enet opus diff --git a/cmake/dependencies/common.cmake b/cmake/dependencies/common.cmake index 316de3f9272..1113832c921 100644 --- a/cmake/dependencies/common.cmake +++ b/cmake/dependencies/common.cmake @@ -9,13 +9,33 @@ add_subdirectory(third-party/moonlight-common-c/enet) # web server add_subdirectory(third-party/Simple-Web-Server) +# common dependencies +find_package(OpenSSL REQUIRED) +find_package(PkgConfig REQUIRED) +find_package(Threads REQUIRED) +pkg_check_modules(CURL REQUIRED libcurl) + # miniupnp -set(UPNPC_BUILD_SHARED OFF CACHE BOOL "No shared libraries") -set(UPNPC_BUILD_TESTS OFF CACHE BOOL "Don't build tests for miniupnpc") -set(UPNPC_BUILD_SAMPLE OFF CACHE BOOL "Don't build samples for miniupnpc") -set(UPNPC_NO_INSTALL ON CACHE BOOL "Don't install any libraries build for miniupnpc") -add_subdirectory(third-party/miniupnp/miniupnpc) -include_directories(SYSTEM third-party/miniupnp/miniupnpc/include) +if(SUNSHINE_SYSTEM_MINIUPNP) + pkg_check_modules(MINIUPNP miniupnpc REQUIRED) + + # Use includedir pkg-config variable rather than MINIUPNP_INCLUDE_DIRS + # defined above. The latter may be blank, as pkg-config sometimes omits -I + # flags for directories that are searched by default (e.g. /usr/include), + # but we need a value to append /miniupnpc to. Normally source files would + # prefix their #include directives with miniupnpc/, but this does not align + # with the directory structure of the git submodule used below. + pkg_get_variable(MINIUPNP_INCLUDE_DIR miniupnpc includedir) + include_directories(SYSTEM ${MINIUPNP_INCLUDE_DIR}/miniupnpc) +else() + set(UPNPC_BUILD_SHARED OFF CACHE BOOL "No shared libraries") + set(UPNPC_BUILD_TESTS OFF CACHE BOOL "Don't build tests for miniupnpc") + set(UPNPC_BUILD_SAMPLE OFF CACHE BOOL "Don't build samples for miniupnpc") + set(UPNPC_NO_INSTALL ON CACHE BOOL "Don't install any libraries build for miniupnpc") + set(MINIUPNP_LIBRARIES libminiupnpc-static) + add_subdirectory(third-party/miniupnp/miniupnpc) + include_directories(SYSTEM third-party/miniupnp/miniupnpc/include) +endif() # ffmpeg pre-compiled binaries if(WIN32) @@ -66,12 +86,6 @@ set(FFMPEG_LIBRARIES ${HDR10_PLUS_LIBRARY} ${FFMPEG_PLATFORM_LIBRARIES}) -# common dependencies -find_package(OpenSSL REQUIRED) -find_package(PkgConfig REQUIRED) -find_package(Threads REQUIRED) -pkg_check_modules(CURL REQUIRED libcurl) - # platform specific dependencies if(WIN32) include(${CMAKE_MODULE_PATH}/dependencies/windows.cmake) @@ -84,4 +98,3 @@ elseif(UNIX) include(${CMAKE_MODULE_PATH}/dependencies/linux.cmake) endif() endif() - diff --git a/cmake/prep/options.cmake b/cmake/prep/options.cmake index 1a216d263c8..cb2646188e6 100644 --- a/cmake/prep/options.cmake +++ b/cmake/prep/options.cmake @@ -4,6 +4,8 @@ option(SUNSHINE_CONFIGURE_ONLY "Configure special files only, then exit." OFF) option(SUNSHINE_ENABLE_TRAY "Enable system tray icon. This option will be ignored on macOS." ON) option(SUNSHINE_REQUIRE_TRAY "Require system tray icon. Fail the build if tray requirements are not met." ON) +option(SUNSHINE_SYSTEM_MINIUPNP "Use system installation of MiniUPnP rather than the submodule." OFF) + if(APPLE) option(SUNSHINE_CONFIGURE_PORTFILE "Configure macOS Portfile. Recommended to use with SUNSHINE_CONFIGURE_ONLY" OFF)