xmake.lua 6.9 KB

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