ref: b8a22bb9e837cacee6b36146cad4934d4fb7db5d
parent: 557185dd7f66b36ffb57b418b47aa39ae09744b6
author: Turo Lamminen <[email protected]>
date: Tue Jul 12 16:48:51 EDT 2022
Add option to disable SDL2_net
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,9 +28,15 @@
"-Wredundant-decls")
endif()
+option(ENABLE_SDL2_NET "Enable SDL2_net" On)
+
find_package(SDL2 2.0.7)
find_package(SDL2_mixer 2.0.2)
-find_package(SDL2_net 2.0.0)
+if(ENABLE_SDL2_NET)
+ find_package(SDL2_net 2.0.0)
+else()
+ add_compile_definitions(DISABLE_SDL2NET=1)
+endif()
# Check for libsamplerate.
find_package(samplerate)
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,15 @@
PKG_CHECK_MODULES(SDL, [sdl2 >= 2.0.7])
PKG_CHECK_MODULES(SDLMIXER, [SDL2_mixer >= 2.0.2])
-PKG_CHECK_MODULES(SDLNET, [SDL2_net >= 2.0.0])
+
+# Check for networking
+AC_ARG_ENABLE([sdl2net],
+AS_HELP_STRING([--disable-sdl2net], [Disable SDL2_net support])
+)
+AS_IF([test "x$enable_sdl2net" != xno], [
+ PKG_CHECK_MODULES(SDLNET, [SDL2_net >= 2.0.0])], [
+ AC_DEFINE([DISABLE_SDL2NET], [1], [SDL2_net disabled])
+])
# Check for bash-completion.
AC_ARG_ENABLE([bash-completion],
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -32,7 +32,10 @@
add_executable("${PROGRAM_PREFIX}server" WIN32 ${COMMON_SOURCE_FILES} ${DEDSERV_FILES})
target_include_directories("${PROGRAM_PREFIX}server"
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries("${PROGRAM_PREFIX}server" SDL2::SDL2main SDL2::SDL2 SDL2::net)
+target_link_libraries("${PROGRAM_PREFIX}server" SDL2::SDL2main SDL2::SDL2)
+if(ENABLE_SDL2_NET)
+ target_link_libraries("${PROGRAM_PREFIX}server" SDL2::net)
+endif()
# Source files used by the game binaries (chocolate-doom, etc.)
@@ -121,7 +124,10 @@
set(SOURCE_FILES ${COMMON_SOURCE_FILES} ${GAME_SOURCE_FILES})
set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES})
-set(EXTRA_LIBS SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net textscreen pcsound opl)
+set(EXTRA_LIBS SDL2::SDL2main SDL2::SDL2 SDL2::mixer textscreen pcsound opl)
+if(ENABLE_SDL2_NET)
+ list(APPEND EXTRA_LIBS SDL2::net)
+endif()
if(SAMPLERATE_FOUND)
list(APPEND EXTRA_LIBS samplerate::samplerate)
endif()
@@ -213,7 +219,10 @@
target_include_directories("${PROGRAM_PREFIX}setup"
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::SDL2main SDL2::SDL2 SDL2::mixer SDL2::net setup textscreen)
+target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::SDL2main SDL2::SDL2 SDL2::mixer setup textscreen)
+if(ENABLE_SDL2_NET)
+ target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::net)
+endif()
if(MSVC)
set_target_properties("${PROGRAM_PREFIX}setup" PROPERTIES
--- a/src/doom/CMakeLists.txt
+++ b/src/doom/CMakeLists.txt
@@ -68,4 +68,7 @@
wi_stuff.c wi_stuff.h)
target_include_directories(doom PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(doom SDL2::SDL2 SDL2::mixer SDL2::net)
+target_link_libraries(doom SDL2::SDL2 SDL2::mixer)
+if(ENABLE_SDL2_NET)
+ target_link_libraries(doom SDL2::net)
+endif()
--- a/src/heretic/CMakeLists.txt
+++ b/src/heretic/CMakeLists.txt
@@ -54,4 +54,7 @@
s_sound.c s_sound.h)
target_include_directories(heretic PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(heretic textscreen SDL2::SDL2 SDL2::mixer SDL2::net)
+target_link_libraries(heretic textscreen SDL2::SDL2 SDL2::mixer)
+if(ENABLE_SDL2_NET)
+ target_link_libraries(heretic SDL2::net)
+endif()
--- a/src/hexen/CMakeLists.txt
+++ b/src/hexen/CMakeLists.txt
@@ -55,4 +55,7 @@
xddefs.h)
target_include_directories(hexen PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(hexen SDL2::SDL2 SDL2::mixer SDL2::net)
+target_link_libraries(hexen SDL2::SDL2 SDL2::mixer)
+if(ENABLE_SDL2_NET)
+ target_link_libraries(hexen SDL2::net)
+endif()
--- a/src/net_sdl.c
+++ b/src/net_sdl.c
@@ -33,6 +33,10 @@
// NETWORKING
//
+
+#ifndef DISABLE_SDL2NET
+
+
#include <SDL_net.h>
#define DEFAULT_PORT 2342
@@ -376,3 +380,62 @@
NET_SDL_ResolveAddress,
};
+
+#else // DISABLE_SDL2NET
+
+// no-op implementation
+
+
+static boolean NET_NULL_InitClient(void)
+{
+ return false;
+}
+
+
+static boolean NET_NULL_InitServer(void)
+{
+ return false;
+}
+
+
+static void NET_NULL_SendPacket(net_addr_t *addr, net_packet_t *packet)
+{
+}
+
+
+static boolean NET_NULL_RecvPacket(net_addr_t **addr, net_packet_t **packet)
+{
+ return false;
+}
+
+
+static void NET_NULL_AddrToString(net_addr_t *addr, char *buffer, int buffer_len)
+{
+
+}
+
+
+static void NET_NULL_FreeAddress(net_addr_t *addr)
+{
+}
+
+
+net_addr_t *NET_NULL_ResolveAddress(const char *address)
+{
+ return NULL;
+}
+
+
+net_module_t net_sdl_module =
+{
+ NET_NULL_InitClient,
+ NET_NULL_InitServer,
+ NET_NULL_SendPacket,
+ NET_NULL_RecvPacket,
+ NET_NULL_AddrToString,
+ NET_NULL_FreeAddress,
+ NET_NULL_ResolveAddress,
+};
+
+
+#endif // DISABLE_SDL2NET
--- a/src/strife/CMakeLists.txt
+++ b/src/strife/CMakeLists.txt
@@ -70,4 +70,7 @@
add_library(strife STATIC ${STRIFE_SOURCES})
target_include_directories(strife PRIVATE "../" "../../win32/" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(strife textscreen SDL2::SDL2 SDL2::mixer SDL2::net)
+target_link_libraries(strife textscreen SDL2::SDL2 SDL2::mixer)
+if(ENABLE_SDL2_NET)
+ target_link_libraries(strife SDL2::net)
+endif()