foxygit / doom Log in
commit b8a22bb9e837cacee6b36146cad4934d4fb7db5d
Author:     Turo Lamminen <turol@iki.fi>
AuthorDate: Tue Jul 12 20:48:51 2022 +0300
Commit:     Turo Lamminen <turol@iki.fi>
CommitDate: Tue Jul 12 21:05:54 2022 +0300

    Add option to disable SDL2_net
---
 CMakeLists.txt             |  8 +++++-
 configure.ac               | 10 +++++++-
 src/CMakeLists.txt         | 15 ++++++++---
 src/doom/CMakeLists.txt    |  5 +++-
 src/heretic/CMakeLists.txt |  5 +++-
 src/hexen/CMakeLists.txt   |  5 +++-
 src/net_sdl.c              | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 src/strife/CMakeLists.txt  |  5 +++-
 8 files changed, 107 insertions(+), 9 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b73c7984..21b7d928 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,9 +28,15 @@ else()
                         "-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)
diff --git a/configure.ac b/configure.ac
index 8ef1d65a..3f3caa5c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,15 @@ fi

 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],
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5de14539..a78903c0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -32,7 +32,10 @@ set(DEDSERV_FILES
 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(DEHACKED_SOURCE_FILES
 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 @@ endif()

 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
diff --git a/src/doom/CMakeLists.txt b/src/doom/CMakeLists.txt
index 0310910a..90f0d164 100644
--- a/src/doom/CMakeLists.txt
+++ b/src/doom/CMakeLists.txt
@@ -68,4 +68,7 @@ add_library(doom STATIC
             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()
diff --git a/src/heretic/CMakeLists.txt b/src/heretic/CMakeLists.txt
index 9f12bde0..95942b5b 100644
--- a/src/heretic/CMakeLists.txt
+++ b/src/heretic/CMakeLists.txt
@@ -54,4 +54,7 @@ add_library(heretic STATIC
             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()
diff --git a/src/hexen/CMakeLists.txt b/src/hexen/CMakeLists.txt
index 6b4beed2..03535e2e 100644
--- a/src/hexen/CMakeLists.txt
+++ b/src/hexen/CMakeLists.txt
@@ -55,4 +55,7 @@ add_library(hexen STATIC
                                 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()
diff --git a/src/net_sdl.c b/src/net_sdl.c
index c9b3e81f..2965f423 100644
--- 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_module_t net_sdl_module =
     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
diff --git a/src/strife/CMakeLists.txt b/src/strife/CMakeLists.txt
index 06b17a6b..d7d03f44 100644
--- a/src/strife/CMakeLists.txt
+++ b/src/strife/CMakeLists.txt
@@ -70,4 +70,7 @@ set(STRIFE_SOURCES
 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()