Jelajahi Sumber

Add enet package (#809)

* Add enet

* ENet: Fix dynamic library build

* enet: Improve shared build on Windows/MinGW
Jérôme Leclercq 3 tahun lalu
induk
melakukan
f2cfd62f25
2 mengubah file dengan 89 tambahan dan 0 penghapusan
  1. 27 0
      packages/e/enet/patches/cmake.patch
  2. 62 0
      packages/e/enet/xmake.lua

+ 27 - 0
packages/e/enet/patches/cmake.patch

@@ -0,0 +1,27 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 6f7fc27..6062da7 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -84,11 +84,20 @@ set(SOURCE_FILES
+ source_group(include FILES ${INCLUDE_FILES})
+ source_group(source FILES ${SOURCE_FILES})
+ 
+-add_library(enet STATIC
++add_library(enet
+     ${INCLUDE_FILES}
+     ${SOURCE_FILES}
+ )
+ 
+-if (MINGW)
++if (WIN32)
++    if (BUILD_SHARED_LIBS)
++        add_definitions(-DENET_DLL=1)
++    endif()
++
+     target_link_libraries(enet winmm ws2_32)
+ endif()
++
++install(FILES ${INCLUDE_FILES} DESTINATION ${INCLUDE_FILES_PREFIX})
++install(TARGETS enet RUNTIME DESTINATION ${BIN_INSTALL_DIR}
++                     LIBRARY DESTINATION ${LIB_INSTALL_DIR}
++                     ARCHIVE DESTINATION ${LIB_INSTALL_DIR})

+ 62 - 0
packages/e/enet/xmake.lua

@@ -0,0 +1,62 @@
+package("enet")
+
+    set_homepage("http://enet.bespin.org")
+    set_description("Reliable UDP networking library.")
+    set_license("MIT")
+
+    add_urls("https://github.com/lsalzman/enet/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/lsalzman/enet.git")
+
+    add_versions("v1.3.17", "1e0b4bc0b7127a2d779dd7928f0b31830f5b3dcb7ec9588c5de70033e8d2434a")
+    add_patches("v1.3.17", path.join(os.scriptdir(), "patches", "cmake.patch"), "e77d2d129952443d67c1ec432de81843d72b854d25bbd6fb244b0f85804d21d1")
+
+    if is_plat("mingw") and is_subhost("msys") then
+        add_extsources("pacman::enet")
+    elseif is_plat("linux") then
+        add_extsources("pacman::enet", "apt::libenet-dev")
+    elseif is_plat("macosx") then
+        add_extsources("brew::enet")
+    end
+
+    add_deps("cmake")
+
+    if is_plat("windows", "mingw") then
+        add_syslinks("winmm", "ws2_32")
+    end
+
+    on_load("windows", "mingw", function (package)
+        if package:config("shared") then
+            package:add("defines", "ENET_DLL")
+        end
+    end)
+
+    on_install(function (package)
+        local configs = {}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        import("package.tools.cmake").install(package, configs)
+   end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            void test()
+            {
+                if (enet_initialize () != 0)
+                    return;
+
+                ENetAddress address;
+                ENetHost* server;
+                address.host = ENET_HOST_ANY;
+                address.port = 1234;
+                server = enet_host_create (&address, 32, 2, 0, 0);
+                if (server == NULL)
+                    return;
+
+                ENetEvent event;
+                while (enet_host_service (server, &event, 1000) > 0);
+
+                enet_host_destroy(server);
+                enet_deinitialize();
+            }
+        ]]}, {includes = {"enet/enet.h"}}))
+    end)