xmake.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. local dep_packages = {}
  2. local options = {{name = "udp", package = "kcp"},
  3. {name = "http", package = "http_parser"},
  4. {name = "zlib", package = is_plat("android", "windows") and "" or "zlib"},
  5. {name = "brotli", package = "brotli"},
  6. {name = "ssl", package = ""},
  7. {name = "iconv", package = ""}}
  8. local winCommonSrcPath = (get_config("hpversion") == "v5.7.3") and "Windows/Common/Src/" or "Windows/Src/Common/"
  9. local winBuiltinDependentLibPath = (get_config("hpversion") == "v5.7.3") and "Windows/Common/Lib/" or "Windows/Dependent/"
  10. for _, opt in ipairs(options) do
  11. local opt_name = "no_" .. opt.name
  12. option(opt_name)
  13. set_default(false)
  14. set_showmenu(true)
  15. set_category("option")
  16. set_description("Build hpsocket without " .. opt.name)
  17. add_defines("_" .. string.upper(opt.name) .. "_DISABLED")
  18. option_end()
  19. if not has_config(opt_name) and opt.package ~= "" then
  20. add_requires(opt.package, is_plat("windows") and {} or {configs = {cxflags = "-fpic"}})
  21. table.insert(dep_packages, opt.package)
  22. end
  23. end
  24. option("no_4c")
  25. set_default(false)
  26. set_showmenu(true)
  27. set_category("option")
  28. set_description("Build hpsocket without C interface")
  29. option_end()
  30. option("unicode")
  31. set_default(false)
  32. set_showmenu(true)
  33. set_category("option")
  34. set_description("Build hpsocket with unicode character set")
  35. option_end()
  36. option("hpversion")
  37. set_default("v5.9.1")
  38. set_showmenu(true)
  39. set_category("option")
  40. set_description("The version of HP-Socket")
  41. option_end()
  42. add_rules("mode.debug", "mode.release")
  43. target("hpsocket")
  44. before_build(function (target)
  45. if is_plat("windows") then
  46. io.writefile("stdafx.h", [[
  47. #pragma once
  48. #include "]] .. winCommonSrcPath .. [[GeneralHelper.h"
  49. ]])
  50. io.writefile("stdafx.cpp", [[
  51. #include "stdafx.h"
  52. ]])
  53. end
  54. end)
  55. set_kind("$(kind)")
  56. for _, opt in ipairs(options) do
  57. add_options("no_" .. opt.name)
  58. end
  59. for _, pkg in ipairs(dep_packages) do
  60. add_packages(pkg)
  61. end
  62. local exclude_file
  63. local install_files = {}
  64. local no_4c = has_config("no_4c")
  65. set_basename(no_4c and "hpsocket" or "hpsocket4c")
  66. exclude_file = no_4c and "HPSocket4C.*|HPSocket4C-SSL.*" or "HPSocket.*|HPSocket-SSL.*"
  67. if is_plat("windows") then
  68. add_syslinks("ws2_32", "user32", "kernel32")
  69. if not has_config("no_ssl") then
  70. add_syslinks("crypt32")
  71. end
  72. elseif is_plat("linux") then
  73. add_syslinks("pthread", "dl", "rt")
  74. elseif is_plat("android") then
  75. add_syslinks("dl")
  76. if not has_config("no_zlib") then
  77. add_syslinks("z")
  78. end
  79. end
  80. if is_plat("windows") then
  81. if has_config("unicode") then
  82. add_defines("UNICODE", "_UNICODE")
  83. end
  84. set_pcxxheader("stdafx.h")
  85. add_files("stdafx.cpp")
  86. add_files(path.join(winCommonSrcPath, "http/*.c"))
  87. add_files(path.join(winCommonSrcPath, "*.cpp"))
  88. add_files("Windows/Src/*.cpp|" .. exclude_file)
  89. add_headerfiles("Windows/Include/HPSocket/*.h|" .. exclude_file)
  90. add_defines(is_kind("shared") and "HPSOCKET_EXPORTS" or "HPSOCKET_STATIC_LIB")
  91. local vs = get_config("vs")
  92. local vs_ver = "10.0"
  93. if vs == "2015" then vs_ver = "14.0"
  94. elseif vs == "2017" then vs_ver = "15.0"
  95. elseif vs == "2019" then vs_ver = "16.0"
  96. elseif vs == "2022" then vs_ver = "17.0"
  97. end
  98. if get_config("hpversion") == "v5.9.1" then
  99. vs_ver = (vs == "2015" and "100" or "14x")
  100. end
  101. add_includedirs(".")
  102. add_includedirs(path.join(winBuiltinDependentLibPath, "openssl", vs_ver, "$(arch)", "include"))
  103. ssllinkdir = path.join(winBuiltinDependentLibPath, "openssl", vs_ver, "$(arch)", "lib")
  104. add_linkdirs(ssllinkdir)
  105. add_includedirs(path.join(winBuiltinDependentLibPath, "zlib", vs_ver, "$(arch)", "include"))
  106. zliblinkdir = path.join(winBuiltinDependentLibPath, "zlib", vs_ver, "$(arch)", "lib")
  107. add_linkdirs(zliblinkdir)
  108. if not has_config("no_ssl") then
  109. add_links("libssl", "libcrypto")
  110. if is_kind("static") then
  111. table.insert(install_files, path.join(ssllinkdir, "*.lib"))
  112. end
  113. end
  114. if not has_config("no_zlib") then
  115. add_links("zlib")
  116. if is_kind("static") then
  117. table.insert(install_files, path.join(zliblinkdir, "*.lib"))
  118. end
  119. end
  120. elseif is_plat("linux", "android") then
  121. add_cxflags("-fpic", {force = true})
  122. add_files("Linux/src/common/crypto/*.cpp")
  123. add_files("Linux/src/common/http/*.c")
  124. add_files("Linux/src/common/*.cpp")
  125. add_files("Linux/src/*.cpp|" .. exclude_file)
  126. add_headerfiles("Linux/include/hpsocket/*.h|" .. exclude_file)
  127. add_headerfiles("Linux/include/hpsocket/(common/*.h)")
  128. if is_plat("android") then
  129. add_includedirs("Linux/dependent/android-ndk/$(arch)/include")
  130. linkdir = "Linux/dependent/android-ndk/$(arch)/lib"
  131. add_linkdirs(linkdir)
  132. if not has_config("no_iconv") then
  133. add_links("charset", "iconv")
  134. if is_kind("static") then
  135. table.insert(install_files, path.join(linkdir, "libcharset.a"))
  136. table.insert(install_files, path.join(linkdir, "libiconv.a"))
  137. end
  138. end
  139. else
  140. local arch = is_arch("x86_64") and "x64" or "x86"
  141. add_includedirs(path.join("Linux/dependent", arch, "include"))
  142. linkdir = path.join("Linux/dependent", arch, "lib")
  143. add_linkdirs(linkdir)
  144. add_links("jemalloc_pic")
  145. if is_kind("static") then
  146. table.insert(install_files, path.join(linkdir, "libjemalloc_pic.a"))
  147. end
  148. end
  149. if not has_config("no_ssl") then
  150. add_links("ssl", "crypto")
  151. if is_kind("static") then
  152. table.insert(install_files, path.join(linkdir, "libssl.a"))
  153. table.insert(install_files, path.join(linkdir, "libcrypto.a"))
  154. end
  155. end
  156. end
  157. for _, file in ipairs(install_files) do
  158. add_installfiles(file, {prefixdir = "lib"})
  159. end