xmake.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package("libfido2")
  2. set_homepage("https://github.com/Yubico/libfido2")
  3. set_description("Provides library functionality for FIDO2, including communication with a device over USB or NFC.")
  4. set_license("BSD-2-Clause")
  5. add_urls("https://github.com/Yubico/libfido2/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/Yubico/libfido2.git")
  7. add_versions("1.15.0", "32e3e431cfe29b45f497300fdb7076971cb77fc584fcfa80084d823a6ed94fbb")
  8. add_patches("1.15.0", "patches/1.15.0/cmake-pkgconfig-find-deps.patch", "1d8c559529f8589e44f794b33d9216234d44ef857742db9ef94693dbd41c9486")
  9. add_patches("1.15.0", "patches/1.15.0/add-syslinks.patch", "1da25738d57afbb8c6b2a95796a9711d234a44903bc32e765377b2b455c340ee")
  10. add_configs("hidapi", {description = "Use hidapi", default = false, type = "boolean"})
  11. add_configs("pcsc", {description = "Enable experimental PCSC support", default = false, type = "boolean"})
  12. add_configs("windows_hello", {description = "Abstract Windows Hello as a FIDO device", default = false, type = "boolean"})
  13. add_configs("nfc", {description = "Enable NFC support on Linux", default = false, type = "boolean"})
  14. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  15. if is_plat("linux") then
  16. add_extsources("pacman::libfido2", "apt::libfido2-dev")
  17. elseif is_plat("macosx") then
  18. add_extsources("brew::libfido2")
  19. end
  20. if is_plat("windows", "mingw") then
  21. add_syslinks("setupapi", "hid", "bcrypt")
  22. elseif is_plat("macosx") then
  23. add_frameworks("CoreFoundation", "IOKit")
  24. end
  25. add_deps("cmake")
  26. if is_host("windows") then
  27. add_deps("pkgconf")
  28. else
  29. add_deps("pkg-config")
  30. end
  31. add_deps("openssl", "libcbor", "zlib")
  32. if is_plat("linux") then
  33. add_deps("libudev")
  34. end
  35. on_load(function(package)
  36. if package:config("hidapi") then
  37. package:add("deps", "hidapi")
  38. end
  39. if package:config("pcsc") then
  40. if package:is_plat("windows", "mingw") then
  41. package:add("syslinks", "winscard")
  42. elseif package:is_plat("macosx") then
  43. package:add("frameworks", "PCSC")
  44. end
  45. end
  46. end)
  47. on_install("windows", "linux", "macosx", "bsd", "mingw", "msys", function (package)
  48. io.replace("CMakeLists.txt", "-Werror", "", {plain = true})
  49. io.replace("CMakeLists.txt", "-WX", "", {plain = true})
  50. io.replace("CMakeLists.txt", "/sdl", "", {plain = true})
  51. local configs = {"-DBUILD_TESTS=OFF", "-DBUILD_EXAMPLES=OFF", "-DBUILD_MANPAGES=OFF"}
  52. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  53. if package:config("shared") then
  54. table.join2(configs, {"-DBUILD_SHARED_LIBS=ON", "-DBUILD_STATIC_LIBS=OFF"})
  55. else
  56. table.join2(configs, {"-DBUILD_SHARED_LIBS=OFF", "-DBUILD_STATIC_LIBS=ON"})
  57. end
  58. table.insert(configs, "-DUSE_HIDAPI=" .. (package:config("hidapi") and "ON" or "OFF"))
  59. table.insert(configs, "-DUSE_PCSC=" .. (package:config("pcsc") and "ON" or "OFF"))
  60. table.insert(configs, "-DUSE_WINHELLO=" .. (package:config("windows_hello") and "ON" or "OFF"))
  61. table.insert(configs, "-DNFC_LINUX=" .. (package:config("nfc") and "ON" or "OFF"))
  62. table.insert(configs, "-DBUILD_TOOLS=" .. (package:config("tools") and "ON" or "OFF"))
  63. local openssl = package:dep("openssl")
  64. if not openssl:is_system() then
  65. table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
  66. end
  67. local opt = {}
  68. if package:is_plat("windows") then
  69. os.mkdir(path.join(package:buildir(), "src", "pdb"))
  70. if package:config("shared") then
  71. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  72. end
  73. end
  74. import("package.tools.cmake").install(package, configs, opt)
  75. end)
  76. on_test(function (package)
  77. assert(package:has_cfuncs("fido_dev_new", {includes = "fido.h"}))
  78. end)