xmake.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package("cryptopp")
  2. set_homepage("https://cryptopp.com/")
  3. set_description("free C++ class library of cryptographic schemes")
  4. add_urls("https://github.com/weidai11/cryptopp.git")
  5. add_urls("https://github.com/weidai11/cryptopp/archive/refs/tags/CRYPTOPP_$(version).tar.gz", {version = function (version) return version:gsub("%.", "_") end})
  6. add_versions("8.9.0", "ab5174b9b5c6236588e15a1aa1aaecb6658cdbe09501c7981ac8db276a24d9ab")
  7. add_versions("8.7.0", "8d6a4064b8e9f34cd3e838f5a12c40067ee7b95ee37d9173ec273cb0913e7ca2")
  8. add_versions("8.6.0", "9304625f4767a13e0a5f26d0f019d78cf9375604a33e5391c3bf2e81399dfeb8")
  9. add_versions("8.5.0", "8f64cf09cf4f61d5d74bca53574b8cc9959186cc0f072a2e6597e4999d6ad5db")
  10. add_versions("8.4.0", "6687dfc1e33b084aeab48c35a8550b239ee5f73a099a3b6a0918d70b8a89e654")
  11. add_resources("8.9.0", "cryptopp_cmake", "https://github.com/abdes/cryptopp-cmake/archive/CRYPTOPP_8_9_0.tar.gz", "191d69061c56602de1610ebf03b44dcf75636006e7e60ef8105bee6472ec0caf")
  12. add_resources("8.7.0", "cryptopp_cmake", "https://github.com/abdes/cryptopp-cmake/archive/CRYPTOPP_8_7_0_1.tar.gz", "49800456bec6432eff4a798d37f6c7760b887adc9f8928e66f44bcb8bf81f157")
  13. add_resources("8.6.0", "cryptopp_cmake", "https://github.com/noloader/cryptopp-cmake/archive/CRYPTOPP_8_6_0.tar.gz", "970b20d55dbf9d6335485e72c9f8967d878bf64bbd3de6aa28436beb6799c493")
  14. add_resources("8.5.0", "cryptopp_cmake", "https://github.com/noloader/cryptopp-cmake/archive/CRYPTOPP_8_5_0.tar.gz", "10685209405e676993873fcf638ade5f8f99d7949afa6b2045289ce9cc6d90ac")
  15. add_resources("8.4.0", "cryptopp_cmake", "https://github.com/noloader/cryptopp-cmake/archive/CRYPTOPP_8_4_0.tar.gz", "b850070141f6724fce640e4e2cfde433ec5b2d99d4386d29ba9255167bc4b4f0")
  16. if is_plat("mingw") and is_subhost("msys") then
  17. add_extsources("pacman::crypto++")
  18. elseif is_plat("linux") then
  19. add_extsources("pacman::crypto++", "apt::libcrypto++-dev")
  20. elseif is_plat("macosx") then
  21. add_extsources("brew::cryptopp")
  22. end
  23. if is_plat("linux", "bsd") then
  24. add_syslinks("pthread")
  25. end
  26. add_deps("cmake")
  27. on_install(function (package)
  28. if package:is_plat("windows") and package:config("shared") then
  29. package:add("defines", "CRYPTOPP_IMPORTS")
  30. end
  31. local cryptopp_cmake = package:resourcedir("cryptopp_cmake")
  32. os.cp(path.join(cryptopp_cmake, "*", "CMakeLists.txt"), ".")
  33. if package:version() and package:version():le("8.6") then
  34. os.cp(path.join(cryptopp_cmake, "*", "cryptopp-config.cmake"), ".")
  35. else
  36. os.cp(path.join(cryptopp_cmake, "*", "CMakePresets.json"), ".")
  37. os.cp(path.join(cryptopp_cmake, "*", "cmake"), ".")
  38. os.cp(path.join(cryptopp_cmake, "*", "cryptopp"), ".")
  39. os.cp(path.join(cryptopp_cmake, "*", "test"), ".")
  40. end
  41. -- fix unresolved external symbol PadLastBlock
  42. -- @see https://github.com/weidai11/cryptopp/issues/358
  43. io.replace("iterhash.h", "CRYPTOPP_NO_VTABLE", "CRYPTOPP_DLL CRYPTOPP_NO_VTABLE", {plain = true})
  44. io.replace("cryptopp/CMakeLists.txt", "set(CMAKE_CXX_VISIBILITY_PRESET hidden)", "", {plain = true})
  45. io.replace("cryptopp/CMakeLists.txt", "set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)", "", {plain = true})
  46. io.replace("cryptopp/CMakeLists.txt", "set(CMAKE_POSITION_INDEPENDENT_CODE 1)", "", {plain = true})
  47. io.replace("cryptopp/CMakeLists.txt", [[target_compile_definitions(cryptopp PRIVATE "CRYPTOPP_EXPORTS")]], "", {plain = true})
  48. io.replace("cryptopp/CMakeLists.txt",
  49. "set(BUILD_SHARED_LIBS ${CRYPTOPP_BUILD_SHARED})",
  50. format("set(CRYPTOPP_BUILD_SHARED %s)", package:config("shared") and "ON" or "OFF"), {plain = true})
  51. local configs = {
  52. -- Disable auto fetch source code
  53. "-DCRYPTOPP_SOURCES=" .. path.unix(os.curdir()),
  54. "-DBUILD_TESTING=OFF",
  55. "-DCRYPTOPP_BUILD_TESTING=OFF",
  56. }
  57. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  58. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  59. table.insert(configs, "-DBUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  60. table.insert(configs, "-DBUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  61. if package:is_plat("windows") and package:is_arch("arm", "arm64") then
  62. table.insert(configs, "-DDISABLE_ASM=ON")
  63. table.insert(configs, "-DDISABLE_SSSE3=ON")
  64. table.insert(configs, "-DDISABLE_SSE4=ON")
  65. table.insert(configs, "-DDISABLE_AESNI=ON")
  66. table.insert(configs, "-DDISABLE_CLMUL=ON")
  67. table.insert(configs, "-DDISABLE_SHA=ON")
  68. table.insert(configs, "-DDISABLE_AVX=ON")
  69. table.insert(configs, "-DDISABLE_AVX2=ON")
  70. end
  71. local cxflags
  72. if package:is_plat("windows") and package:config("shared") then
  73. cxflags = "-DCRYPTOPP_EXPORTS"
  74. end
  75. import("package.tools.cmake").install(package, configs, {cxflags = cxflags})
  76. end)
  77. on_test(function (package)
  78. assert(package:check_cxxsnippets({test = [[
  79. #include <cryptopp/cryptlib.h>
  80. #include <cryptopp/aes.h>
  81. #include <cryptopp/modes.h>
  82. using namespace CryptoPP;
  83. void test() {
  84. unsigned char key[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08, 0x01,0x02, 0x03,0x04,0x05,0x06,0x07,0x08};
  85. unsigned char iv[] = {0x01,0x02,0x03,0x03,0x03,0x03,0x03,0x03, 0x03,0x03, 0x01,0x02,0x03,0x03,0x03,0x03};
  86. CTR_Mode<AES>::Encryption Encryptor2(key, 16, iv);
  87. }
  88. ]]}, {configs = {languages = "c++11"}}))
  89. end)