xmake.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package("tinycbor")
  2. set_homepage("https://github.com/intel/tinycbor")
  3. set_description("Concise Binary Object Representation (CBOR) Library")
  4. set_license("MIT")
  5. add_urls("https://github.com/intel/tinycbor/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/intel/tinycbor.git")
  7. add_versions("v0.6.1", "0f9944496d1143935e9c996bc6233ca0dd5451299def33ef400a409942f8f34b")
  8. add_versions("v0.6.0", "512e2c9fce74f60ef9ed3af59161e905f9e19f30a52e433fc55f39f4c70d27e4")
  9. add_configs("float", {description = "Enable floating point data type.", default = true, type = "boolean"})
  10. add_configs("cmake", {description = "Use cmake build system", default = false, type = "boolean"})
  11. on_load(function (package)
  12. if (package:gitref() or package:version():gt("0.6.1")) and package:config("cmake") then
  13. package:add("deps", "cmake")
  14. if not package:config("shared") then
  15. package:add("defines", "CBOR_STATIC_DEFINE")
  16. end
  17. end
  18. if package:is_plat("mingw") and package:is_arch("i386") then
  19. -- Only work with gcc >= 14
  20. package:config_set("float", false)
  21. wprint("package(tinycbor) disable config(float) on mingw/i386")
  22. end
  23. end)
  24. on_install(function (package)
  25. local configs = {}
  26. if package:config("cmake") then
  27. io.replace("CMakeLists.txt", "add_subdirectory(tests)", "", {plain = true})
  28. io.replace("CMakeLists.txt", "include(PackageConfig)", "", {plain = true})
  29. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  30. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  31. import("package.tools.cmake").install(package, configs)
  32. else
  33. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  34. import("package.tools.xmake").install(package, {enable_float = package:config("float")})
  35. if package:is_plat("windows") and package:config("shared") then
  36. io.replace(path.join(package:installdir("include"), "cbor.h"), "define CBOR_API", "define CBOR_API __declspec(dllimport)", {plain = true})
  37. end
  38. end
  39. end)
  40. on_test(function (package)
  41. assert(package:has_cfuncs("cbor_encoder_init", {includes = "cbor.h"}))
  42. end)