xmake.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package("verilator")
  2. set_kind("toolchain")
  3. set_homepage("https://verilator.org")
  4. set_description("Verilator open-source SystemVerilog simulator and lint system")
  5. set_license("LGPL-3.0")
  6. add_urls("https://github.com/verilator/verilator/archive/refs/tags/$(version).tar.gz",
  7. "https://github.com/verilator/verilator.git")
  8. add_versions("v5.036", "4199964882d56cf6a19ce80c6a297ebe3b0c35ea81106cd4f722342594337c47")
  9. add_versions("v5.034", "002da98e316ca6eee40407f5deb7d7c43a0788847d39c90d4d31ddbbc03020e8")
  10. add_versions("v5.032", "5a262564b10be8bdb31ff4fb67d77bcf5f52fc1b4e6c88d5ca3264fb481f1e41")
  11. add_versions("v5.016", "66fc36f65033e5ec904481dd3d0df56500e90c0bfca23b2ae21b4a8d39e05ef1")
  12. add_versions("v5.032", "5a262564b10be8bdb31ff4fb67d77bcf5f52fc1b4e6c88d5ca3264fb481f1e41")
  13. add_deps("cmake")
  14. if on_check then
  15. on_check(function (package)
  16. if is_subhost("msys") and xmake:version():lt("2.9.7") then
  17. raise("package(verilator) requires xmake >= 2.9.7 on msys")
  18. end
  19. end)
  20. end
  21. on_load(function (package)
  22. if not package:is_precompiled() then
  23. package:add("deps", "flex", {kind = "library"})
  24. package:add("deps", "bison")
  25. package:add("deps", "python 3.x", {kind = "binary"})
  26. end
  27. package:mark_as_pathenv("VERILATOR_ROOT")
  28. package:addenv("VERILATOR_ROOT", ".")
  29. end)
  30. on_install(function (package)
  31. import("package.tools.cmake")
  32. if is_subhost("msys") then
  33. io.replace("CMakeLists.txt", "if(WIN32)", "if(0)", {plain = true})
  34. end
  35. local version = package:version()
  36. if version then
  37. if version:ge("5.024") then
  38. io.replace("bin/verilator", "$verilator_root ne realpath($ENV{VERILATOR_ROOT})", "true")
  39. end
  40. if version:ge("5.030") then
  41. io.replace("src/CMakeLists.txt", "MSVC_RUNTIME_LIBRARY MultiThreaded$<IF:$<CONFIG:Release>,,DebugDLL>", "", {plain = true})
  42. else
  43. io.replace("src/CMakeLists.txt", "MSVC_RUNTIME_LIBRARY MultiThreaded$<IF:$<CONFIG:Release>,,DebugDLL>", "", {plain = true})
  44. if version:lt("5.028") then
  45. if is_host("linux", "bsd") then
  46. io.replace("src/CMakeLists.txt", "install(TARGETS ${verilator})",
  47. "target_link_libraries(${verilator} PRIVATE pthread)\ninstall(TARGETS ${verilator})", {plain = true})
  48. end
  49. if version:lt("5.020") then
  50. if is_host("windows") and not package:has_tool("cxx", "cl") then
  51. io.replace("src/CMakeLists.txt", "INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE", "", {plain = true})
  52. io.replace("src/CMakeLists.txt", "/bigobj", "-Wa,-mbig-obj", {plain = true})
  53. io.replace("src/CMakeLists.txt", "YY_NO_UNISTD_H", "", {plain = true})
  54. io.replace("src/CMakeLists.txt", "/STACK:10000000", "-Wl,--stack,10000000 -mconsole -lcomctl32 -DWIN_32_LEAN_AND_MEAN", {plain = true})
  55. end
  56. end
  57. end
  58. end
  59. end
  60. local configs = {
  61. "-DOBJCACHE_ENABLED=OFF",
  62. "-DDEBUG_AND_RELEASE_AND_COVERAGE=OFF",
  63. }
  64. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  65. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  66. if not is_host("linux") then
  67. table.insert(configs, "-DCMAKE_CXX_STANDARD=20")
  68. end
  69. local opt = {}
  70. opt.envs = cmake.buildenvs(package)
  71. local winflexbison = package:dep("winflexbison")
  72. if winflexbison then
  73. opt.envs.WIN_FLEX_BISON = winflexbison:installdir("include")
  74. else
  75. local flex = package:dep("flex")
  76. -- https://github.com/verilator/verilator/issues/3487
  77. if is_subhost("msys") or not flex:is_system() then
  78. local includedir = flex:installdir("include")
  79. if version and version:lt("5.026") then
  80. opt.cxflags = "-I" .. includedir
  81. else
  82. table.insert(configs, "-DFLEX_INCLUDE_DIR=" .. includedir)
  83. end
  84. end
  85. end
  86. cmake.install(package, configs, opt)
  87. if is_host("linux") then
  88. if package:is_debug() then
  89. local bindir = package:installdir("bin")
  90. os.ln(path.join(bindir, "verilator_bin_dbg"), path.join(bindir, "verilator_bin"))
  91. end
  92. elseif is_host("windows") then
  93. local bindir = package:installdir("bin")
  94. local verilator = path.join(bindir, "verilator.exe")
  95. if not os.isfile(verilator) then
  96. local verilator_bin = "verilator_bin"
  97. if package:is_debug() then
  98. verilator_bin = verilator_bin .. "_dbg"
  99. end
  100. verilator_bin = path.join(bindir, verilator_bin .. ".exe")
  101. os.trycp(verilator_bin, verilator)
  102. end
  103. end
  104. end)
  105. on_test(function (package)
  106. os.vrun("verilator --version")
  107. end)