xmake.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.8.4")
  38. set_showmenu(true)
  39. set_values("v5.7.3", "v5.8.4")
  40. set_category("option")
  41. set_description("The version of HP-Socket")
  42. option_end()
  43. add_rules("mode.debug", "mode.release")
  44. target("hpsocket")
  45. before_build(function (target)
  46. if is_plat("windows") then
  47. io.writefile("stdafx.h", [[
  48. #pragma once
  49. #include "]] .. winCommonSrcPath .. [[GeneralHelper.h"
  50. ]])
  51. io.writefile("stdafx.cpp", [[
  52. #include "stdafx.h"
  53. ]])
  54. end
  55. end)
  56. set_kind("$(kind)")
  57. for _, opt in ipairs(options) do
  58. add_options("no_" .. opt.name)
  59. end
  60. for _, pkg in ipairs(dep_packages) do
  61. add_packages(pkg)
  62. end
  63. local exclude_file
  64. local install_files = {}
  65. local no_4c = has_config("no_4c")
  66. set_basename(no_4c and "hpsocket" or "hpsocket4c")
  67. exclude_file = no_4c and "HPSocket4C.*|HPSocket4C-SSL.*" or "HPSocket.*|HPSocket-SSL.*"
  68. if is_plat("windows") then
  69. add_syslinks("ws2_32", "user32", "kernel32")
  70. if not has_config("no_ssl") then
  71. add_syslinks("crypt32")
  72. end
  73. elseif is_plat("linux") then
  74. add_syslinks("pthread", "dl", "rt")
  75. elseif is_plat("android") then
  76. add_syslinks("dl")
  77. if not has_config("no_zlib") then
  78. add_syslinks("z")
  79. end
  80. end
  81. if is_plat("windows") then
  82. if has_config("unicode") then
  83. add_defines("UNICODE", "_UNICODE")
  84. end
  85. set_pcxxheader("stdafx.h")
  86. add_files("stdafx.cpp")
  87. add_files(path.join(winCommonSrcPath, "http/*.c"))
  88. add_files(path.join(winCommonSrcPath, "*.cpp"))
  89. add_files("Windows/Src/*.cpp|" .. exclude_file)
  90. add_headerfiles("Windows/Include/HPSocket/*.h|" .. exclude_file)
  91. add_defines(is_kind("shared") and "HPSOCKET_EXPORTS" or "HPSOCKET_STATIC_LIB")
  92. local vs = get_config("vs")
  93. local vs_ver = "10.0"
  94. if vs == "2015" then vs_ver = "14.0"
  95. elseif vs == "2017" then vs_ver = "15.0"
  96. elseif vs == "2019" then vs_ver = "16.0"
  97. end
  98. add_includedirs(".")
  99. add_includedirs(path.join(winBuiltinDependentLibPath, "openssl", vs_ver, "$(arch)", "include"))
  100. ssllinkdir = path.join(winBuiltinDependentLibPath, "openssl", vs_ver, "$(arch)", "lib")
  101. add_linkdirs(ssllinkdir)
  102. add_includedirs(path.join(winBuiltinDependentLibPath, "zlib", vs_ver, "$(arch)", "include"))
  103. zliblinkdir = path.join(winBuiltinDependentLibPath, "zlib", vs_ver, "$(arch)", "lib")
  104. add_linkdirs(zliblinkdir)
  105. if not has_config("no_ssl") then
  106. add_links("libssl", "libcrypto")
  107. if is_kind("static") then
  108. table.insert(install_files, path.join(ssllinkdir, "*.lib"))
  109. end
  110. end
  111. if not has_config("no_zlib") then
  112. add_links("zlib")
  113. if is_kind("static") then
  114. table.insert(install_files, path.join(zliblinkdir, "*.lib"))
  115. end
  116. end
  117. elseif is_plat("linux", "android") then
  118. add_cxflags("-fpic", {force = true})
  119. add_files("Linux/src/common/crypto/*.cpp")
  120. add_files("Linux/src/common/http/*.c")
  121. add_files("Linux/src/common/*.cpp")
  122. add_files("Linux/src/*.cpp|" .. exclude_file)
  123. add_headerfiles("Linux/include/hpsocket/*.h|" .. exclude_file)
  124. add_headerfiles("Linux/include/hpsocket/(common/*.h)")
  125. if is_plat("android") then
  126. add_includedirs("Linux/dependent/android-ndk/$(arch)/include")
  127. linkdir = "Linux/dependent/android-ndk/$(arch)/lib"
  128. add_linkdirs(linkdir)
  129. if not has_config("no_iconv") then
  130. add_links("charset", "iconv")
  131. if is_kind("static") then
  132. table.insert(install_files, path.join(linkdir, "libcharset.a"))
  133. table.insert(install_files, path.join(linkdir, "libiconv.a"))
  134. end
  135. end
  136. else
  137. local arch = is_arch("x86_64") and "x64" or "x86"
  138. add_includedirs(path.join("Linux/dependent", arch, "include"))
  139. linkdir = path.join("Linux/dependent", arch, "lib")
  140. add_linkdirs(linkdir)
  141. add_links("jemalloc_pic")
  142. if is_kind("static") then
  143. table.insert(install_files, path.join(linkdir, "libjemalloc_pic.a"))
  144. end
  145. end
  146. if not has_config("no_ssl") then
  147. add_links("ssl", "crypto")
  148. if is_kind("static") then
  149. table.insert(install_files, path.join(linkdir, "libssl.a"))
  150. table.insert(install_files, path.join(linkdir, "libcrypto.a"))
  151. end
  152. end
  153. end
  154. for _, file in ipairs(install_files) do
  155. add_installfiles(file, {prefixdir = "lib"})
  156. end