diff --git a/SoCMakeConfig.cmake b/SoCMakeConfig.cmake index d83ffc6..81e3ffd 100644 --- a/SoCMakeConfig.cmake +++ b/SoCMakeConfig.cmake @@ -27,7 +27,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/cmake/utils/copy_rtl_files/vhier.cmake") # ==================================== # ----- Verilator ------ -include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/verilator/verilate.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/verilator/verilator.cmake") # ----- iverilog ------ include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/iverilog/iverilog.cmake") diff --git a/cmake/sim/verilator/verilate.cmake b/cmake/sim/verilator/verilator.cmake similarity index 84% rename from cmake/sim/verilator/verilate.cmake rename to cmake/sim/verilator/verilator.cmake index 64832a6..8f9187b 100644 --- a/cmake/sim/verilator/verilate.cmake +++ b/cmake/sim/verilator/verilator.cmake @@ -1,4 +1,4 @@ -function(verilate IP_LIB) +function(verilator IP_LIB) set(OPTIONS "COVERAGE;TRACE;TRACE_FST;SYSTEMC;TRACE_STRUCTS;MAIN") set(ONE_PARAM_ARGS "PREFIX;TOP_MODULE;THREADS;TRACE_THREADS;DIRECTORY;EXECUTABLE_NAME") set(MULTI_PARAM_ARGS "VERILATOR_ARGS;OPT_SLOW;OPT_FAST;OPT_GLOBAL") @@ -21,7 +21,7 @@ function(verilate IP_LIB) get_target_property(BINARY_DIR ${IP_LIB} BINARY_DIR) if(NOT ARG_DIRECTORY) - set(DIRECTORY "${BINARY_DIR}/${IP_LIB}_verilate") + set(DIRECTORY "${BINARY_DIR}/${IP_LIB}_verilator") else() set(DIRECTORY ${ARG_DIRECTORY}) endif() @@ -58,8 +58,10 @@ function(verilate IP_LIB) set(PREFIX V${ARG_TOP_MODULE}) endif() + ## TODO deprecate get_ip_property(VERILATOR_ARGS ${IP_LIB} VERILATOR_ARGS) list(APPEND ARG_VERILATOR_ARGS ${VERILATOR_ARGS}) + ## get_ip_compile_definitions(COMP_DEFS ${IP_LIB} SYSTEMVERILOG VERILOG) foreach(def ${COMP_DEFS}) @@ -76,7 +78,7 @@ function(verilate IP_LIB) if(ARG_MAIN) list(APPEND ARG_VERILATOR_ARGS --main) if(NOT ARG_EXECUTABLE_NAME) - set(ARG_EXECUTABLE_NAME ${IP_LIB}_verilator_tb) + set(ARG_EXECUTABLE_NAME ${IP_LIB}_verilator_exec) endif() set(EXECUTABLE_PATH ${BINARY_DIR}/${ARG_EXECUTABLE_NAME}) unset(ARG_MAIN) @@ -111,7 +113,6 @@ function(verilate IP_LIB) endforeach() string(REPLACE ";" "|" ARGUMENTS_LIST "${ARGUMENTS_LIST}") - if(ARG_SYSTEMC) if(NOT SYSTEMC_HOME) find_package(SystemCLanguage REQUIRED @@ -125,6 +126,17 @@ function(verilate IP_LIB) set(ARG_CMAKE_CXX_STANDARD "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}") endif() + ################################## + ## Prepare help message ########## + ################################## + if(EXECUTABLE_PATH) + set(OUTPUT_TYPE "EXECUTABLE") + else() + set(OUTPUT_TYPE "STATIC_LIBRARY") + endif() + set(DESCRIPTION "Compiling ${IP_LIB} with verilator as ${OUTPUT_TYPE}") + ### + set(VERILATE_TARGET ${IP_LIB}_verilate) include(ExternalProject) ExternalProject_Add(${VERILATE_TARGET} @@ -152,6 +164,7 @@ function(verilate IP_LIB) INSTALL_COMMAND "" DEPENDS ${IP_LIB} EXCLUDE_FROM_ALL 1 + COMMENT ${DESCRIPTION} ) set_property( @@ -160,6 +173,7 @@ function(verilate IP_LIB) ${DIRECTORY} ${EXECUTABLE_PATH} ) + set_property(TARGET ${VERILATE_TARGET} PROPERTY DESCRIPTION ${DESCRIPTION}) set(VLT_STATIC_LIB "${DIRECTORY}/lib${ARG_TOP_MODULE}.a") set(INC_DIR ${DIRECTORY}) @@ -181,4 +195,16 @@ function(verilate IP_LIB) string(REPLACE "__" "::" ALIAS_NAME "${VERILATED_LIB}") add_library(${ALIAS_NAME} ALIAS ${VERILATED_LIB}) + + if(EXECUTABLE_PATH) + set(DESCRIPTION "Run ${CMAKE_CURRENT_FUNCTION} testbench compiled from ${IP_LIB}") + # Add a custom target to run the generated executable + add_custom_target( + run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION} + COMMAND ${EXECUTABLE_PATH} + DEPENDS ${EXECUTABLE_PATH} ${STAMP_FILE} ${VERILATE_TARGET} + COMMENT ${DESCRIPTION} + ) + set_property(TARGET run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION}) + endif() endfunction() diff --git a/cmake/utils/copy_rtl_files/vhier.cmake b/cmake/utils/copy_rtl_files/vhier.cmake index 4bd3d78..3a509a6 100644 --- a/cmake/utils/copy_rtl_files/vhier.cmake +++ b/cmake/utils/copy_rtl_files/vhier.cmake @@ -32,6 +32,8 @@ function(vhier IP_LIB) $<$:--forest> ) + set(DESCRIPTION "Extract verilog hierarchy of ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}") + set(OUT_FILE ${CMAKE_BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.$,xml,txt>) set(STAMP_FILE "${CMAKE_BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.stamp") add_custom_command( @@ -39,12 +41,14 @@ function(vhier IP_LIB) COMMAND touch ${STAMP_FILE} COMMAND ${__CMD} | tee ${OUT_FILE} DEPENDS ${RTL_SOURCES} ${IP_LIB} - COMMENT "Printing verilog hierarchy of ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}" + COMMENT ${DESCRIPTION} ) add_custom_target( ${IP_LIB}_${CMAKE_CURRENT_FUNCTION} DEPENDS ${IP_LIB} ${STAMP_FILE} ${OUT_FILE} ) + + set_property(TARGET ${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION}) endfunction() diff --git a/examples/sim_example/CMakeLists.txt b/examples/sim_example/CMakeLists.txt index ffae88e..cf960a7 100644 --- a/examples/sim_example/CMakeLists.txt +++ b/examples/sim_example/CMakeLists.txt @@ -13,7 +13,7 @@ ip_sources(${IP} VERILOG # Add source files to the VERILOG file set iverilog(${IP}) -verilate(${IP} # Create verilate target +verilator(${IP} # Create verilate target MAIN) # Let Verilator create a main.cpp testbench help() diff --git a/examples/sim_example/deps/deps.cmake b/examples/sim_example/deps/deps.cmake index b1386cd..2659496 100644 --- a/examples/sim_example/deps/deps.cmake +++ b/examples/sim_example/deps/deps.cmake @@ -3,6 +3,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) # Include the CPM.cmake downloader CPMAddPackage( # Add SoCMake as a package NAME SoCMake - GIT_TAG master # You can define GIT_TAG or VERSION for versioning + GIT_TAG develop # You can define GIT_TAG or VERSION for versioning GIT_REPOSITORY "https://github.com/HEP-SoC/SoCMake.git" # GIT_REPOSITORY or URL ) diff --git a/examples/sim_example/tb.v b/examples/sim_example/tb.v index 8a6e8f0..7d32df2 100644 --- a/examples/sim_example/tb.v +++ b/examples/sim_example/tb.v @@ -1,6 +1,6 @@ module tb; initial begin - $display("Simulated with Iverilog, from SoCMake build system\n"); + $display("Hello world, from SoCMake build system\n"); $finish(); end endmodule diff --git a/examples/verilator/CMakeLists.txt b/examples/verilator/CMakeLists.txt index 51fdc9b..fea400d 100644 --- a/examples/verilator/CMakeLists.txt +++ b/examples/verilator/CMakeLists.txt @@ -4,8 +4,10 @@ project(example CXX C) include("deps/deps.cmake") add_subdirectory(adder) -verilate(cern::ip::adder::0.0.1 TRACE) +verilator(cern::ip::adder::0.0.1 TRACE) add_executable(testbench main.cpp) target_link_libraries(testbench cern::ip::adder::0.0.1::vlt) + +help() diff --git a/examples/verilator/adder/CMakeLists.txt b/examples/verilator/adder/CMakeLists.txt index 945f3b7..bbacdf9 100644 --- a/examples/verilator/adder/CMakeLists.txt +++ b/examples/verilator/adder/CMakeLists.txt @@ -1,10 +1,8 @@ cmake_minimum_required(VERSION 3.25) project(adder NONE) -add_ip(adder - VENDOR cern - LIBRARY ip - VERSION 0.0.1 +add_ip(cern::ip::adder::0.0.1 + DESCRIPTION "Just a simple adder" ) ip_sources(adder VERILOG diff --git a/examples/verilator/deps/deps.cmake b/examples/verilator/deps/deps.cmake index b1386cd..2659496 100644 --- a/examples/verilator/deps/deps.cmake +++ b/examples/verilator/deps/deps.cmake @@ -3,6 +3,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) # Include the CPM.cmake downloader CPMAddPackage( # Add SoCMake as a package NAME SoCMake - GIT_TAG master # You can define GIT_TAG or VERSION for versioning + GIT_TAG develop # You can define GIT_TAG or VERSION for versioning GIT_REPOSITORY "https://github.com/HEP-SoC/SoCMake.git" # GIT_REPOSITORY or URL )