2024-01-05 16:40:41 +00:00
|
|
|
cmake_minimum_required(VERSION 3.20)
|
2024-01-04 16:05:11 +00:00
|
|
|
|
2024-01-05 16:40:41 +00:00
|
|
|
project(npc)
|
2024-03-07 07:32:05 +00:00
|
|
|
include(CTest)
|
2024-01-05 16:40:41 +00:00
|
|
|
set (CMAKE_CXX_STANDARD 11)
|
|
|
|
cmake_policy(SET CMP0144 NEW)
|
2024-01-04 16:05:11 +00:00
|
|
|
|
2024-01-05 16:40:41 +00:00
|
|
|
execute_process(
|
2024-01-05 16:47:23 +00:00
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/../git_commit.sh "configure(npc)"
|
2024-01-05 16:43:00 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..
|
2024-01-05 16:40:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
find_package(SDL2_image REQUIRED)
|
|
|
|
|
|
|
|
find_package(verilator REQUIRED)
|
|
|
|
|
|
|
|
find_library(NVBOARD_LIBRARY NAMES nvboard)
|
|
|
|
find_path(NVBOARD_INCLUDE_DIR NAMES nvboard.h)
|
|
|
|
|
2024-01-10 12:11:41 +00:00
|
|
|
set(TOPMODULES "Switch" "Keyboard")
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:22:57 +00:00
|
|
|
foreach(TOPMODULE IN LISTS TOPMODULES)
|
2024-01-10 12:16:11 +00:00
|
|
|
|
|
|
|
# FIXME: all scala source file are tracked here, cause all files to rebuild
|
|
|
|
# after a source update.
|
2024-01-10 10:21:53 +00:00
|
|
|
set(SCALA_CORE "${CMAKE_CURRENT_SOURCE_DIR}/core")
|
|
|
|
set(CHISEL_MODULE_CLASS "${CMAKE_PROJECT_NAME}.${TOPMODULE}")
|
|
|
|
file(GLOB_RECURSE SCALA_CORE_SOURCES "${SCALA_CORE}/src/main/scala/*.scala")
|
|
|
|
file(GLOB_RECURSE SCALA_CORE_TEST_SOURCES "${SCALA_CORE}/src/test/scala/*.scala")
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
# Configure time verilog source generation for verilator
|
|
|
|
execute_process(
|
|
|
|
COMMAND sbt "runMain circt.stage.ChiselMain --target-dir ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc --module ${CHISEL_MODULE_CLASS} --target verilog"
|
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
|
|
|
)
|
2024-01-04 16:05:11 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc/${TOPMODULE}.v
|
|
|
|
COMMAND sbt "runMain circt.stage.ChiselMain --target-dir ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc --module ${CHISEL_MODULE_CLASS} --target verilog"
|
|
|
|
WORKING_DIRECTORY ${SCALA_CORE}
|
|
|
|
DEPENDS ${SCALA_CORE_SOURCES}
|
|
|
|
)
|
2024-01-04 16:05:11 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
add_custom_target(
|
2024-01-10 12:01:29 +00:00
|
|
|
ChiselBuild_${TOPMODULE}
|
2024-01-10 10:21:53 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc/${TOPMODULE}.v
|
|
|
|
)
|
2024-01-04 16:05:11 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
# -- Build NVBoard executable
|
2024-01-04 16:05:11 +00:00
|
|
|
|
2024-01-10 10:21:53 +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
|
|
|
|
)
|
2024-01-04 16:05:11 +00:00
|
|
|
|
2024-01-10 10:32:30 +00:00
|
|
|
unset(SOURCES)
|
|
|
|
file(GLOB_RECURSE SOURCES csrc_nvboard/${TOPMODULE}/*.cpp)
|
|
|
|
add_executable(V${TOPMODULE}_nvboard ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/auto_bind.cpp)
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
verilate(V${TOPMODULE}_nvboard TRACE COVERAGE THREADS
|
|
|
|
TOP_MODULE ${TOPMODULE}
|
|
|
|
PREFIX V${TOPMODULE}
|
|
|
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc/${TOPMODULE}.v)
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 12:02:26 +00:00
|
|
|
add_dependencies(V${TOPMODULE}_nvboard ChiselBuild_${TOPMODULE})
|
2024-01-10 10:21:53 +00:00
|
|
|
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)
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
install(TARGETS V${TOPMODULE}_nvboard)
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
# -- Build Verilator executable and add to test
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:32:30 +00:00
|
|
|
unset(SOURCES)
|
|
|
|
file(GLOB_RECURSE SOURCES csrc/${TOPMODULE}/*.cpp)
|
|
|
|
add_executable(V${TOPMODULE} ${SOURCES})
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
verilate(V${TOPMODULE} TRACE COVERAGE THREADS
|
|
|
|
TOP_MODULE ${TOPMODULE}
|
|
|
|
PREFIX V${TOPMODULE}
|
|
|
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${TOPMODULE}/vsrc/${TOPMODULE}.v)
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 12:02:26 +00:00
|
|
|
add_dependencies(V${TOPMODULE} ChiselBuild_${TOPMODULE})
|
2024-01-05 16:40:41 +00:00
|
|
|
|
2024-01-10 10:21:53 +00:00
|
|
|
enable_testing()
|
2024-03-07 07:34:14 +00:00
|
|
|
add_test(V${TOPMODULE}_build
|
|
|
|
"${CMAKE_COMMAND}"
|
|
|
|
--build "${CMAKE_BINARY_DIR}"
|
|
|
|
--config "$<CONFIG>"
|
|
|
|
--target V${TOPMODULE}
|
|
|
|
)
|
|
|
|
set_tests_properties(V${TOPMODULE}_build PROPERTIES FIXTURES_SETUP V${TOPMODULE}_fixture)
|
2024-03-07 07:49:59 +00:00
|
|
|
add_test(V${TOPMODULE} V${TOPMODULE})
|
2024-03-07 07:34:14 +00:00
|
|
|
set_tests_properties(V${TOPMODULE} PROPERTIES FIXTURES_REQUIRED V${TOPMODULE}_fixture)
|
2024-01-10 10:21:53 +00:00
|
|
|
|
|
|
|
# -- Add build tracking
|
|
|
|
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}/..
|
|
|
|
)
|
|
|
|
|
|
|
|
endforeach()
|