xmake.lua 5.2 KB

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