xmake.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package("botan")
  2. set_homepage("https://botan.randombit.net")
  3. set_description("Cryptography Toolkit")
  4. set_license("BSD-2-Clause")
  5. set_urls("https://github.com/randombit/botan/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/randombit/botan.git")
  7. add_versions("3.5.0", "7d91d3349e6029e1a6929a50ab587f9fd4e29a9af3f3d698553451365564001f")
  8. add_versions("3.4.0", "6ef2a16a0527b1cfc9648a644877f7b95c4d07e8ef237273b030c623418c5e5b")
  9. add_configs("tools", {description = "Build tools.", default = false, type = "boolean"})
  10. add_configs("python", {description = "Enable python module", default = false, type = "boolean"})
  11. add_configs("endian", {description = [[The parameter should be either “little” or “big”. If not used then if the target architecture has a default, that is used. Otherwise left unspecified, which causes less optimal codepaths to be used but will work on either little or big endian.]], default = nil, type = "string", values = {"little", "big"}})
  12. add_configs("modules", {description = [[Enable modules, example: {configs = {modules = {"zlib", "lzma"}}}]], type = "table"})
  13. if is_plat("wasm") then
  14. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  15. end
  16. add_deps("python 3.x", "ninja", {kind = "binary"})
  17. if is_plat("mingw") and is_subhost("msys") then
  18. add_extsources("pacman::libbotan")
  19. elseif is_plat("linux") then
  20. add_extsources("pacman::botan", "apt::libbotan-2-dev")
  21. elseif is_plat("macosx") then
  22. add_extsources("brew::botan")
  23. end
  24. if is_plat("linux", "bsd") then
  25. add_syslinks("pthread")
  26. end
  27. if on_check then
  28. on_check("windows", function (package)
  29. import("core.tool.toolchain")
  30. local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()})
  31. if msvc then
  32. local vs = msvc:config("vs")
  33. assert(vs and tonumber(vs) >= 2022, "package(botan): current version need vs >= 2022")
  34. end
  35. end)
  36. end
  37. on_load(function (package)
  38. import("core.base.hashset")
  39. local major = "3"
  40. if package:version() then
  41. major = package:version():major()
  42. end
  43. package:add("includedirs", "include/botan-" .. major)
  44. local modules = package:config("modules")
  45. if modules then
  46. local deps = hashset.from(modules)
  47. if deps then
  48. for _, dep in ipairs({"boost", "bzip2", "lzma", "sqlite3", "zlib"}) do
  49. if deps:has(dep) then
  50. if dep == "boost" then
  51. package:add("deps", "boost", {configs = {filesystem = true}})
  52. elseif dep == "lzma" then
  53. package:add("deps", "xz")
  54. else
  55. package:add("deps", dep)
  56. end
  57. end
  58. end
  59. end
  60. end
  61. end)
  62. on_install("windows", "linux", "macosx|native", "bsd", "mingw@windows", "msys", "wasm", function (package)
  63. -- https://botan.randombit.net/handbook/building.html
  64. local configs = {
  65. "configure.py",
  66. "--prefix=" .. package:installdir(),
  67. "--build-tool=ninja",
  68. "--without-documentation",
  69. "--minimized-build",
  70. }
  71. local cc
  72. local envs
  73. if package:is_plat("windows") then
  74. local msvc = package:toolchain("msvc")
  75. assert(msvc:check(), "vs not found!")
  76. local vs = msvc:config("vs")
  77. if tonumber(vs) < 2019 then
  78. raise("This version of Botan requires at least msvc 19.30")
  79. end
  80. envs = msvc:runenvs()
  81. table.insert(configs, "--msvc-runtime=" .. package:runtimes())
  82. if package:has_tool("cxx", "cl") then
  83. cc = "msvc"
  84. elseif package:has_tool("cxx", "clang_cl") then
  85. raise("Unsupported toolchains on windows")
  86. end
  87. else
  88. local cxx = package:build_getenv("cxx")
  89. if cxx:find("clang", 1, true) then
  90. cc = "clang"
  91. elseif cxx:find("gcc", 1, true) then
  92. cc = "gcc"
  93. end
  94. local cc_bin
  95. if package:is_plat("mingw") then
  96. cc = "gcc"
  97. cc_bin = cxx
  98. elseif package:is_plat("wasm") then
  99. cc = "emcc"
  100. cc_bin = cxx
  101. end
  102. end
  103. if cc then
  104. table.insert(configs, "--cc=" .. cc)
  105. end
  106. if cc_bin then
  107. table.insert(configs, "--cc-bin=" .. cc_bin)
  108. end
  109. if package:is_plat("wasm") then
  110. table.insert(configs, "--os=emscripten")
  111. table.insert(configs, "--cpu=wasm")
  112. else
  113. if package:is_plat("iphoneos") then
  114. table.insert(configs, "--os=ios")
  115. elseif not package:is_plat("bsd") then
  116. -- let configure.py detech bsd host name
  117. table.insert(configs, "--os=" .. package:plat())
  118. end
  119. table.insert(configs, "--cpu=" .. package:arch())
  120. end
  121. if package:is_debug() then
  122. table.insert(configs, "--debug-mode")
  123. end
  124. local targets = (package:config("shared") and "shared" or "static")
  125. if package:config("tools") then
  126. targets = targets .. ",cli"
  127. end
  128. table.insert(configs, "--build-targets=" .. targets)
  129. local modules = package:config("modules")
  130. if modules then
  131. table.insert(configs, "--enable-modules=" .. table.concat(modules, ","))
  132. end
  133. if not package:config("python") then
  134. table.insert(configs, "--no-install-python-module")
  135. end
  136. if package:config("endian") then
  137. table.insert(configs, "--with-endian=" .. package:config("endian"))
  138. end
  139. local cxflags = {}
  140. table.join2(cxflags, table.wrap(package:config("cxflags")))
  141. table.join2(cxflags, table.wrap(package:config("cxxflags")))
  142. for _, flag in ipairs(cxflags) do
  143. table.insert(configs, "--extra-cxxflags=" .. flag)
  144. end
  145. for _, dep in ipairs({"boost", "bzip2", "xz", "sqlite3", "zlib"}) do
  146. local packagedep = package:dep(dep)
  147. if packagedep then
  148. local fetchinfo = packagedep:fetch()
  149. if fetchinfo then
  150. for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  151. table.insert(configs, "--with-external-includedir=" .. includedir)
  152. end
  153. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  154. table.insert(configs, "--with-external-libdir=" .. linkdir)
  155. end
  156. end
  157. end
  158. end
  159. os.vrunv("python3", configs, {envs = envs})
  160. import("package.tools.ninja").install(package, {}, {envs = envs})
  161. end)
  162. on_test(function (package)
  163. assert(package:check_cxxsnippets({test = [[
  164. #include <botan/hex.h>
  165. void test() {
  166. std::vector<uint8_t> key = Botan::hex_decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
  167. }
  168. ]]}, {configs = {languages = "c++20"}}))
  169. if not package:is_cross() and package:config("tools") then
  170. os.vrun("botan-cli version")
  171. end
  172. end)