xmake.lua 6.8 KB

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