Browse Source

add hpsocket (#107)

* add hpsocket

* fix hpsocket

* fix code format
yecate 4 years ago
parent
commit
8de8415706
2 changed files with 153 additions and 0 deletions
  1. 78 0
      packages/h/hpsocket/port/xmake.lua
  2. 75 0
      packages/h/hpsocket/xmake.lua

+ 78 - 0
packages/h/hpsocket/port/xmake.lua

@@ -0,0 +1,78 @@
+add_rules("mode.debug", "mode.release")
+target("hpsocket")
+    set_kind("static")
+    if is_plat("windows") then
+        add_includedirs("/")
+        set_pcxxheader("stdafx.h")
+        add_defines("HPSOCKET_STATIC_LIB")
+
+        add_files("stdafx.cpp")
+        add_files("Windows/Common/Src/zlib/*.c")
+        add_files("Windows/Common/Src/http/http_parser.c")
+        add_files("Windows/Common/Src/kcp/ikcp.c")
+        add_files("Windows/Common/Src/*.cpp")
+        add_files("Windows/Src/*.cpp|HPSocket4C-SSL.cpp|HPSocket4C.cpp")
+
+        local vs = get_config("vs")
+        local vs_ver = "10.0"
+        local arch = "x64"
+        if is_arch("x86") then
+            arch = "x86"
+        end
+
+        if vs == "2015" then
+            vs_ver = "14.0"
+        elseif vs == "2017" then
+            vs_ver = "15.0"
+        elseif vs == "2019" then
+            vs_ver = "16.0"
+        end
+
+        local openssl_inc_dir = "Windows/Common/Lib/openssl/" .. vs_ver .. "/" .. arch .. "/include"
+        local openssl_lib_dir = "Windows/Common/Lib/openssl/" .. vs_ver .. "/" .. arch .. "/lib"
+        add_includedirs(openssl_inc_dir)
+        add_linkdirs(openssl_lib_dir)
+        add_links("libssl", "libcrypto", "crypt32")
+        
+        add_headerfiles("Windows/Include/HPSocket/HPSocket.h")
+        add_headerfiles("Windows/Include/HPSocket/HPSocket-SSL.h")
+        add_headerfiles("Windows/Include/HPSocket/HPTypeDef.h")
+        add_headerfiles("Windows/Include/HPSocket/SocketInterface.h")
+    end
+
+    if is_plat("linux", "android") then
+        add_cxxflags("-fPIC")
+        add_files("Linux/src/common/crypto/Crypto.cpp")
+        add_files("Linux/src/common/http/http_parser.c")
+        add_files("Linux/src/common/kcp/ikcp.c")
+        add_files("Linux/src/common/*.cpp")
+        add_files("Linux/src/*.cpp|HPSocket4C-SSL.cpp|HPSocket4C.cpp")
+
+        local include_dir
+        local link_dir
+        if is_plat("android") then
+            include_dir = "Linux/dependent/android-ndk/$(arch)/include"
+            link_dir = "Linux/dependent/android-ndk/$(arch)/lib"
+        else 
+            local arch = "x86"
+            if is_arch("x86_64") then
+                arch = "x64"
+            end
+            include_dir = "Linux/dependent/" .. arch .. "/include"
+            link_dir = "Linux/dependent/" .. arch .. "/lib"
+        end
+        add_includedirs(include_dir)
+        add_linkdirs(link_dir)
+        add_links("ssl", "crypto")
+        if is_plat("android") then
+            add_links("iconv", "charset")
+        else
+            add_links("z", "jemalloc_pic")
+        end
+
+        add_headerfiles("Linux/include/hpsocket/HPSocket.h") 
+        add_headerfiles("Linux/include/hpsocket/HPSocket-SSL.h")
+        add_headerfiles("Linux/include/hpsocket/HPTypeDef.h")
+        add_headerfiles("Linux/include/hpsocket/SocketInterface.h")
+        add_headerfiles("Linux/include/hpsocket/(common/*.h)")
+    end

+ 75 - 0
packages/h/hpsocket/xmake.lua

@@ -0,0 +1,75 @@
+package("hpsocket")
+    set_homepage("https://github.com/ldcsaa/HP-Socket")
+    set_description("High Performance Network Framework")
+    add_urls("https://github.com/ldcsaa/HP-Socket/archive/$(version).tar.gz",
+             "https://github.com/ldcsaa/HP-Socket.git")
+
+    add_versions("v5.7.2", "4397375000ec261265542498f6c5675d71cec9582319a9083e0f77ac41deac5a")
+
+    if is_plat("windows") then
+        add_syslinks("crypt32", "ws2_32", "kernel32")
+        add_links("hpsocket", "libssl", "libcrypto")
+    elseif is_plat("linux") then
+        add_syslinks("rt", "dl", "pthread")
+        add_links("hpsocket", "ssl", "crypto", "z", "jemalloc_pic")
+    elseif is_plat("android") then
+        add_syslinks("dl", "z")
+        add_links("hpsocket", "ssl", "crypto", "iconv", "charset")
+    end
+
+    on_load(function (package)
+        if package:is_plat("windows") then
+            package:add("defines", "HPSOCKET_STATIC_LIB")
+        end
+    end)
+
+    on_install("windows", "linux", "android", function (package)
+        if package:is_plat("windows") then
+            io.writefile("stdafx.h", [[
+            #pragma once
+            #define _DETECT_MEMORY_LEAK
+            #include "Windows/Common/Src/GeneralHelper.h"
+            ]])
+            io.writefile("stdafx.cpp", [[
+                #include "stdafx.h"
+            ]])
+        end
+        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+        import("package.tools.xmake").install(package)
+
+        if package:is_plat("windows") then
+            local vs = get_config("vs")
+            local vs_ver = "10.0"
+            local arch = "x64"
+            if is_arch("x86") then
+                arch = "x86"
+            end
+
+            if vs == "2015" then
+                vs_ver = "14.0"
+            elseif vs == "2017" then
+                vs_ver = "15.0"
+            elseif vs == "2019" then
+                vs_ver = "16.0"
+            end
+            os.cp("Windows/Common/Lib/openssl/" .. vs_ver .. "/" .. arch .. "/lib" .. "/*.lib", package:installdir("lib"))
+        elseif package:is_plat("linux") then
+            local arch = "x86"
+            if is_arch("x86_64") then 
+                arch = "x64"
+            end
+            os.cp("Linux/dependent/" .. arch .. "/lib" .. "/*.a", package:installdir("lib"))
+        elseif package:is_plat("android") then
+            os.cp("Linux/dependent/android-ndk/$(arch)/lib/*.a", package:installdir("lib"))
+        end
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <iostream>
+            #include "HPSocket.h"
+            static void test() {
+                std::cout << HP_GetHPSocketVersion() << "\n";
+            }
+        ]]}, {configs = {languages = "c++11"}, includes = "HPSocket.h", defines = "HPSOCKET_STATIC_LIB"}))
+    end)