xmake.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package("libsolv")
  2. set_homepage("https://github.com/openSUSE/libsolv")
  3. set_description("Library for solving packages and reading repositories.")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/openSUSE/libsolv/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/openSUSE/libsolv.git")
  7. add_versions("0.7.35", "e6ef552846f908beb3bbf6ca718b6dd431bd8a281086d82af9a6d2a3ba919be5")
  8. add_versions("0.7.34", "fd9c8a75d3ca09d9ff7b0d160902fac789b3ce6f9fb5b46a7647895f9d3eaf05")
  9. add_patches("<=0.7.34", "patches/fix-msvc-c2036.patch", "a924517033d4f8ba18e922e892953834d3ca1a4fa5a69ae04fd308df40d1b2e8")
  10. add_patches("<=0.7.34", "patches/fix-compile-on-mingw-w64.patch", "e6ba565110c918363a4499a4fc949f29777e0a189f192c231c81a47da821d21d")
  11. -- when using mingw, cmake cannot force export of all symbols.
  12. if is_plat("mingw", "msys", "cygwin") then
  13. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  14. end
  15. add_configs("tools", {description = "Build tools.", default = false, type = "boolean"})
  16. -- needs rpm, rpmdb, rpmio, rpmmisc, db
  17. add_configs("rpmdb", {description = "Build with rpm database support.", default = false, type = "boolean"})
  18. add_configs("rpmdb_librpm", {description = "Use librpm to access the rpm database.", default = false, type = "boolean"})
  19. add_configs("rpmdb_bdb", {description = "Use BerkeleyDB to access the rpm database.", default = false, type = "boolean"})
  20. add_configs("rpmdb_byrpmheader", {description = "Build with rpmdb Header support.", default = false, type = "boolean"})
  21. add_configs("rpmpkg", {description = "Build with rpm package support.", default = false, type = "boolean"})
  22. add_configs("rpmpkg_librpm", {description = "Use librpm to access rpm header information.", default = false, type = "boolean"})
  23. add_configs("pubkey", {description = "Build with pubkey support.", default = false, type = "boolean"})
  24. add_configs("rpmmd", {description = "Build with rpmmd repository support.", default = false, type = "boolean"})
  25. add_configs("rpm5", {description = "Enabling RPM 5 support.", default = false, type = "boolean"})
  26. add_configs("suserepo", {description = "Build with suse repository support.", default = false, type = "boolean"})
  27. add_configs("comps", {description = "Build with fedora comps support.", default = false, type = "boolean"})
  28. add_configs("helixrepo", {description = "Build with helix repository support.", default = false, type = "boolean"})
  29. add_configs("debian", {description = "Build with debian package/repository support.", default = false, type = "boolean"})
  30. add_configs("mdkrepo", {description = "Build with mandriva/mageia repository support.", default = false, type = "boolean"})
  31. add_configs("archrepo", {description = "Build with archlinux repository support.", default = false, type = "boolean"})
  32. add_configs("apk", {description = "Build with apk package/repository support.", default = false, type = "boolean"})
  33. add_configs("cudfrepo", {description = "Build with cudf repository support.", default = false, type = "boolean"})
  34. add_configs("haiku", {description = "Build with Haiku package support.", default = false, type = "boolean"})
  35. add_configs("conda", {description = "Build with conda dependency support.", default = false, type = "boolean"})
  36. add_configs("appdata", {description = "Build with AppStream appdata support.", default = false, type = "boolean"})
  37. add_configs("multi_semantics", {description = "Build with support for multiple distribution types.", default = false, type = "boolean"})
  38. add_configs("lzma_compression", {description = "Build with lzma/xz compression support.", default = false, type = "boolean"})
  39. add_configs("bzip2_compression", {description = "Build with bzip2 compression support.", default = false, type = "boolean"})
  40. add_configs("zstd_compression", {description = "Build with zstd compression support.", default = false, type = "boolean"})
  41. add_configs("zchunk_compression", {description = "Build with zchunk compression support.", default = false, type = "boolean"})
  42. add_configs("libxml2", {description = "Build with libxml2 instead of libexpat.", default = false, type = "boolean"})
  43. if not is_plat("windows", "mingw", "msys", "cygwin") then
  44. add_configs("cookieopen", {description = "Enable the use of stdio cookie opens.", default = true, type = "boolean"})
  45. else
  46. add_configs("cookieopen", {description = "Enable the use of stdio cookie opens.", default = false, type = "boolean", readonly = true})
  47. end
  48. add_configs("FEDORA", {description = "Building for Fedora.", default = false, type = "boolean"})
  49. add_configs("DEBIAN", {description = "Building for Debian.", default = false, type = "boolean"})
  50. add_configs("SUSE", {description = "Building for SUSE.", default = false, type = "boolean"})
  51. add_configs("ARCHLINUX", {description = "Building for Archlinux.", default = false, type = "boolean"})
  52. add_configs("MANDRIVA", {description = "Building for Mandriva.", default = false, type = "boolean"})
  53. add_configs("MAGEIA", {description = "Building for Mageia.", default = false, type = "boolean"})
  54. add_configs("HAIKU", {description = "Building for Haiku.", default = false, type = "boolean"}) -- needs haiku be, network, package.
  55. add_deps("cmake")
  56. if not is_subhost("windows") then
  57. add_deps("pkg-config")
  58. else
  59. add_deps("pkgconf")
  60. end
  61. on_load(function (package)
  62. local libxml2_or_expat_enabled = false
  63. if package:config("ARCHLINUX") then
  64. package:config_set("archrepo", true)
  65. end
  66. if package:config("MANDRIVA") then
  67. package:config_set("mdkrepo", true)
  68. end
  69. if package:config("MAGEIA") then
  70. package:config_set("mdkrepo", true)
  71. package:config_set("lzma_compression", true)
  72. end
  73. if package:config("DEBIAN") then
  74. package:config_set("debian", true)
  75. end
  76. if package:config("SUSE") then
  77. package:config_set("suserepo", true)
  78. package:config_set("helixrepo", true)
  79. end
  80. if package:config("rpm5") then
  81. package:config_set("rpmmd", true)
  82. end
  83. if package:config("archrepo") or package:config("debian") then
  84. package:config_set("lzma_compression", true)
  85. end
  86. if package:config("apk") then
  87. package:config_set("zstd_compression", true)
  88. end
  89. if package:config("rpmmd") or package:config("suserepo") or package:config("appdata") or package:config("comps") or package:config("helixrepo") or mdkrepo_enabled then
  90. libxml2_or_expat_enabled = true
  91. end
  92. package:add("deps", "zlib")
  93. if package:config("lzma_compression") then
  94. package:add("deps", "xz")
  95. end
  96. if package:config("bzip2_compression") then
  97. package:add("deps", "bzip2")
  98. end
  99. if package:config("zstd_compression") then
  100. package:add("deps", "zstd")
  101. end
  102. if package:config("zchunk_compression") then
  103. package:add("deps", "zchunk")
  104. end
  105. if libxml2_or_expat_enabled then
  106. if package:config("libxml2") then
  107. package:add("deps", "libxml2")
  108. else
  109. package:add("deps", "expat")
  110. end
  111. end
  112. end)
  113. on_install(function (package)
  114. local configs = {}
  115. table.insert(configs, "-DENABLE_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  116. table.insert(configs, "-DDISABLE_SHARED=" .. (package:config("shared") and "OFF" or "ON"))
  117. local options = {
  118. "rpmdb", "rpmdb_librpm", "rpmdb_bdb", "rpmdb_byrpmheader", "rpmpkg", "rpmpkg_librpm", "pubkey", "rpmmd", "rpm5",
  119. "suserepo", "comps", "helixrepo", "debian", "mdkrepo", "archrepo", "apk", "cudfrepo",
  120. "haiku", "conda", "appdata", "multi_semantics",
  121. "lzma_compression", "bzip2_compression", "zstd_compression", "zchunk_compression"
  122. }
  123. local no_prefix_options = {
  124. "multi_semantics", "rpm5"
  125. }
  126. for _, option in ipairs(options) do
  127. if package:config(option) then
  128. if not table.contains(no_prefix_options, option) then
  129. table.insert(configs, ("-DENABLE_%s=ON"):format(option:upper()))
  130. else
  131. table.insert(configs, ("-D%s=ON"):format(option:upper()))
  132. end
  133. end
  134. end
  135. table.insert(configs, "-DWITHOUT_COOKIEOPEN=" .. (package:config("cookieopen") and "OFF" or "ON"))
  136. table.insert(configs, "-DWITH_LIBXML2=" .. (package:config("libxml2") and "ON" or "OFF"))
  137. if package:config("zchunk_compression") then
  138. table.insert(configs, "-DWITH_SYSTEM_ZCHUNK=ON")
  139. end
  140. if not package:config("tools") then
  141. io.replace("CMakeLists.txt", "ADD_SUBDIRECTORY (tools)", "", {plain = true})
  142. end
  143. io.replace("CMakeLists.txt", "ADD_SUBDIRECTORY (examples)", "", {plain = true})
  144. io.replace("CMakeLists.txt", "ADD_SUBDIRECTORY (doc)", "", {plain = true})
  145. io.replace("ext/CMakeLists.txt", "repo_testcase.c", "", {plain = true})
  146. io.replace("ext/CMakeLists.txt", "testcase.c", "", {plain = true})
  147. io.replace("ext/CMakeLists.txt", "testcase.h", "", {plain = true})
  148. if package:config("cookieopen") then
  149. -- @see https://developer.android.com/ndk/guides/common-problems
  150. -- funopen() is sometimes not available when API < 24.
  151. if package:is_plat("android") and package:is_arch("armeabi-v7a") then
  152. local ndk_sdkver = package:toolchain("ndk"):config("ndk_sdkver")
  153. if ndk_sdkver and tonumber(ndk_sdkver) < 24 then
  154. io.replace("CMakeLists.txt", "ADD_DEFINITIONS (-D_FILE_OFFSET_BITS=64)", "", {plain = true})
  155. end
  156. end
  157. end
  158. import("package.tools.cmake").install(package, configs)
  159. end)
  160. on_test(function (package)
  161. assert(package:check_csnippets({test = [[
  162. void test() {
  163. Pool *pool = pool_create();
  164. }
  165. ]]}, {configs = {languages = "c99"}, includes = "solv/pool.h"}))
  166. end)