cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
868 stars 115 forks source link

Check for shared ENet if USE_SHARED_ENET is set #825

Open rootkea opened 8 months ago

rootkea commented 8 months ago

Hello!

When I ask to use the shared ENet (-DUSE_SHARED_ENET=ON) cmake doesn't check for the enet unlike SDL2. And so build files get written without any issue. It's the ninja which fails since it can't find the enet as it's not installed on the system.

I tried to check for enet in CMakeLists.txt but couldn't fix the issue as it seems we need to write FindENet.cmake. This is what I tried:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 61b486b1..ceba1328 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,7 +83,9 @@ else()
     set(ENet_LIBRARIES ${ENet_LIBRARY})
 endif()

-if(NOT USE_SHARED_ENET)
+if(USE_SHARED_ENET)
+    find_package(enet REQUIRED)
+else()
     include_directories(src/cdogs/enet/include)
 endif()

@@ -309,7 +311,7 @@ else()
        # debian specific
        set(CPACK_DEBIAN_PACKAGE_MAINTAINER "C-Dogs SDL Team")
        set(CPACK_DEBIAN_PACKAGE_SECTION Games)
-       set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libsdl2-image, libsdl2-mixer")
+       set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libsdl2-image, libsdl2-mixer, libenet")

        # fedora/suse specific
        set(CPACK_RPM_PACKAGE_LICENSE "GPL2")
rootkea commented 8 months ago

I did find FindENet.cmake at https://github.com/stuntrally/stuntrally/blob/master/cmake/FindENet.cmake but I'm a cmake newbie so not sure exactly which part is relevant to us...

rootkea commented 8 months ago

BTW, ENet provides libenet.pc so maybe we can use pkg-config within cmake instead of maintaining our own FindENet.cmake?

  1. https://stackoverflow.com/questions/29191855/what-is-the-proper-way-to-use-pkg-config-from-cmake
  2. https://cmake.org/cmake/help/latest/module/FindPkgConfig.html
rootkea commented 8 months ago

Moreover, I'm sorry but is there a strong a reason to maintain our own ENet in cdogs-sdl source? I mean upstream seems pretty active. Why aren't we upstreaming our ENet patches https://github.com/cxong/cdogs-sdl/commits/master/src/cdogs/enet ? It should ease the maintenance and also good for FLOSS. :)

reinerh commented 8 months ago

BTW, ENet provides libenet.pc so maybe we can use pkg-config within cmake instead of maintaining our own FindENet.cmake?

In my opinion using pkg-config to find ENet would be better than writing and maintaining a custom CMake module that searches it.

cxong commented 8 months ago

It would be good to upstream any changes, but testing enet / networking is a lot of work, happy if anyone else is willing to look at it