xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package("libdispatch")
  2. set_homepage("swift.org")
  3. set_description("The libdispatch Project, (a.k.a. Grand Central Dispatch), for concurrency on multicore hardware")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/swiftlang/swift-corelibs-libdispatch/archive/refs/tags/swift-$(version)-RELEASE.tar.gz")
  6. add_urls("https://github.com/swiftlang/swift-corelibs-libdispatch.git", {alias = "git"})
  7. add_versions("6.1.1", "6fc6f8b1767a1348e1d960647b2bfbc52fd7074b7aeab97bd0f4b21af58baa47")
  8. add_versions("git:6.1.1", "swift-6.1.1-RELEASE")
  9. add_links("dispatch", "BlocksRuntime")
  10. if is_plat("windows", "mingw") then
  11. add_syslinks("shlwapi", "ws2_32", "winmm", "synchronization")
  12. elseif is_plat("linux", "bsd") then
  13. add_syslinks("pthread", "rt")
  14. end
  15. add_deps("cmake")
  16. on_check(function (package)
  17. if package:is_plat("windows") then
  18. if not package:has_tool("cxx", "clang_cl") then
  19. raise("package(libdispatch) unsupported msvc && clang toolchain, you can use clang-cl toolchain\nadd_requires(\"libdispatch\", {configs = {toolchains = \"clang-cl\"}}))")
  20. end
  21. else
  22. if not package:has_tool("cxx", "clang", "clangxx") then
  23. raise("package(libdispatch) unsupported gcc toolchain, you can use clang toolchain\nadd_requires(\"libdispatch\", {configs = {toolchains = \"clang\"}}))")
  24. end
  25. end
  26. if package:is_plat("android") then
  27. local ndk = package:toolchain("ndk"):config("ndkver")
  28. assert(ndk and tonumber(ndk) > 22, "package(libdispatch) require ndk version > 22")
  29. end
  30. end)
  31. on_install("!bsd and !macosx and !iphoneos", function (package)
  32. if not package:config("shared") then
  33. package:add("defines", "dispatch_STATIC")
  34. if not package:is_plat("macosx") then
  35. package:add("defines", "BlocksRuntime_STATIC")
  36. end
  37. end
  38. io.replace("CMakeLists.txt", "set(CMAKE_POSITION_INDEPENDENT_CODE YES)", "", {plain = true})
  39. io.replace("cmake/modules/DispatchCompilerWarnings.cmake", "-Werror", "", {plain = true})
  40. if package:is_plat("macosx") then
  41. io.replace("src/CMakeLists.txt", "BlocksRuntime::BlocksRuntime", "", {plain = true})
  42. end
  43. local configs = {"-DBUILD_TESTING=OFF"}
  44. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  45. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  46. import("package.tools.cmake").install(package, configs)
  47. end)
  48. on_test(function (package)
  49. assert(package:has_cfuncs("dispatch_get_main_queue", {includes = "dispatch/dispatch.h"}))
  50. end)