xmake.lua 6.5 KB

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