|
@@ -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
|