xmake.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package("google-cloud-cpp")
  2. set_homepage("https://github.com/googleapis/google-cloud-cpp")
  3. set_description("C++ Client Libraries for Google Cloud Services")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/googleapis/google-cloud-cpp/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/googleapis/google-cloud-cpp.git")
  7. add_versions("v2.37.0", "10867580483cb338e7d50920c2383698f3572cc6b4c7d072e38d5f43755cbd80")
  8. add_versions("v2.36.0", "9a6e182fd658ba114512cf21bd9f274a315830638f62f0b831113df9e674bea0")
  9. add_versions("v2.34.0", "22deeb6c2abf0838f4d4c6100e83489bb581fa8015180370500ad31712f601ac")
  10. add_versions("v2.33.0", "e53ba3799c052d97acac9a6a6b27af24ce822dbde7bfde973bac9e5da714e6b2")
  11. add_configs("libraries", {description = "Enable subset of the libraries (default: google_cloud_cpp_common)", default = {}, type = "table"})
  12. add_configs("exceptions", {description = "Enable exceptions", default = true, type = "boolean"})
  13. if is_plat("linux", "bsd") then
  14. add_syslinks("pthread")
  15. end
  16. add_deps("cmake")
  17. on_check("mingw", function (package)
  18. -- https://github.com/googleapis/google-cloud-cpp/issues/14436
  19. if is_subhost("msys") then
  20. raise("Unsupported msys2 mingw64, see https://github.com/rui314/mold/issues/613#issuecomment-1214294138")
  21. end
  22. end)
  23. on_load(function (package)
  24. package:add("deps", "abseil")
  25. if not package:is_plat("windows", "mingw", "msys") then
  26. if package:is_plat("macosx") then
  27. package:add("deps", "openssl3", {system = false})
  28. else
  29. package:add("deps", "openssl3")
  30. end
  31. end
  32. -- https://github.com/googleapis/google-cloud-cpp/blob/main/cmake/GoogleCloudCppFeatures.cmake
  33. local libraries = package:config("libraries")
  34. if libraries and #libraries ~= 0 then
  35. import("core.base.hashset")
  36. local has_grpc = false
  37. local no_grpc_require = hashset.of("experimental-bigquery_rest", "mocks", "oauth2", "storage")
  38. local has_rest = false
  39. local rest_requires = hashset.of(
  40. "storage",
  41. "bigquerycontrol",
  42. "compute",
  43. "experimental",
  44. "gkeconnect",
  45. "oauth2",
  46. "opentelemetry",
  47. "sql",
  48. "universe_domain",
  49. "generator"
  50. )
  51. for _, lib in ipairs(libraries) do
  52. if not no_grpc_require:has(lib) then
  53. has_grpc = true
  54. end
  55. if rest_requires:has(lib) then
  56. has_rest = true
  57. end
  58. end
  59. if has_grpc then
  60. if package:config("shared") then
  61. package:add("deps", "grpc", {configs = {shared = true}})
  62. wprint([[Build google-cloud-cpp shared library require protobuf shared too, Please use `add_requireconfs("**.protobuf-cpp", {configs = {shared = true}})`]])
  63. else
  64. package:add("deps", "grpc")
  65. end
  66. if package:is_cross() then
  67. package:add("deps", "grpc~binary", {private = true, kind = "binary"})
  68. end
  69. -- commit hash from https://github.com/googleapis/google-cloud-cpp/blob/main/cmake/GoogleapisConfig.cmake
  70. package:add("resources", ">=2.33.0", "googleapis", "https://github.com/googleapis/googleapis.git", "c3556b45dc35a145e04b5692bc72e01a4f58a6b2")
  71. end
  72. if has_rest then
  73. package:add("deps", "nlohmann_json", {configs = {cmake = true}})
  74. package:add("deps", "libcurl", "crc32c")
  75. end
  76. local hash_libraries = hashset.from(libraries)
  77. package:data_set("hash_libraries", hash_libraries)
  78. if hash_libraries:has("opentelemetry") then
  79. package:add("deps", "opentelemetry-cpp")
  80. end
  81. end
  82. end)
  83. on_install(function (package)
  84. -- https://github.com/googleapis/google-cloud-cpp/blob/main/doc/packaging.md
  85. if package:dep("grpc") then
  86. local googleapis_dir = path.unix(package:resourcedir("googleapis"))
  87. io.replace("external/googleapis/CMakeLists.txt",
  88. [[set(EXTERNAL_GOOGLEAPIS_PREFIX "${PROJECT_BINARY_DIR}/external/googleapis")]],
  89. format([[set(EXTERNAL_GOOGLEAPIS_PREFIX "%s")]], googleapis_dir), {plain = true})
  90. end
  91. local configs = {
  92. "-DBUILD_TESTING=OFF",
  93. "-DGOOGLE_CLOUD_CPP_ENABLE_EXAMPLES=OFF",
  94. "-DGOOGLE_CLOUD_CPP_ENABLE_WERROR=OFF",
  95. "-DGOOGLE_CLOUD_CPP_WITH_MOCKS=OFF",
  96. "-DGOOGLE_CLOUD_CPP_ENABLE_MACOS_OPENSSL_CHECK=OFF",
  97. }
  98. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  99. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  100. table.insert(configs, "-DGOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS=" .. (package:config("exceptions") and "ON" or "OFF"))
  101. if package:is_plat("windows") and package:config("shared") then
  102. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  103. end
  104. local openssl = package:dep("openssl")
  105. if openssl then
  106. if not openssl:is_system() then
  107. table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
  108. end
  109. end
  110. local libraries = package:config("libraries")
  111. if libraries then
  112. table.insert(configs, "-DGOOGLE_CLOUD_CPP_ENABLE=" .. table.concat(libraries, ";"))
  113. end
  114. import("package.tools.cmake").install(package, configs)
  115. end)
  116. on_test(function (package)
  117. local languages = "c++" .. package:dep("abseil"):config("cxx_standard")
  118. assert(package:check_cxxsnippets({test = [[
  119. #include <google/cloud/version.h>
  120. void test() {
  121. auto version = google::cloud::version_string();
  122. }
  123. ]]}, {configs = {languages = languages}}))
  124. local hash_libraries = package:data("hash_libraries")
  125. if not hash_libraries then
  126. return
  127. end
  128. if hash_libraries:has("storage") then
  129. assert(package:check_cxxsnippets({test = [[
  130. #include <google/cloud/storage/client.h>
  131. void test() {
  132. auto client = google::cloud::storage::Client();
  133. }
  134. ]]}, {configs = {languages = languages}}))
  135. end
  136. end)