xmake.lua 5.1 KB

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