improve hpsocket and upgrade version to v5.7.3 (#193)

pull/196/head
yecate 4 years ago committed by GitHub
parent f47299b730
commit 5888b5597d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 182
      packages/h/hpsocket/port/xmake.lua
  2. 112
      packages/h/hpsocket/xmake.lua

@ -1,78 +1,142 @@
add_rules("mode.debug", "mode.release")
local dep_packages = {}
local options = {{name = "udp", package = "kcp"},
{name = "http", package = "http_parser"},
{name = "zlib", package = is_plat("android") and "" or "zlib"},
{name = "brotli", package = "brotli"},
{name = "ssl", package = ""},
{name = "iconv", package = ""}}
for _, opt in ipairs(options) do
local opt_name = "no_" .. opt.name
option(opt_name)
set_default(false)
set_showmenu(true)
set_category("option")
set_description("Build hpsocket without " .. opt.name)
add_defines("_" .. string.upper(opt.name) .. "_DISABLED")
option_end()
if not has_config(opt_name) and opt.package ~= "" then
add_requires(opt.package, is_plat("windows") and {} or {configs = {cxflags = "-fpic"}})
table.insert(dep_packages, opt.package)
end
end
option("no_4c")
set_default(false)
set_showmenu(true)
set_category("option")
set_description("Build hpsocket without C interface")
option_end()
option("unicode")
set_default(false)
set_showmenu(true)
set_category("option")
set_description("Build hpsocket with unicode character set")
option_end()
add_rules("mode.debug", "mode.release")
target("hpsocket")
set_kind("static")
set_kind("$(kind)")
for _, opt in ipairs(options) do
add_options("no_" .. opt.name)
end
for _, pkg in ipairs(dep_packages) do
add_packages(pkg)
end
local exclude_file
local install_files = {}
local no_4c = has_config("no_4c")
set_basename(no_4c and "hpsocket" or "hpsocket4c")
exclude_file = no_4c and "HPSocket4C.*|HPSocket4C-SSL.*" or "HPSocket.*|HPSocket-SSL.*"
if is_plat("windows") then
add_includedirs("/")
set_pcxxheader("stdafx.h")
add_defines("HPSOCKET_STATIC_LIB")
add_syslinks("ws2_32", "user32", "kernel32")
if not has_config("no_ssl") then
add_syslinks("crypt32")
end
elseif is_plat("linux") then
add_syslinks("pthread", "dl", "rt")
elseif is_plat("android") then
add_syslinks("dl")
if not has_config("no_zlib") then
add_syslinks("z")
end
end
local linkdir
if is_plat("windows") then
if has_config("unicode") then
add_defines("UNICODE", "_UNICODE")
end
set_pcxxheader("stdafx.h")
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")
add_files("Windows/Src/*.cpp|" .. exclude_file)
add_headerfiles("Windows/Include/HPSocket/*.h|" .. exclude_file)
add_defines(is_kind("shared") and "HPSOCKET_EXPORTS" or "HPSOCKET_STATIC_LIB")
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"
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
add_includedirs(".")
add_includedirs(path.join("Windows/Common/Lib/openssl", vs_ver, "$(arch)", "include"))
linkdir = path.join("Windows/Common/Lib/openssl", vs_ver, "$(arch)", "lib")
add_linkdirs(linkdir)
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")
if not has_config("no_ssl") then
add_links("libssl", "libcrypto")
if is_kind("static") then
table.insert(install_files, path.join(linkdir, "*.lib"))
end
end
elseif is_plat("linux", "android") then
add_cxflags("-fpic", {force = true})
add_files("Linux/src/common/crypto/*.cpp")
add_files("Linux/src/common/*.cpp")
add_files("Linux/src/*.cpp|HPSocket4C-SSL.cpp|HPSocket4C.cpp")
add_files("Linux/src/*.cpp|" .. exclude_file)
add_headerfiles("Linux/include/hpsocket/*.h|" .. exclude_file)
add_headerfiles("Linux/include/hpsocket/(common/*.h)")
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"
add_includedirs("Linux/dependent/android-ndk/$(arch)/include")
linkdir = "Linux/dependent/android-ndk/$(arch)/lib"
add_linkdirs(linkdir)
if not has_config("no_iconv") then
add_links("charset", "iconv")
if is_kind("static") then
table.insert(install_files, path.join(linkdir, "libcharset.a"))
table.insert(install_files, path.join(linkdir, "libiconv.a"))
end
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")
local arch = is_arch("x86_64") and "x64" or "x86"
add_includedirs(path.join("Linux/dependent", arch, "include"))
linkdir = path.join("Linux/dependent", arch, "lib")
add_linkdirs(linkdir)
add_links("jemalloc_pic")
if is_kind("static") then
table.insert(install_files, path.join(linkdir, "libjemalloc_pic.a"))
end
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)")
if not has_config("no_ssl") then
add_links("ssl", "crypto")
if is_kind("static") then
table.insert(install_files, path.join(linkdir, "libssl.a"))
table.insert(install_files, path.join(linkdir, "libcrypto.a"))
end
end
end
for _, file in ipairs(install_files) do
add_installfiles(file, {prefixdir = "lib"})
end

@ -1,75 +1,105 @@
package("hpsocket")
set_homepage("https://github.com/ldcsaa/HP-Socket")
set_description("High Performance Network Framework")
set_license("Apache-2.0")
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")
add_versions("v5.7.3", "b3f77120f94b0e85cabce3c184b8163c62aec42562c3b44beff61fd4d3aa4784")
local configs = {{name = "udp", package = "kcp"},
{name = "http", package = "http_parser"},
{name = "zlib", package = is_plat("android") and "" or "zlib"},
{name = "brotli", package = "brotli"},
{name = "ssl", package = ""},
{name = "iconv", package = ""}}
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")
for _, cfg in ipairs(configs) do
local cfg_name = "no_" .. cfg.name
add_configs(cfg_name, {description = "Build hpsocket without " .. cfg.name, default = false, type = "boolean"})
end
add_configs("no_4c", {description = "Build hpsocket without C interface", default = true, type = "boolean"})
add_configs("unicode", {description = "Build hpsocket with unicode character set", default = false, type = "boolean"})
on_load(function (package)
for _, cfg in ipairs(configs) do
local cfg_name = "no_" .. cfg.name
if not package:config(cfg_name) then
if cfg.package ~= "" then
package:add("deps", cfg.package, package:is_plat("windows") and {} or {configs = {cxflags = "-fpic"}})
end
else
package:add("defines", "_" .. string.upper(cfg.name) .. "_DISABLED")
end
end
if package:is_plat("windows") then
package:add("defines", "HPSOCKET_STATIC_LIB")
if not package:config("shared") then
package:add("defines", "HPSOCKET_STATIC_LIB")
end
package:add("syslinks", "ws2_32", "user32", "kernel32")
if not package:config("no_ssl") then
package:add("syslinks", "crypt32")
end
elseif package:is_plat("linux") then
package:add("syslinks", "pthread", "dl", "rt")
elseif package:is_plat("android") then
package:add("syslinks", "dl")
if not package:config("no_zlib") then
package:add("syslinks", "z")
end
end
package:add("links", package:config("no_4c") and "hpsocket" or "hpsocket4c")
if not package:config("shared") then
if not package:config("no_ssl") then
local prefix = is_plat("windows") and "lib" or ""
package:add("links", prefix .. "ssl", prefix .. "crypto")
end
if not package:config("no_iconv") then
if is_plat("android") then
package:add("links", "iconv", "charset")
end
end
if is_plat("linux") then
package:add("links", "jemalloc_pic")
end
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"
#pragma once
#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"
local config = {}
config.no_4c = package:config("no_4c")
config.unicode = package:config("unicode")
for _, cfg in ipairs(configs) do
local cfg_name = "no_" .. cfg.name
if package:config(cfg_name) then
config[cfg_name] = true
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
if package:config("shared") then
config.kind = "shared"
end
import("package.tools.xmake").install(package, config)
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)
]]}, {configs = {languages = "c++11"}, includes = package:config("no_4c") and "HPSocket.h" or "HPSocket4C.h"}))
end)
Loading…
Cancel
Save