xmake.lua 6.9 KB

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