2024-03-29 02:35:49 +00:00
|
|
|
cmake_minimum_required(VERSION 3.26)
|
2024-01-05 15:50:26 +00:00
|
|
|
|
2024-03-13 06:53:31 +00:00
|
|
|
project(flow)
|
2024-03-29 02:35:49 +00:00
|
|
|
set (CMAKE_CXX_STANDARD 14)
|
2024-01-05 15:50:26 +00:00
|
|
|
cmake_policy(SET CMP0144 NEW)
|
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
include(CMakeDependentOption)
|
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
# -- Build options
|
|
|
|
option(BUILD_USE_BLOOP "Whether to use bloop to spped up elaborate" ON)
|
|
|
|
option(BUILD_SIM_TARGET "Whether to build verilator simulation binary" ON)
|
|
|
|
cmake_dependent_option(BUILD_SIM_NVBOARD_TARGET "Whether to build nvboard target" OFF "BUILD_SIM_TARGET" OFF)
|
|
|
|
option(ENABLE_YSYX_GIT_TRACKER "Ysyx tracker support" OFF)
|
|
|
|
set(TOPMODULE "Flow" CACHE STRING "Topmodule name in chisel")
|
2024-01-05 17:01:02 +00:00
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
# -- Ysyx tracker, configure
|
|
|
|
if(ENABLE_YSYX_GIT_TRACKER)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/../git_commit.sh "configure(npc)"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..
|
|
|
|
)
|
|
|
|
endif()
|
2024-01-05 15:50:26 +00:00
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
# -- Check dependencies
|
|
|
|
if(BUILD_SIM_TARGET)
|
|
|
|
find_package(verilator REQUIRED)
|
|
|
|
endif()
|
|
|
|
if(BUILD_SIM_NVBOARD_TARGET)
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
find_package(SDL2_image REQUIRED)
|
|
|
|
endif()
|
2024-01-05 15:50:26 +00:00
|
|
|
|
|
|
|
find_library(NVBOARD_LIBRARY NAMES nvboard)
|
|
|
|
find_path(NVBOARD_INCLUDE_DIR NAMES nvboard.h)
|
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
# FIXME: all scala source file are tracked here, cause all files to rebuild
|
|
|
|
# after a source update.
|
|
|
|
set(SCALA_CORE "${CMAKE_CURRENT_SOURCE_DIR}/core")
|
|
|
|
set(CHISEL_MODULE_CLASS "${CMAKE_PROJECT_NAME}.${TOPMODULE}")
|
|
|
|
|
|
|
|
# Verilog files are generted in CHISEL_OUTPUT_TMP_DIR and copy to
|
|
|
|
# CHISEL_OUTPUT_DIR if content changes
|
|
|
|
set(CHISEL_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc/)
|
|
|
|
set(CHISEL_OUTPUT_TMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc_tmp/)
|
|
|
|
|
|
|
|
set(CHISEL_OUTPUT_VERILATOR_CONF ${CHISEL_OUTPUT_DIR}/conf.vlt)
|
|
|
|
set(CHISEL_OUTPUT_TOPMODULE ${CHISEL_OUTPUT_DIR}/${TOPMODULE}.sv)
|
|
|
|
set(CHISEL_EMIT_ARGS "--target-dir ${CHISEL_OUTPUT_TMP_DIR}")
|
|
|
|
|
|
|
|
# -- Add an always run target to generate verilog files with sbt/bloop,
|
|
|
|
# as we don't know if the result files will be different from cmake
|
|
|
|
# NOTE: Must reconfigure if we add new files in SCALA_CORE directory
|
|
|
|
file(GLOB_RECURSE SCALA_CORE_SOURCES "${SCALA_CORE}/src/main/scala/*.scala")
|
|
|
|
file(GLOB_RECURSE SCALA_CORE_RESOURCES "${SCALA_CORE}/src/resource/*")
|
|
|
|
set(CHISEL_DEPENDENCY ${SCALA_CORE_SOURCES} ${SCALA_CORE_RESOURCE} ${SCALA_CORE}/build.sbt)
|
|
|
|
|
|
|
|
if(BUILD_USE_BLOOP)
|
|
|
|
set(CHISEL_TARGET bloop_${TOPMODULE})
|
|
|
|
set(CHISEL_TEST_TARGET bloop_${TOPMODULE}_test)
|
|
|
|
# Export sbt build config to bloop
|
|
|
|
if(NOT EXISTS ${SCALA_CORE}/.bloop)
|
|
|
|
execute_process(
|
|
|
|
COMMAND sbt bloopInstall
|
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
string(REPLACE " " ";" CHISEL_EMIT_ARGS_LIST ${CHISEL_EMIT_ARGS})
|
|
|
|
list(TRANSFORM CHISEL_EMIT_ARGS_LIST PREPEND "--args;")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CHISEL_OUTPUT_TOPMODULE}
|
|
|
|
COMMAND bloop run root ${CHISEL_EMIT_ARGS_LIST}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CHISEL_OUTPUT_TMP_DIR} ${CHISEL_OUTPUT_DIR}
|
2024-01-10 12:20:45 +00:00
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
2024-03-29 02:35:49 +00:00
|
|
|
DEPENDS ${CHISEL_DEPENDENCY}
|
|
|
|
COMMAND_EXPAND_LISTS
|
2024-01-10 12:20:45 +00:00
|
|
|
)
|
2024-03-29 02:35:49 +00:00
|
|
|
add_test(
|
|
|
|
NAME bloop_${TOPMODULE}_test
|
|
|
|
COMMAND bloop test
|
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(CHISEL_TARGET sbt_${TOPMODULE})
|
|
|
|
set(CHISEL_TEST_TARGET sbt_${TOPMODULE}_test)
|
2024-01-10 12:20:45 +00:00
|
|
|
add_custom_command(
|
2024-03-29 02:35:49 +00:00
|
|
|
OUTPUT ${CHISEL_OUTPUT_TOPMODULE}
|
|
|
|
COMMAND sbt "run ${CHISEL_EMIT_ARGS}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CHISEL_OUTPUT_TMP_DIR} ${CHISEL_OUTPUT_DIR}
|
2024-01-10 12:20:45 +00:00
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
2024-03-29 02:35:49 +00:00
|
|
|
DEPENDS ${CHISEL_DEPENDENCY}
|
|
|
|
VERBATIM
|
2024-01-10 12:20:45 +00:00
|
|
|
)
|
2024-03-29 02:35:49 +00:00
|
|
|
add_test(
|
|
|
|
NAME sbt_${TOPMODULE}_test
|
|
|
|
COMMAND sbt test
|
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
2024-01-10 12:20:45 +00:00
|
|
|
)
|
2024-03-29 02:35:49 +00:00
|
|
|
endif()
|
2024-01-10 12:20:45 +00:00
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
if(NOT EXISTS ${CHISEL_OUTPUT_TOPMODULE})
|
|
|
|
# Probably cold build, generate verilog at configure time to produce top module file
|
|
|
|
execute_process(
|
|
|
|
COMMAND sbt "run ${CHISEL_EMIT_ARGS}"
|
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
|
|
|
)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CHISEL_OUTPUT_TMP_DIR} ${CHISEL_OUTPUT_DIR}
|
|
|
|
)
|
|
|
|
endif()
|
2024-01-10 12:20:45 +00:00
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
# -- Build NVBoard executable
|
|
|
|
if(BUILD_SIM_NVBOARD_TARGET)
|
2024-01-10 12:20:45 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/auto_bind.cpp
|
|
|
|
COMMAND auto_pin_bind ${CMAKE_SOURCE_DIR}/constr/${TOPMODULE}.nxdc ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/auto_bind.cpp
|
|
|
|
DEPENDS ${CMAKE_SOURCE_DIR}/constr/${TOPMODULE}.nxdc
|
|
|
|
)
|
|
|
|
|
|
|
|
file(GLOB_RECURSE SOURCES csrc_nvboard/${TOPMODULE}/*.cpp)
|
|
|
|
add_executable(V${TOPMODULE}_nvboard ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/auto_bind.cpp)
|
|
|
|
|
2024-03-13 06:53:31 +00:00
|
|
|
verilate(V${TOPMODULE}_nvboard TRACE THREADS
|
2024-01-10 12:20:45 +00:00
|
|
|
TOP_MODULE ${TOPMODULE}
|
|
|
|
PREFIX V${TOPMODULE}
|
2024-03-29 02:35:49 +00:00
|
|
|
SOURCES ${CHISEL_OUTPUT_TOPMODULE}
|
|
|
|
INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc)
|
2024-01-10 12:20:45 +00:00
|
|
|
|
|
|
|
add_dependencies(V${TOPMODULE}_nvboard ChiselBuild_${TOPMODULE})
|
|
|
|
target_include_directories(V${TOPMODULE}_nvboard PRIVATE ${NVBOARD_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
|
|
|
|
target_link_libraries(V${TOPMODULE}_nvboard PRIVATE ${NVBOARD_LIBRARY} SDL2::SDL2 SDL2_image::SDL2_image)
|
|
|
|
|
|
|
|
install(TARGETS V${TOPMODULE}_nvboard)
|
2024-03-29 02:35:49 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# -- Build Verilator executable and add to test
|
|
|
|
file(GLOB_RECURSE SOURCES csrc/${TOPMODULE}/*.cpp)
|
|
|
|
add_executable(V${TOPMODULE} ${SOURCES})
|
|
|
|
|
|
|
|
verilate(V${TOPMODULE} TRACE COVERAGE THREADS
|
|
|
|
TOP_MODULE ${TOPMODULE}
|
|
|
|
PREFIX V${TOPMODULE}
|
|
|
|
SOURCES ${CHISEL_OUTPUT_TOPMODULE} ${CHISEL_OUTPUT_VERILATOR_CONF}
|
|
|
|
INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc
|
|
|
|
VERILATOR_ARGS
|
|
|
|
"--vpi" # Enable VPI
|
|
|
|
|
|
|
|
)
|
2024-01-10 12:20:45 +00:00
|
|
|
|
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
add_test(NAME V${TOPMODULE} COMMAND V${TOPMODULE})
|
2024-01-10 12:20:45 +00:00
|
|
|
|
2024-03-29 02:35:49 +00:00
|
|
|
# -- Add build tracking
|
|
|
|
if(ENABLE_YSYX_GIT_TRACKER)
|
2024-01-10 12:20:45 +00:00
|
|
|
add_custom_command(
|
|
|
|
TARGET V${TOPMODULE}_nvboard PRE_BUILD
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/../git_commit.sh "build_${CMAKE_PROJECT_NAME}_V${TOPMODULE}_nvboard"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
TARGET V${TOPMODULE} PRE_BUILD
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/../git_commit.sh "build_${CMAKE_PROJECT_NAME}_V${TOPMODULE}"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..
|
|
|
|
)
|
2024-03-29 02:35:49 +00:00
|
|
|
endif()
|