xmake.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package("antlr4-runtime")
  2. set_homepage("http://antlr.org")
  3. set_description("ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/antlr/antlr4/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/antlr/antlr4.git")
  7. add_versions("4.13.2", "9f18272a9b32b622835a3365f850dd1063d60f5045fb1e12ce475ae6e18a35bb")
  8. add_versions("4.13.1", "da20d487524d7f0a8b13f73a8dc326de7fc2e5775f5a49693c0a4e59c6b1410c")
  9. add_patches("4.13.2", "patches/4.13.2/add-include-chrono.patch", "79400e790cc757760a292168a52762e6e2b91045190231fdf06cba60a164309e")
  10. if is_plat("mingw") and is_subhost("msys") then
  11. add_extsources("pacman::antlr4-runtime-cpp")
  12. elseif is_plat("linux") then
  13. add_extsources("pacman::antlr4-runtime", "apt::libantlr4-runtime-dev")
  14. elseif is_plat("macosx") then
  15. add_extsources("brew::antlr4-cpp-runtime")
  16. end
  17. if is_plat("linux", "bsd") then
  18. add_syslinks("m", "pthread")
  19. elseif is_plat("macosx") then
  20. add_frameworks("CoreFoundation")
  21. end
  22. add_includedirs("include", "include/antlr4-runtime")
  23. add_deps("cmake")
  24. on_install(function (package)
  25. if not package:config("shared") then
  26. package:add("defines", "ANTLR4CPP_STATIC")
  27. end
  28. os.cd("runtime/Cpp")
  29. io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")]], "", {plain = true})
  30. io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")]], "", {plain = true})
  31. io.replace("CMakeLists.txt", "add_subdirectory(runtime)",
  32. "include(GNUInstallDirs)\nadd_subdirectory(runtime)", {plain = true})
  33. local configs = {"-DANTLR_BUILD_CPP_TESTS=OFF", "-DANTLR4_INSTALL=ON"}
  34. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  35. table.insert(configs, "-DANTLR_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  36. table.insert(configs, "-DANTLR_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  37. import("package.tools.cmake").install(package, configs)
  38. end)
  39. on_test(function (package)
  40. assert(package:check_cxxsnippets({test = [[
  41. void test() {
  42. antlr4::ANTLRInputStream x;
  43. }
  44. ]]}, {configs = {languages = "c++17"}, includes = "antlr4-runtime/antlr4-runtime.h"}))
  45. end)