diff --git a/cmake/dependencies/common.cmake b/cmake/dependencies/common.cmake index 24a808837..8674342da 100644 --- a/cmake/dependencies/common.cmake +++ b/cmake/dependencies/common.cmake @@ -7,6 +7,36 @@ include(dependencies/Boost_Sunshine) # submodules # moonlight common library set(ENET_NO_INSTALL ON CACHE BOOL "Don't install any libraries built for enet") + +# Apply FreeBSD patch to ENet if on FreeBSD +if(FREEBSD) + set(ENET_PATCH_FILE "${CMAKE_SOURCE_DIR}/patches/enet-freebsd-support.patch") + set(ENET_SOURCE_FILE "${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/enet/unix.c") + + # Check if patch needs to be applied + execute_process( + COMMAND patch -p0 -N --dry-run -i ${ENET_PATCH_FILE} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/enet + RESULT_VARIABLE PATCH_DRY_RUN_RESULT + OUTPUT_QUIET + ERROR_QUIET + ) + + # Apply patch if it hasn't been applied yet + if(PATCH_DRY_RUN_RESULT EQUAL 0) + message(STATUS "Applying FreeBSD patch to ENet") + execute_process( + COMMAND patch -p0 -N -i ${ENET_PATCH_FILE} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/enet + RESULT_VARIABLE PATCH_RESULT + ) + + if(NOT PATCH_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to apply FreeBSD patch to ENet") + endif() + endif() +endif() + add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/enet") # web server diff --git a/patches/enet_freebsd.patch b/patches/enet-freebsd-support.patch similarity index 96% rename from patches/enet_freebsd.patch rename to patches/enet-freebsd-support.patch index 51e65706e..530ec105b 100644 --- a/patches/enet_freebsd.patch +++ b/patches/enet-freebsd-support.patch @@ -1,8 +1,8 @@ diff --git a/unix.c b/unix.c -index 1234567..abcdefg 100644 +index 3d57e9d..c2318ca 100644 --- a/unix.c +++ b/unix.c -@@ -373,6 +373,14 @@ enet_socket_create (ENetSocketType type, int af) +@@ -373,6 +373,14 @@ enet_socket_create (int af, ENetSocketType type) } #endif