diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ca3ff8..53f64d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.10) project(rvscc) + +set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) +include(CTest) include(ExternalProject) ExternalProject_Add(firmware diff --git a/cmake/riscv-toolchain.cmake b/cmake/riscv-toolchain.cmake new file mode 100644 index 0000000..4eb572a --- /dev/null +++ b/cmake/riscv-toolchain.cmake @@ -0,0 +1,14 @@ +set(CMAKE_SYSTEM_NAME Generic) + +find_program(RISCV_GCC_FOUND + NAMES riscv-none-elf-gcc riscv32-unknown-elf-gcc) + +get_filename_component(GCC_BIN ${RISCV_GCC_FOUND} NAME) + +string(REPLACE gcc "" TOOLCHAIN_PREFIX ${GCC_BIN}) + +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}as) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump) diff --git a/cmake/utils.cmake b/cmake/utils.cmake new file mode 100644 index 0000000..db7b298 --- /dev/null +++ b/cmake/utils.cmake @@ -0,0 +1,66 @@ +cmake_minimum_required(VERSION 3.10) + +function(rvscc_bin_to_verilog_mem_file) + cmake_parse_arguments(RVSCC + "" + "TARGET" + "" + ${ARGN} + ) + add_custom_command(TARGET ${RVSCC_TARGET} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -j .text + -O verilog + --verilog-data-width=1 + --reverse-bytes=4 + "$" ${RVSCC_TARGET}.mem + COMMENT "Invoking: Verilog Hexdump" + ) +endfunction() + +function(rvscc_dissasemble) + cmake_parse_arguments(RVSCC + "" + "TARGET" + "" + ${ARGN} + ) + add_custom_command(TARGET ${RVSCC_TARGET} POST_BUILD + COMMAND ${CMAKE_OBJDUMP} -S "$" > ${RVSCC_TARGET}.disasm + COMMENT "Invoking: Disassemble" + ) +endfunction() + +function(rvscc_add_test) + cmake_parse_arguments(TEST + "" + "NAME" + "SOURCES" + ${ARGN} + ) + message("Adding test ${TEST_NAME}") + set(TEST_TARGET_NAME test-${TEST_NAME}) + add_executable(${TEST_TARGET_NAME} sim_individual_test.cpp) + if ("${CMAKE_BUILD_TYPE}" EQUAL "Release") + verilate(${TEST_TARGET_NAME} + SOURCES ${TEST_SOURCES} + SYSTEMC + VERILATOR_ARGS --timing + ) + else() # Debug + verilate(${TEST_TARGET_NAME} + SOURCES ${TEST_SOURCES} + TRACE + SYSTEMC + VERILATOR_ARGS --timing + ) + endif() + set_property(TARGET ${TEST_TARGET_NAME} PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD}) + verilator_link_systemc(${TEST_TARGET_NAME}) + list(GET TEST_SOURCES 0 TEST_TOP_MODULE) + get_filename_component(TEST_TOP_MODULE_NAME ${TEST_TOP_MODULE} NAME_WE) + target_compile_definitions(${TEST_TARGET_NAME} PRIVATE + TEST_HEADER="V${TEST_TOP_MODULE_NAME}.h" + TEST_CLASS=V${TEST_TOP_MODULE_NAME} + ) + add_test(NAME ${TEST_TARGET_NAME} COMMAND ${TEST_TARGET_NAME}) +endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cc6a58a..9e8efa3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.10) project(rvscc-tests CXX) -include(CTest) - find_package(verilator HINTS $ENV{VERILATOR_ROOT}) if (NOT verilator_FOUND) message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable")