xmake.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package("librime")
  2. set_homepage("https://rime.im")
  3. set_description("Rime Input Method Engine, the core library")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/rime/librime/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/rime/librime.git", {submodules = false})
  7. add_versions("1.14.0", "b2b29c3551eec6b45af1ba8fd3fcffb99e2b7451aa974c1c9ce107e69ce3ea68")
  8. add_deps("cmake")
  9. add_deps("glog >=0.7", {configs = {gflags = true}})
  10. add_deps("boost >=1.74", {configs = {regex = true, container = true}})
  11. add_deps("leveldb", "opencc >=1.0.2", "yaml-cpp >=0.5")
  12. on_load("windows", "mingw", function (package)
  13. if package:config("shared") then
  14. package:add("defines", "RIME_IMPORTS")
  15. end
  16. end)
  17. on_install(function (package)
  18. -- remove hardcode abi flags
  19. io.replace("CMakeLists.txt", "set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake)", "", {plain = true})
  20. -- config mode will find gflags automatically
  21. io.replace("CMakeLists.txt", "find_package(Glog REQUIRED)", "find_package(Glog CONFIG REQUIRED)", {plain = true})
  22. io.replace("src/CMakeLists.txt", "${Glog_LIBRARY}", "glog::glog", {plain = true})
  23. io.replace("src/CMakeLists.txt", "${CMAKE_INSTALL_FULL_LIBDIR})", [[
  24. RUNTIME DESTINATION bin
  25. LIBRARY DESTINATION lib
  26. ARCHIVE DESTINATION lib)
  27. ]], {plain = true})
  28. local deps = {
  29. ["Boost_USE_STATIC_LIBS"] = "boost",
  30. ["Gflags_STATIC"] = "gflags",
  31. ["Glog_STATIC"] = "glog",
  32. ["LevelDb_STATIC"] = "leveldb",
  33. ["Marisa_STATIC"] = "marisa",
  34. ["Opencc_STATIC"] = "opencc",
  35. ["YamlCpp_STATIC"] = "yaml-cpp",
  36. }
  37. for str, dep in pairs(deps) do
  38. local value = (package:dep(dep):config("shared") and "0" or "1")
  39. io.replace("CMakeLists.txt", format("set(%s ${BUILD_STATIC})", str), format("set(%s %s)", str, value), {plain = true})
  40. end
  41. local configs = {
  42. "-DBUILD_TEST=OFF",
  43. "-DENABLE_LOGGING=ON",
  44. }
  45. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  46. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  47. table.insert(configs, "-DENABLE_ASAN=" .. (package:config("asan") and "ON" or "OFF"))
  48. import("package.tools.cmake").install(package, configs)
  49. -- Can't use `extern "C"` in c code
  50. if package:config("shared") then
  51. io.replace(path.join(package:installdir("include"), "rime_api.h"), [[extern "C" RIME_DLL]], "RIME_DLL", {plain = true})
  52. end
  53. end)
  54. on_test(function (package)
  55. assert(package:has_cfuncs("rime_get_api", {includes = "rime_api.h"}))
  56. end)