xmake.lua 5.4 KB

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