xmake.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package("concurrentqueue")
  2. set_homepage("https://github.com/cameron314/concurrentqueue")
  3. set_description("A fast multi-producer, multi-consumer lock-free concurrent queue for C++11")
  4. set_license("BSD")
  5. add_urls("https://github.com/cameron314/concurrentqueue/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/cameron314/concurrentqueue.git")
  7. add_versions("v1.0.4", "87fbc9884d60d0d4bf3462c18f4c0ee0a9311d0519341cac7cbd361c885e5281")
  8. add_configs("c_api", {description = "Build C API", default = false, type = "boolean"})
  9. add_deps("cmake")
  10. add_includedirs("include", "include/concurrentqueue/moodycamel")
  11. on_load(function (package)
  12. if not package:config("c_api") then
  13. package:set("kind", "library", {headeronly = true})
  14. end
  15. end)
  16. on_install(function (package)
  17. local configs = {}
  18. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  19. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  20. import("package.tools.cmake").install(package, configs)
  21. io.writefile(path.join(package:installdir("include"), "concurrentqueue", "concurrentqueue.h"), [[
  22. #pragma once
  23. #pragma message please update include <concurrentqueue/concurrentqueue.h> to <concurrentqueue.h>
  24. #include "moodycamel/concurrentqueue.h"
  25. ]])
  26. if package:config("c_api") then
  27. io.writefile("xmake.lua", [[
  28. add_rules("mode.debug", "mode.release")
  29. target("concurrentqueue-c")
  30. set_kind("$(kind)")
  31. add_files("c_api/*.cpp")
  32. add_headerfiles("(c_api/concurrentqueue.h)")
  33. if is_plat("windows") and is_kind("shared") then
  34. add_defines("DLL_EXPORT")
  35. end
  36. ]])
  37. import("package.tools.xmake").install(package)
  38. if package:is_plat("windows") and (not package:config("shared")) then
  39. package:add("defines", "MOODYCAMEL_STATIC")
  40. end
  41. end
  42. end)
  43. on_test(function (package)
  44. assert(package:check_cxxsnippets({test = [[
  45. #include <concurrentqueue.h>
  46. void test() {
  47. moodycamel::ConcurrentQueue<int> q;
  48. q.enqueue(25);
  49. }
  50. ]]}, {configs = {languages = "c++11"}}))
  51. if package:config("c_api") then
  52. assert(package:has_cfuncs("moodycamel_cq_create", {includes = "c_api/concurrentqueue.h"}))
  53. end
  54. end)