Internals: Standardize format of CMake files with gersemi. No functional change intended.

This commit is contained in:
Wilson Snyder 2024-09-24 20:43:19 -04:00
parent 3ae18af8dd
commit a4085f3a06
11 changed files with 765 additions and 493 deletions

View File

@ -14,14 +14,17 @@
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW) # Use MSVC_RUNTIME_LIBRARY to select the runtime cmake_policy(SET CMP0091 NEW) # Use MSVC_RUNTIME_LIBRARY to select the runtime
project(Verilator project(
Verilator
VERSION 5.029 VERSION 5.029
HOMEPAGE_URL https://verilator.org HOMEPAGE_URL https://verilator.org
LANGUAGES CXX LANGUAGES CXX
) )
option(DEBUG_AND_RELEASE_AND_COVERAGE option(
"Builds both the debug and release binaries, overriding CMAKE_BUILD_TYPE. Not supported under MSBuild.") DEBUG_AND_RELEASE_AND_COVERAGE
"Builds both the debug and release binaries, overriding CMAKE_BUILD_TYPE. Not supported under MSBuild."
)
find_package(Python3 COMPONENTS Interpreter) find_package(Python3 COMPONENTS Interpreter)
set(PYTHON3 ${Python3_EXECUTABLE}) set(PYTHON3 ${Python3_EXECUTABLE})
@ -32,19 +35,22 @@ include(CheckStructHasMember)
include(ExternalProject) include(ExternalProject)
include(FindThreads) include(FindThreads)
if (NOT WIN32) if(NOT WIN32)
message(WARNING "CMake support on Linux/OSX is experimental.") message(WARNING "CMake support on Linux/OSX is experimental.")
endif() endif()
if (WIN32) if(WIN32)
if (DEFINED ENV{WIN_FLEX_BISON}) if(DEFINED ENV{WIN_FLEX_BISON})
set(WIN_FLEX_BISON "$ENV{WIN_FLEX_BISON}") set(WIN_FLEX_BISON "$ENV{WIN_FLEX_BISON}")
endif() endif()
if (EXISTS ${WIN_FLEX_BISON}) if(EXISTS ${WIN_FLEX_BISON})
list(APPEND CMAKE_PREFIX_PATH ${WIN_FLEX_BISON}) list(APPEND CMAKE_PREFIX_PATH ${WIN_FLEX_BISON})
endif() endif()
if (NOT WIN_FLEX_BISON) if(NOT WIN_FLEX_BISON)
message(FATAL_ERROR "Please install https://github.com/lexxmark/winflexbison and set WIN_FLEX_BISON environment variable. Please use install cmake target after a successful build.") message(
FATAL_ERROR
"Please install https://github.com/lexxmark/winflexbison and set WIN_FLEX_BISON environment variable. Please use install cmake target after a successful build."
)
endif() endif()
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
endif() endif()
@ -52,20 +58,25 @@ endif()
set(OBJCACHE "" CACHE STRING "Path for ccache, auto-detected if empty") set(OBJCACHE "" CACHE STRING "Path for ccache, auto-detected if empty")
option(OBJCACHE_ENABLED "Compile Verilator with ccache" ON) option(OBJCACHE_ENABLED "Compile Verilator with ccache" ON)
if (OBJCACHE_ENABLED) if(OBJCACHE_ENABLED)
if (OBJCACHE STREQUAL "") if(OBJCACHE STREQUAL "")
find_program(OBJCACHE_PATH ccache) find_program(OBJCACHE_PATH ccache)
if (OBJCACHE_PATH STREQUAL "OBJCACHE_PATH-NOTFOUND") if(OBJCACHE_PATH STREQUAL "OBJCACHE_PATH-NOTFOUND")
set(OBJCACHE_PATH "") set(OBJCACHE_PATH "")
endif() endif()
else() else()
set(OBJCACHE_PATH "${OBJCACHE}") set(OBJCACHE_PATH "${OBJCACHE}")
endif() endif()
if (NOT OBJCACHE_PATH STREQUAL "") if(NOT OBJCACHE_PATH STREQUAL "")
execute_process(COMMAND "${OBJCACHE_PATH}" --version execute_process(
OUTPUT_VARIABLE objcache_version) COMMAND "${OBJCACHE_PATH}" --version
OUTPUT_VARIABLE objcache_version
)
string(REGEX MATCH "[^\n\r]+" objcache_version "${objcache_version}") string(REGEX MATCH "[^\n\r]+" objcache_version "${objcache_version}")
message(STATUS "Found ccache: ${OBJCACHE_PATH} (\"${objcache_version}\")") message(
STATUS
"Found ccache: ${OBJCACHE_PATH} (\"${objcache_version}\")"
)
set(CMAKE_CXX_COMPILER_LAUNCHER "${OBJCACHE_PATH}") set(CMAKE_CXX_COMPILER_LAUNCHER "${OBJCACHE_PATH}")
endif() endif()
endif() endif()
@ -76,8 +87,8 @@ find_package(FLEX)
# Build # Build
#set_property(GLOBAL PROPERTY JOB_POOLS one_job=1) #set_property(GLOBAL PROPERTY JOB_POOLS one_job=1)
if (DEBUG_AND_RELEASE_AND_COVERAGE) if(DEBUG_AND_RELEASE_AND_COVERAGE)
if (CMAKE_GENERATOR MATCHES "^Visual Studio ") if(CMAKE_GENERATOR MATCHES "^Visual Studio ")
error("%Error: The DEBUG_AND_RELEASE_AND_COVERAGE option is not supported in MSBuild-based builds.") error("%Error: The DEBUG_AND_RELEASE_AND_COVERAGE option is not supported in MSBuild-based builds.")
endif() endif()
set(saved_build_type ${CMAKE_BUILD_TYPE}) set(saved_build_type ${CMAKE_BUILD_TYPE})
@ -102,22 +113,39 @@ set(AR ${CMAKE_AR})
configure_file(include/verilated_config.h.in include/verilated_config.h @ONLY) configure_file(include/verilated_config.h.in include/verilated_config.h @ONLY)
configure_file(include/verilated.mk.in include/verilated.mk @ONLY) configure_file(include/verilated.mk.in include/verilated.mk @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/verilated_config.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include) install(
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/verilated.mk DESTINATION ${CMAKE_INSTALL_PREFIX}/include) FILES ${CMAKE_CURRENT_BINARY_DIR}/include/verilated_config.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/include/verilated.mk
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
)
configure_package_config_file(verilator-config.cmake.in verilator-config.cmake configure_package_config_file(
verilator-config.cmake.in
verilator-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX} INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}
) )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/verilator-config.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/verilator-config.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
configure_package_config_file(verilator-config-version.cmake.in verilator-config-version.cmake configure_package_config_file(
verilator-config-version.cmake.in
verilator-config-version.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX} INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}
) )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/verilator-config-version.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/verilator-config-version.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
foreach (program foreach(
program
verilator verilator
verilator_gantt verilator_gantt
verilator_ccache_report verilator_ccache_report
@ -128,13 +156,19 @@ foreach (program
install(PROGRAMS bin/${program} TYPE BIN) install(PROGRAMS bin/${program} TYPE BIN)
endforeach() endforeach()
install(DIRECTORY examples TYPE DATA FILES_MATCHING install(
DIRECTORY examples
TYPE DATA
FILES_MATCHING
PATTERN "examples/*/*.[chv]*" PATTERN "examples/*/*.[chv]*"
PATTERN "examples/*/Makefile*" PATTERN "examples/*/Makefile*"
PATTERN "examples/*/CMakeLists.txt" PATTERN "examples/*/CMakeLists.txt"
) )
install(DIRECTORY include TYPE DATA FILES_MATCHING install(
DIRECTORY include
TYPE DATA
FILES_MATCHING
PATTERN "include/verilated_config.h" PATTERN "include/verilated_config.h"
PATTERN "include/*.[chv]" PATTERN "include/*.[chv]"
PATTERN "include/*.cpp" PATTERN "include/*.cpp"

View File

@ -463,6 +463,14 @@ YAMLFIX = YAMLFIX_WHITELINES=1 YAMLFIX_LINE_LENGTH=130 YAMLFIX_preserve_quotes=t
yamlfix: yamlfix:
$(YAMLFIX) . $(YAMLFIX) .
# CMake files
CMAKE_FILES = \
CMakeLists.txt \
examples/*/CMakeLists.txt \
src/CMakeLists.txt \
test_regress/CMakeLists.txt \
*.cmake.in \
# Python programs, subject to format and lint # Python programs, subject to format and lint
PY_PROGRAMS = \ PY_PROGRAMS = \
bin/verilator_ccache_report \ bin/verilator_ccache_report \
@ -508,6 +516,12 @@ YAPF_FLAGS = -i --parallel
yapf: yapf:
$(YAPF) $(YAPF_FLAGS) $(PY_FILES) $(YAPF) $(YAPF_FLAGS) $(PY_FILES)
GERSEMI = gersemi
GERSEMI_FLAGS = -i
format-cmake:
$(GERSEMI) $(GERSEMI_FLAGS) $(CMAKE_FILES)
PYLINT = pylint PYLINT = pylint
PYLINT_FLAGS = --recursive=n --score=n --disable=R0801 PYLINT_FLAGS = --recursive=n --score=n --disable=R0801
PYLINT_TEST_FLAGS = $(PYLINT_FLAGS) --disable=C0103,C0114,C0116,C0209,C0411,C0413,C0301,R0801,R0912,R0915,R0916,R1702,W0511,W0621 PYLINT_TEST_FLAGS = $(PYLINT_FLAGS) --disable=C0103,C0114,C0116,C0209,C0411,C0413,C0301,R0801,R0912,R0915,R0916,R1702,W0511,W0621

View File

@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW)
project(cmake_hello_c) project(cmake_hello_c)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND) if(NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") message(
FATAL_ERROR
"Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable"
)
endif() endif()
# Create a new executable target that will contain all your sources # Create a new executable target that will contain all your sources
@ -35,4 +38,5 @@ target_compile_features(example PUBLIC cxx_std_14)
# Add the Verilated circuit to the target # Add the Verilated circuit to the target
verilate(example verilate(example
INCLUDE_DIRS "../make_hello_c" INCLUDE_DIRS "../make_hello_c"
SOURCES ../make_hello_c/top.v) SOURCES ../make_hello_c/top.v
)

View File

@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW)
project(cmake_hello_sc CXX) project(cmake_hello_sc CXX)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND) if(NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") message(
FATAL_ERROR
"Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable"
)
endif() endif()
# SystemC dependencies # SystemC dependencies
@ -39,14 +42,12 @@ find_package(SystemCLanguage QUIET)
add_executable(example ../make_hello_sc/sc_main.cpp) add_executable(example ../make_hello_sc/sc_main.cpp)
target_compile_features(example PUBLIC cxx_std_14) target_compile_features(example PUBLIC cxx_std_14)
set_property( set_property(TARGET example PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD})
TARGET example
PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD}
)
# Add the Verilated circuit to the target # Add the Verilated circuit to the target
verilate(example SYSTEMC verilate(example SYSTEMC
INCLUDE_DIRS "../make_hello_sc" INCLUDE_DIRS "../make_hello_sc"
SOURCES ../make_hello_sc/top.v) SOURCES ../make_hello_sc/top.v
)
verilator_link_systemc(example) verilator_link_systemc(example)

View File

@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW)
project(cmake_protect_lib) project(cmake_protect_lib)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND) if(NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") message(
FATAL_ERROR
"Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable"
)
endif() endif()
# Create the main executable target # Create the main executable target
@ -55,9 +58,11 @@ verilate(verilated_secret
VERILATOR_ARGS --protect-lib verilated_secret VERILATOR_ARGS --protect-lib verilated_secret
--protect-key ${PROTECT_KEY} --protect-key ${PROTECT_KEY}
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/verilated_secret DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/verilated_secret
SOURCES ../make_protect_lib/secret_impl.v) SOURCES ../make_protect_lib/secret_impl.v
)
# Include location of verilated_secret.sv wrapper # Include location of verilated_secret.sv wrapper
verilate(example verilate(example
VERILATOR_ARGS "-I${CMAKE_CURRENT_BINARY_DIR}/verilated_secret" VERILATOR_ARGS "-I${CMAKE_CURRENT_BINARY_DIR}/verilated_secret"
SOURCES ../make_protect_lib/top.v) SOURCES ../make_protect_lib/top.v
)

View File

@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW)
project(cmake_tracing_c) project(cmake_tracing_c)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND) if(NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") message(
FATAL_ERROR
"Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable"
)
endif() endif()
# Create a new executable target that will contain all your sources # Create a new executable target that will contain all your sources
@ -36,4 +39,5 @@ target_compile_features(example PUBLIC cxx_std_14)
verilate(example COVERAGE TRACE verilate(example COVERAGE TRACE
INCLUDE_DIRS "../make_tracing_c" INCLUDE_DIRS "../make_tracing_c"
VERILATOR_ARGS -f ../make_tracing_c/input.vc -x-assign fast VERILATOR_ARGS -f ../make_tracing_c/input.vc -x-assign fast
SOURCES ../make_tracing_c/top.v) SOURCES ../make_tracing_c/top.v
)

View File

@ -25,8 +25,11 @@ cmake_policy(SET CMP0074 NEW)
project(cmake_tracing_sc_example CXX) project(cmake_tracing_sc_example CXX)
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
if (NOT verilator_FOUND) if(NOT verilator_FOUND)
message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") message(
FATAL_ERROR
"Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable"
)
endif() endif()
# SystemC dependencies # SystemC dependencies
@ -40,15 +43,13 @@ find_package(SystemCLanguage QUIET)
add_executable(example ../make_tracing_sc/sc_main.cpp) add_executable(example ../make_tracing_sc/sc_main.cpp)
target_compile_features(example PUBLIC cxx_std_14) target_compile_features(example PUBLIC cxx_std_14)
set_property( set_property(TARGET example PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD})
TARGET example
PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD}
)
# Add the Verilated circuit to the target # Add the Verilated circuit to the target
verilate(example SYSTEMC COVERAGE TRACE verilate(example SYSTEMC COVERAGE TRACE
INCLUDE_DIRS "../make_tracing_sc" INCLUDE_DIRS "../make_tracing_sc"
VERILATOR_ARGS -f ../make_tracing_sc/input.vc -x-assign fast VERILATOR_ARGS -f ../make_tracing_sc/input.vc -x-assign fast
SOURCES ../make_tracing_sc/top.v) SOURCES ../make_tracing_sc/top.v
)
verilator_link_systemc(example) verilator_link_systemc(example)

View File

@ -14,14 +14,23 @@
# #
# Utilities # Utilities
macro (addBuildType sourceConfig newConfig) macro(addBuildType sourceConfig newConfig)
get_cmake_property(variableNames VARIABLES) get_cmake_property(variableNames VARIABLES)
foreach (variableName ${variableNames}) foreach(variableName ${variableNames})
if (variableName MATCHES "^CMAKE_.*_${sourceConfig}(|_.*)$") if(variableName MATCHES "^CMAKE_.*_${sourceConfig}(|_.*)$")
string(REPLACE _${sourceConfig} _${newConfig} newVariableName ${variableName}) string(
REPLACE
_${sourceConfig}
_${newConfig}
newVariableName
${variableName}
)
set(${newVariableName} ${${variableName}}) set(${newVariableName} ${${variableName}})
mark_as_advanced(${newVariableName}) mark_as_advanced(${newVariableName})
message(DEBUG " Propagating ${variableName} to ${newVariableName} = ${${newVariableName}}") message(
DEBUG
" Propagating ${variableName} to ${newVariableName} = ${${newVariableName}}"
)
endif() endif()
endforeach() endforeach()
endmacro() endmacro()
@ -327,9 +336,7 @@ set(COMMON_SOURCES
V3PreProc.cpp V3PreProc.cpp
) )
SET(COVERAGE_SOURCES set(COVERAGE_SOURCES VlcMain.cpp)
VlcMain.cpp
)
# Note about tests: # Note about tests:
# VlcMain.cpp #includes the following files: # VlcMain.cpp #includes the following files:
@ -352,34 +359,49 @@ configure_file(config_package.h.in config_package.h @ONLY)
add_custom_command( add_custom_command(
OUTPUT V3Ast__gen_forward_class_decls.h V3Dfg__gen_forward_class_decls.h OUTPUT V3Ast__gen_forward_class_decls.h V3Dfg__gen_forward_class_decls.h
DEPENDS ./V3Ast.h ${ASTGEN} DEPENDS ./V3Ast.h ${ASTGEN}
COMMAND ${PYTHON3} ARGS COMMAND ${PYTHON3}
${ASTGEN} -I "${srcdir}" --astdef V3AstNodeDType.h --astdef V3AstNodeExpr.h --astdef V3AstNodeOther.h --dfgdef V3DfgVertices.h --classes ARGS
${ASTGEN} -I "${srcdir}" --astdef V3AstNodeDType.h --astdef
V3AstNodeExpr.h --astdef V3AstNodeOther.h --dfgdef V3DfgVertices.h
--classes
)
list(
APPEND
GENERATED_FILES
V3Ast__gen_forward_class_decls.h
V3Dfg__gen_forward_class_decls.h
) )
list(APPEND GENERATED_FILES V3Ast__gen_forward_class_decls.h V3Dfg__gen_forward_class_decls.h)
# Output used directly by the `verilator` target # Output used directly by the `verilator` target
set(verilog_y "${srcdir}/verilog.y" ) set(verilog_y "${srcdir}/verilog.y")
set(BISON_V3ParseBison_OUTPUT_HEADER "${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.h") set(BISON_V3ParseBison_OUTPUT_HEADER
set(BISON_V3ParseBison_OUTPUT_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.c") "${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.h"
)
set(BISON_V3ParseBison_OUTPUT_SOURCE
"${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.c"
)
add_custom_command( add_custom_command(
OUTPUT V3ParseBison.c V3ParseBison.h OUTPUT V3ParseBison.c V3ParseBison.h
MAIN_DEPENDENCY ./verilog.y MAIN_DEPENDENCY ./verilog.y
DEPENDS ${BISONPRE} DEPENDS ${BISONPRE}
COMMAND ${PYTHON3} ARGS COMMAND ${PYTHON3}
${BISONPRE} --yacc "${BISON_EXECUTABLE}" -d -v ARGS
-o "${BISON_V3ParseBison_OUTPUT_SOURCE}" "${verilog_y}" ${BISONPRE} --yacc "${BISON_EXECUTABLE}" -d -v -o
"${BISON_V3ParseBison_OUTPUT_SOURCE}" "${verilog_y}"
) )
list(APPEND GENERATED_FILES V3ParseBison.c V3ParseBison.h) list(APPEND GENERATED_FILES V3ParseBison.c V3ParseBison.h)
# Output used directly by the `verilator` target # Output used directly by the `verilator` target
set(verilog_l "${srcdir}/verilog.l") set(verilog_l "${srcdir}/verilog.l")
set(FLEX_V3Lexer_pregen_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/V3Lexer_pregen.yy.cpp") set(FLEX_V3Lexer_pregen_OUTPUTS
"${CMAKE_CURRENT_BINARY_DIR}/V3Lexer_pregen.yy.cpp"
)
add_custom_command( add_custom_command(
OUTPUT V3Lexer_pregen.yy.cpp OUTPUT V3Lexer_pregen.yy.cpp
MAIN_DEPENDENCY ./verilog.l MAIN_DEPENDENCY ./verilog.l
DEPENDS ${BISON_V3ParseBison_OUTPUT_HEADER} ${HEADERS} DEPENDS ${BISON_V3ParseBison_OUTPUT_HEADER} ${HEADERS}
COMMAND ${FLEX_EXECUTABLE} ARGS COMMAND ${FLEX_EXECUTABLE}
${LFLAGS} -o "${FLEX_V3Lexer_pregen_OUTPUTS}" "${verilog_l}" ARGS ${LFLAGS} -o "${FLEX_V3Lexer_pregen_OUTPUTS}" "${verilog_l}"
) )
# Output used by another command # Output used by another command
@ -388,19 +410,26 @@ add_custom_command(
OUTPUT V3Lexer.yy.cpp OUTPUT V3Lexer.yy.cpp
MAIN_DEPENDENCY ${FLEX_V3Lexer_pregen_OUTPUTS} MAIN_DEPENDENCY ${FLEX_V3Lexer_pregen_OUTPUTS}
DEPENDS ${FLEXFIX} DEPENDS ${FLEXFIX}
COMMAND ${PYTHON3} ARGS COMMAND ${PYTHON3}
${FLEXFIX} V3Lexer < "$<SHELL_PATH:${FLEX_V3Lexer_pregen_OUTPUTS}>" > "$<SHELL_PATH:${FLEX_V3Lexer_OUTPUTS}>" ARGS
${FLEXFIX} V3Lexer < "$<SHELL_PATH:${FLEX_V3Lexer_pregen_OUTPUTS}>" >
"$<SHELL_PATH:${FLEX_V3Lexer_OUTPUTS}>"
)
add_custom_target(
V3Lexer_yy_cpp${CMAKE_BUILD_TYPE}
DEPENDS ${FLEX_V3Lexer_OUTPUTS}
) )
add_custom_target(V3Lexer_yy_cpp${CMAKE_BUILD_TYPE} DEPENDS ${FLEX_V3Lexer_OUTPUTS})
# Output included by another source file # Output included by another source file
set(FLEX_V3PreLex_pregen_OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/V3PreLex_pregen.yy.cpp) set(FLEX_V3PreLex_pregen_OUTPUTS
${CMAKE_CURRENT_BINARY_DIR}/V3PreLex_pregen.yy.cpp
)
add_custom_command( add_custom_command(
OUTPUT V3PreLex_pregen.yy.cpp OUTPUT V3PreLex_pregen.yy.cpp
MAIN_DEPENDENCY ./V3PreLex.l MAIN_DEPENDENCY ./V3PreLex.l
DEPENDS ${HEADERS} DEPENDS ${HEADERS}
COMMAND ${FLEX_EXECUTABLE} ARGS COMMAND ${FLEX_EXECUTABLE}
${LFLAGS} -o "${FLEX_V3PreLex_pregen_OUTPUTS}" "${srcdir}/V3PreLex.l" ARGS ${LFLAGS} -o "${FLEX_V3PreLex_pregen_OUTPUTS}" "${srcdir}/V3PreLex.l"
) )
# Output used by another command # Output used by another command
@ -409,37 +438,45 @@ add_custom_command(
OUTPUT V3PreLex.yy.cpp OUTPUT V3PreLex.yy.cpp
MAIN_DEPENDENCY ${FLEX_V3PreLex_pregen_OUTPUTS} MAIN_DEPENDENCY ${FLEX_V3PreLex_pregen_OUTPUTS}
DEPENDS ${FLEXFIX} DEPENDS ${FLEXFIX}
COMMAND ${PYTHON3} ARGS COMMAND ${PYTHON3}
${FLEXFIX} V3PreLex < "$<SHELL_PATH:${FLEX_V3PreLex_pregen_OUTPUTS}>" > "$<SHELL_PATH:${FLEX_V3PreLex_OUTPUTS}>" ARGS
${FLEXFIX} V3PreLex < "$<SHELL_PATH:${FLEX_V3PreLex_pregen_OUTPUTS}>" >
"$<SHELL_PATH:${FLEX_V3PreLex_OUTPUTS}>"
)
add_custom_target(
V3PreLex_yy_cpp${CMAKE_BUILD_TYPE}
DEPENDS ${FLEX_V3PreLex_OUTPUTS}
) )
add_custom_target(V3PreLex_yy_cpp${CMAKE_BUILD_TYPE} DEPENDS ${FLEX_V3PreLex_OUTPUTS})
# Output included by another source file # Output included by another source file
set(gitHead ${srcdir}/../.git/logs/HEAD) set(gitHead ${srcdir}/../.git/logs/HEAD)
if (NOT EXISTS ${githead}) if(NOT EXISTS ${githead})
set(gitHead "") set(gitHead "")
endif() endif()
add_custom_command( add_custom_command(
OUTPUT config_rev.h OUTPUT config_rev.h
MAIN_DEPENDENCY ${gitHead} MAIN_DEPENDENCY ${gitHead}
DEPENDS ${CONFIG_REV} DEPENDS ${CONFIG_REV}
COMMAND ${PYTHON3} ARGS COMMAND ${PYTHON3}
${CONFIG_REV} "${srcdir}" > "$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/config_rev.h>" ARGS
${CONFIG_REV} "${srcdir}" >
"$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/config_rev.h>"
) )
list(APPEND GENERATED_FILES config_rev.h) list(APPEND GENERATED_FILES config_rev.h)
# Output used directly by the `verilator` target # Output used directly by the `verilator` target
set(ASTGENERATED_NAMES set(ASTGENERATED_NAMES V3Const)
V3Const
)
foreach(astgen_name ${ASTGENERATED_NAMES}) foreach(astgen_name ${ASTGENERATED_NAMES})
add_custom_command( add_custom_command(
OUTPUT ${astgen_name}__gen.cpp OUTPUT ${astgen_name}__gen.cpp
MAIN_DEPENDENCY ${astgen_name}.cpp MAIN_DEPENDENCY ${astgen_name}.cpp
DEPENDS ${ASTGEN} V3Ast.h DEPENDS ${ASTGEN} V3Ast.h
COMMAND ${PYTHON3} ARGS COMMAND ${PYTHON3}
${ASTGEN} -I "${srcdir}" --astdef V3AstNodeDType.h --astdef V3AstNodeExpr.h --astdef V3AstNodeOther.h --dfgdef V3DfgVertices.h ${astgen_name}.cpp ARGS
${ASTGEN} -I "${srcdir}" --astdef V3AstNodeDType.h --astdef
V3AstNodeExpr.h --astdef V3AstNodeOther.h --dfgdef V3DfgVertices.h
${astgen_name}.cpp
) )
list(APPEND GENERATED_FILES ${astgen_name}__gen.cpp) list(APPEND GENERATED_FILES ${astgen_name}__gen.cpp)
endforeach() endforeach()
@ -447,7 +484,7 @@ endforeach()
# #
# Set up the Coverage build type # Set up the Coverage build type
addBuildType(DEBUG COVERAGE) addbuildtype(DEBUG COVERAGE)
# This regenerates include/verilated_cov_key.h in the source tree. # This regenerates include/verilated_cov_key.h in the source tree.
# It is a custom_target, not custom_command, because vlcovgen.d is # It is a custom_target, not custom_command, because vlcovgen.d is
@ -456,8 +493,7 @@ add_custom_target(
vlcovgen.d${CMAKE_BUILD_TYPE} vlcovgen.d${CMAKE_BUILD_TYPE}
DEPENDS ../include/verilated_cov_key.h ${VLCOVGEN} DEPENDS ../include/verilated_cov_key.h ${VLCOVGEN}
COMMENT "Updating include/verilated_cov_key.h" COMMENT "Updating include/verilated_cov_key.h"
COMMAND ${PYTHON3} COMMAND ${PYTHON3} ${VLCOVGEN} --srcdir ${srcdir}
${VLCOVGEN} --srcdir ${srcdir}
) )
# #
@ -465,13 +501,17 @@ add_custom_target(
set(verilator verilator${CMAKE_BUILD_TYPE}) set(verilator verilator${CMAKE_BUILD_TYPE})
add_executable(${verilator} add_executable(
${verilator}
$<$<NOT:$<CONFIG:COVERAGE>>:${COMMON_SOURCES}> $<$<NOT:$<CONFIG:COVERAGE>>:${COMMON_SOURCES}>
$<$<NOT:$<CONFIG:COVERAGE>>:${GENERATED_FILES}> $<$<NOT:$<CONFIG:COVERAGE>>:${GENERATED_FILES}>
$<$<CONFIG:COVERAGE>:${COVERAGE_SOURCES} config_rev.h> $<$<CONFIG:COVERAGE>:${COVERAGE_SOURCES}
config_rev.h>
) )
set_target_properties(${verilator} PROPERTIES set_target_properties(
${verilator}
PROPERTIES
OUTPUT_NAME_RELEASE verilator_bin OUTPUT_NAME_RELEASE verilator_bin
OUTPUT_NAME_DEBUG verilator_bin_dbg OUTPUT_NAME_DEBUG verilator_bin_dbg
OUTPUT_NAME_COVERAGE verilator_coverage_bin_dbg OUTPUT_NAME_COVERAGE verilator_coverage_bin_dbg
@ -482,7 +522,8 @@ set_target_properties(${verilator} PROPERTIES
INCLUDE_DIRECTORIES ${FLEX_INCLUDE_DIR} INCLUDE_DIRECTORIES ${FLEX_INCLUDE_DIR}
) )
add_dependencies(${verilator} add_dependencies(
${verilator}
V3Lexer_yy_cpp${CMAKE_BUILD_TYPE} V3Lexer_yy_cpp${CMAKE_BUILD_TYPE}
V3PreLex_yy_cpp${CMAKE_BUILD_TYPE} V3PreLex_yy_cpp${CMAKE_BUILD_TYPE}
) )
@ -492,21 +533,24 @@ target_link_libraries(${verilator} PRIVATE Threads::Threads)
# verilated_cov_key.h is only regenerated in a single-configuration environment. # verilated_cov_key.h is only regenerated in a single-configuration environment.
# This limitation can be lifted when `add_dependencies` will support generator # This limitation can be lifted when `add_dependencies` will support generator
# expressions. See https://gitlab.kitware.com/cmake/cmake/issues/19467 # expressions. See https://gitlab.kitware.com/cmake/cmake/issues/19467
if (CMAKE_BUILD_TYPE STREQUAL Coverage) if(CMAKE_BUILD_TYPE STREQUAL Coverage)
add_dependencies(${verilator} vlcovgen.d${CMAKE_BUILD_TYPE}) add_dependencies(${verilator} vlcovgen.d${CMAKE_BUILD_TYPE})
endif() endif()
if (NOT MSVC) if(NOT MSVC)
target_compile_features(${verilator} PRIVATE cxx_std_11) target_compile_features(${verilator} PRIVATE cxx_std_11)
endif() endif()
target_compile_definitions(${verilator} PRIVATE target_compile_definitions(
${verilator}
PRIVATE
YYDEBUG # Required to get nice error messages YYDEBUG # Required to get nice error messages
$<$<CONFIG:DEBUG>:VL_DEBUG> $<$<CONFIG:DEBUG>:VL_DEBUG>
$<$<CONFIG:DEBUG>:_GLIBCXX_DEBUG> $<$<CONFIG:DEBUG>:_GLIBCXX_DEBUG>
) )
target_include_directories(${verilator} target_include_directories(
${verilator}
PRIVATE PRIVATE
../include ../include
${WIN_FLEX_BISON} ${WIN_FLEX_BISON}
@ -515,18 +559,23 @@ target_include_directories(${verilator}
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
if (WIN32) if(WIN32)
if(MINGW) if(MINGW)
target_compile_options(${verilator} PRIVATE -Wa,-mbig-obj) target_compile_options(${verilator} PRIVATE -Wa,-mbig-obj)
target_link_options(${verilator} PRIVATE -Wl,--stack,10000000 -mconsole -lcomctl32 -DWIN_32_LEAN_AND_MEAN) target_link_options(
${verilator}
PRIVATE
-Wl,--stack,10000000
-mconsole
-lcomctl32
-DWIN_32_LEAN_AND_MEAN
)
else() else()
target_compile_options(${verilator} PRIVATE /bigobj) target_compile_options(${verilator} PRIVATE /bigobj)
target_link_options(${verilator} PRIVATE /STACK:10000000) target_link_options(${verilator} PRIVATE /STACK:10000000)
endif() endif()
target_compile_definitions(${verilator} PRIVATE target_compile_definitions(${verilator} PRIVATE YY_NO_UNISTD_H)
YY_NO_UNISTD_H
)
target_include_directories(${verilator} PRIVATE ../platform/win32) target_include_directories(${verilator} PRIVATE ../platform/win32)
target_link_libraries(${verilator} PRIVATE bcrypt psapi) target_link_libraries(${verilator} PRIVATE bcrypt psapi)
endif() endif()

View File

@ -14,12 +14,24 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
cmake_policy(SET CMP0074 NEW) cmake_policy(SET CMP0074 NEW)
set(TEST_REQUIRED_VARS NAME CSOURCES OPT_FAST OPT_GLOBAL set(TEST_REQUIRED_VARS
VERILATOR_ROOT VERILATOR_ARGS NAME
VERILATOR_SOURCES SYSTEMC VERBOSE VERILATION) CSOURCES
OPT_FAST
OPT_GLOBAL
VERILATOR_ROOT
VERILATOR_ARGS
VERILATOR_SOURCES
SYSTEMC
VERBOSE
VERILATION
)
foreach(var ${TEST_REQUIRED_VARS}) foreach(var ${TEST_REQUIRED_VARS})
if (NOT DEFINED TEST_${var}) if(NOT DEFINED TEST_${var})
message(FATAL_ERROR "TEST_${var} not defined. This CMakeLists.txt file is meant to be run by driver.py.") message(
FATAL_ERROR
"TEST_${var} not defined. This CMakeLists.txt file is meant to be run by driver.py."
)
endif() endif()
endforeach() endforeach()
@ -47,24 +59,40 @@ function(getarg LST ARG OUT)
endfunction() endfunction()
# Normalise -- to - # Normalise -- to -
string(REGEX REPLACE "(^|;)--" "\\1-" string(
REGEX REPLACE
"(^|;)--"
"\\1-"
TEST_VERILATOR_ARGS_NORM TEST_VERILATOR_ARGS_NORM
"${TEST_VERILATOR_ARGS}") "${TEST_VERILATOR_ARGS}"
)
getarg(TEST_VERILATOR_ARGS_NORM "-prefix" TEST_PREFIX) getarg(TEST_VERILATOR_ARGS_NORM "-prefix" TEST_PREFIX)
getarg(TEST_VERILATOR_ARGS_NORM "-threads" TEST_THREADS) getarg(TEST_VERILATOR_ARGS_NORM "-threads" TEST_THREADS)
getarg(TEST_VERILATOR_ARGS_NORM "-trace-threads" TEST_TRACE_THREADS) getarg(TEST_VERILATOR_ARGS_NORM "-trace-threads" TEST_TRACE_THREADS)
# Strip unwanted args with 1 parameter # Strip unwanted args with 1 parameter
string(REGEX REPLACE "(^|;)--?(Mdir|make|prefix|threads|trace-threads);[^;]*" "" string(
REGEX REPLACE
"(^|;)--?(Mdir|make|prefix|threads|trace-threads);[^;]*"
""
TEST_VERILATOR_ARGS TEST_VERILATOR_ARGS
"${TEST_VERILATOR_ARGS}") "${TEST_VERILATOR_ARGS}"
)
# Strip unwanted args # Strip unwanted args
string(REGEX REPLACE "(^|;)--?(sc|cc)" "" string(
REGEX REPLACE
"(^|;)--?(sc|cc)"
""
TEST_VERILATOR_ARGS TEST_VERILATOR_ARGS
"${TEST_VERILATOR_ARGS}") "${TEST_VERILATOR_ARGS}"
)
separate_arguments(TEST_VERILATOR_SOURCES UNIX_COMMAND "${TEST_VERILATOR_SOURCES}") separate_arguments(
TEST_VERILATOR_SOURCES
UNIX_COMMAND
"${TEST_VERILATOR_SOURCES}"
)
# filter out empty sources # filter out empty sources
list(FILTER TEST_VERILATOR_SOURCES EXCLUDE REGEX "$^") list(FILTER TEST_VERILATOR_SOURCES EXCLUDE REGEX "$^")
@ -98,7 +126,8 @@ if(TEST_VERILATION)
verilate(${TARGET_NAME} ${verilate_ARGS} verilate(${TARGET_NAME} ${verilate_ARGS}
VERILATOR_ARGS ${TEST_VERILATOR_ARGS} VERILATOR_ARGS ${TEST_VERILATOR_ARGS}
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${TEST_VERILATOR_SOURCES}) SOURCES ${TEST_VERILATOR_SOURCES}
)
endif() endif()
if(TEST_SYSTEMC) if(TEST_SYSTEMC)
@ -107,7 +136,9 @@ endif()
string(TOUPPER "${TEST_NAME}" TEST_NAME_UC) string(TOUPPER "${TEST_NAME}" TEST_NAME_UC)
target_compile_definitions(${TARGET_NAME} PRIVATE target_compile_definitions(
${TARGET_NAME}
PRIVATE
"TEST_OBJ_DIR=${CMAKE_CURRENT_BINARY_DIR}" "TEST_OBJ_DIR=${CMAKE_CURRENT_BINARY_DIR}"
"VM_PREFIX=${TEST_PREFIX}" "VM_PREFIX=${TEST_PREFIX}"
"VM_PREFIX_INCLUDE=<${TEST_PREFIX}.h>" "VM_PREFIX_INCLUDE=<${TEST_PREFIX}.h>"

View File

@ -22,21 +22,30 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
# Prefer VERILATOR_ROOT from environment # Prefer VERILATOR_ROOT from environment
if (DEFINED ENV{VERILATOR_ROOT}) if(DEFINED ENV{VERILATOR_ROOT})
set(VERILATOR_ROOT "$ENV{VERILATOR_ROOT}" CACHE PATH "VERILATOR_ROOT") set(VERILATOR_ROOT "$ENV{VERILATOR_ROOT}" CACHE PATH "VERILATOR_ROOT")
endif() endif()
set(VERILATOR_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "VERILATOR_ROOT") set(VERILATOR_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "VERILATOR_ROOT")
find_program(VERILATOR_BIN NAMES verilator_bin verilator_bin.exe find_program(
HINTS ${VERILATOR_ROOT}/bin ENV VERILATOR_ROOT VERILATOR_BIN
NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) NAMES verilator_bin verilator_bin.exe
HINTS ${VERILATOR_ROOT}/bin
ENV VERILATOR_ROOT
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
)
if (NOT VERILATOR_ROOT) if(NOT VERILATOR_ROOT)
message(FATAL_ERROR "VERILATOR_ROOT cannot be detected. Set it to the appropriate directory (e.g. /usr/share/verilator) as an environment variable or CMake define.") message(
FATAL_ERROR
"VERILATOR_ROOT cannot be detected. Set it to the appropriate directory (e.g. /usr/share/verilator) as an environment variable or CMake define."
)
endif() endif()
if (NOT VERILATOR_BIN) if(NOT VERILATOR_BIN)
message(FATAL_ERROR "Cannot find verilator_bin excecutable.") message(FATAL_ERROR "Cannot find verilator_bin excecutable.")
endif() endif()
@ -52,102 +61,116 @@ function(_verilator_check_cxx_libraries LIBRARIES RESVAR)
set(CMAKE_REQUIRED_LINK_OPTIONS) set(CMAKE_REQUIRED_LINK_OPTIONS)
set(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES}) set(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES})
set(CMAKE_REQUIRED_QUIET) set(CMAKE_REQUIRED_QUIET)
check_cxx_source_compiles("${_VERILATOR_CHECK_CXX_LINK_OPTIONS_SRC}" "${RESVAR}") check_cxx_source_compiles(
"${_VERILATOR_CHECK_CXX_LINK_OPTIONS_SRC}"
"${RESVAR}"
)
set("${RESVAR}" "${${RESVAR}}" PARENT_SCOPE) set("${RESVAR}" "${${RESVAR}}" PARENT_SCOPE)
endfunction() endfunction()
# Check compiler flag support. Skip on MSVC, these are all GCC flags. # Check compiler flag support. Skip on MSVC, these are all GCC flags.
if (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC) if(NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
if (NOT DEFINED VERILATOR_CFLAGS OR NOT DEFINED VERILATOR_MT_CFLAGS) if(NOT DEFINED VERILATOR_CFLAGS OR NOT DEFINED VERILATOR_MT_CFLAGS)
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
foreach (FLAG @CFG_CXX_FLAGS_CMAKE@) foreach(FLAG @CFG_CXX_FLAGS_CMAKE@)
string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME) string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME)
check_cxx_compiler_flag(${FLAG} ${FLAGNAME}) check_cxx_compiler_flag(${FLAG} ${FLAGNAME})
if (${FLAGNAME}) if(${FLAGNAME})
list(APPEND VERILATOR_CFLAGS ${FLAG}) list(APPEND VERILATOR_CFLAGS ${FLAG})
endif() endif()
endforeach() endforeach()
foreach (FLAG @CFG_LDFLAGS_THREADS_CMAKE@) foreach(FLAG @CFG_LDFLAGS_THREADS_CMAKE@)
string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME) string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME)
_verilator_check_cxx_libraries("${FLAG}" ${FLAGNAME}) _verilator_check_cxx_libraries("${FLAG}" ${FLAGNAME})
if (${FLAGNAME}) if(${FLAGNAME})
list(APPEND VERILATOR_MT_CFLAGS ${FLAG}) list(APPEND VERILATOR_MT_CFLAGS ${FLAG})
endif() endif()
endforeach() endforeach()
endif() endif()
endif() endif()
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang") if(${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
add_link_options(-Wl,-U,__Z15vl_time_stamp64v,-U,__Z13sc_time_stampv) add_link_options(-Wl,-U,__Z15vl_time_stamp64v,-U,__Z13sc_time_stampv)
endif() endif()
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_THREADED PROPERTY VERILATOR_THREADED
BRIEF_DOCS "Deprecated and has no effect (ignored)" BRIEF_DOCS "Deprecated and has no effect (ignored)"
FULL_DOCS "Deprecated and has no effect (ignored)" FULL_DOCS "Deprecated and has no effect (ignored)"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_TRACE_THREADED PROPERTY VERILATOR_TRACE_THREADED
BRIEF_DOCS "Verilator multithread tracing enabled" BRIEF_DOCS "Verilator multithread tracing enabled"
FULL_DOCS "Verilator multithread tracing enabled" FULL_DOCS "Verilator multithread tracing enabled"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_TIMING PROPERTY VERILATOR_TIMING
BRIEF_DOCS "Verilator timing enabled" BRIEF_DOCS "Verilator timing enabled"
FULL_DOCS "Verilator timing enabled" FULL_DOCS "Verilator timing enabled"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_COVERAGE PROPERTY VERILATOR_COVERAGE
BRIEF_DOCS "Verilator coverage enabled" BRIEF_DOCS "Verilator coverage enabled"
FULL_DOCS "Verilator coverage enabled" FULL_DOCS "Verilator coverage enabled"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_TRACE PROPERTY VERILATOR_TRACE
BRIEF_DOCS "Verilator trace enabled" BRIEF_DOCS "Verilator trace enabled"
FULL_DOCS "Verilator trace enabled" FULL_DOCS "Verilator trace enabled"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_TRACE_VCD PROPERTY VERILATOR_TRACE_VCD
BRIEF_DOCS "Verilator VCD trace enabled" BRIEF_DOCS "Verilator VCD trace enabled"
FULL_DOCS "Verilator VCD trace enabled" FULL_DOCS "Verilator VCD trace enabled"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_TRACE_FST PROPERTY VERILATOR_TRACE_FST
BRIEF_DOCS "Verilator FST trace enabled" BRIEF_DOCS "Verilator FST trace enabled"
FULL_DOCS "Verilator FST trace enabled" FULL_DOCS "Verilator FST trace enabled"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_SYSTEMC PROPERTY VERILATOR_SYSTEMC
BRIEF_DOCS "Verilator SystemC enabled" BRIEF_DOCS "Verilator SystemC enabled"
FULL_DOCS "Verilator SystemC enabled" FULL_DOCS "Verilator SystemC enabled"
) )
define_property(TARGET define_property(
TARGET
PROPERTY VERILATOR_TRACE_STRUCTS PROPERTY VERILATOR_TRACE_STRUCTS
BRIEF_DOCS "Verilator trace structs enabled" BRIEF_DOCS "Verilator trace structs enabled"
FULL_DOCS "Verilator trace structs enabled" FULL_DOCS "Verilator trace structs enabled"
) )
function(verilate TARGET) function(verilate TARGET)
cmake_parse_arguments(VERILATE "COVERAGE;TRACE;TRACE_FST;SYSTEMC;TRACE_STRUCTS" cmake_parse_arguments(
VERILATE
"COVERAGE;TRACE;TRACE_FST;SYSTEMC;TRACE_STRUCTS"
"PREFIX;TOP_MODULE;THREADS;TRACE_THREADS;DIRECTORY" "PREFIX;TOP_MODULE;THREADS;TRACE_THREADS;DIRECTORY"
"SOURCES;VERILATOR_ARGS;INCLUDE_DIRS;OPT_SLOW;OPT_FAST;OPT_GLOBAL" "SOURCES;VERILATOR_ARGS;INCLUDE_DIRS;OPT_SLOW;OPT_FAST;OPT_GLOBAL"
${ARGN}) ${ARGN}
if (NOT VERILATE_SOURCES) )
if(NOT VERILATE_SOURCES)
message(FATAL_ERROR "Need at least one source") message(FATAL_ERROR "Need at least one source")
endif() endif()
if (NOT VERILATE_PREFIX) if(NOT VERILATE_PREFIX)
list(LENGTH VERILATE_SOURCES NUM_SOURCES) list(LENGTH VERILATE_SOURCES NUM_SOURCES)
if (${NUM_SOURCES} GREATER 1) if(${NUM_SOURCES} GREATER 1)
message(WARNING "Specify PREFIX if there are multiple SOURCES") message(WARNING "Specify PREFIX if there are multiple SOURCES")
endif() endif()
list(GET VERILATE_SOURCES 0 TOPSRC) list(GET VERILATE_SOURCES 0 TOPSRC)
@ -155,41 +178,41 @@ function(verilate TARGET)
string(MAKE_C_IDENTIFIER V${_SRC_NAME} VERILATE_PREFIX) string(MAKE_C_IDENTIFIER V${_SRC_NAME} VERILATE_PREFIX)
endif() endif()
if (VERILATE_TOP_MODULE) if(VERILATE_TOP_MODULE)
list(APPEND VERILATOR_ARGS --top ${VERILATE_TOP_MODULE}) list(APPEND VERILATOR_ARGS --top ${VERILATE_TOP_MODULE})
endif() endif()
if (VERILATE_THREADS) if(VERILATE_THREADS)
list(APPEND VERILATOR_ARGS --threads ${VERILATE_THREADS}) list(APPEND VERILATOR_ARGS --threads ${VERILATE_THREADS})
endif() endif()
if (VERILATE_TRACE_THREADS) if(VERILATE_TRACE_THREADS)
list(APPEND VERILATOR_ARGS --trace-threads ${VERILATE_TRACE_THREADS}) list(APPEND VERILATOR_ARGS --trace-threads ${VERILATE_TRACE_THREADS})
endif() endif()
if (VERILATE_COVERAGE) if(VERILATE_COVERAGE)
list(APPEND VERILATOR_ARGS --coverage) list(APPEND VERILATOR_ARGS --coverage)
endif() endif()
if (VERILATE_TRACE AND VERILATE_TRACE_FST) if(VERILATE_TRACE AND VERILATE_TRACE_FST)
message(FATAL_ERROR "Cannot have both TRACE and TRACE_FST") message(FATAL_ERROR "Cannot have both TRACE and TRACE_FST")
endif() endif()
if (VERILATE_TRACE) if(VERILATE_TRACE)
list(APPEND VERILATOR_ARGS --trace) list(APPEND VERILATOR_ARGS --trace)
endif() endif()
if (VERILATE_TRACE_FST) if(VERILATE_TRACE_FST)
list(APPEND VERILATOR_ARGS --trace-fst) list(APPEND VERILATOR_ARGS --trace-fst)
endif() endif()
if (VERILATE_SYSTEMC) if(VERILATE_SYSTEMC)
list(APPEND VERILATOR_ARGS --sc) list(APPEND VERILATOR_ARGS --sc)
else() else()
list(APPEND VERILATOR_ARGS --cc) list(APPEND VERILATOR_ARGS --cc)
endif() endif()
if (VERILATE_TRACE_STRUCTS) if(VERILATE_TRACE_STRUCTS)
list(APPEND VERILATOR_ARGS --trace-structs) list(APPEND VERILATOR_ARGS --trace-structs)
endif() endif()
@ -198,33 +221,48 @@ function(verilate TARGET)
endforeach() endforeach()
string(TOLOWER ${CMAKE_CXX_COMPILER_ID} COMPILER) string(TOLOWER ${CMAKE_CXX_COMPILER_ID} COMPILER)
if (COMPILER STREQUAL "appleclang") if(COMPILER STREQUAL "appleclang")
set(COMPILER clang) set(COMPILER clang)
elseif (NOT COMPILER MATCHES "^msvc$|^clang$") elseif(NOT COMPILER MATCHES "^msvc$|^clang$")
set(COMPILER gcc) set(COMPILER gcc)
endif() endif()
get_target_property(BINARY_DIR "${TARGET}" BINARY_DIR) get_target_property(BINARY_DIR "${TARGET}" BINARY_DIR)
get_target_property(TARGET_NAME "${TARGET}" NAME) get_target_property(TARGET_NAME "${TARGET}" NAME)
set(VDIR "${BINARY_DIR}/CMakeFiles/${TARGET_NAME}.dir/${VERILATE_PREFIX}.dir") set(VDIR
"${BINARY_DIR}/CMakeFiles/${TARGET_NAME}.dir/${VERILATE_PREFIX}.dir"
)
if (VERILATE_DIRECTORY) if(VERILATE_DIRECTORY)
set(VDIR "${VERILATE_DIRECTORY}") set(VDIR "${VERILATE_DIRECTORY}")
endif() endif()
file(MAKE_DIRECTORY ${VDIR}) file(MAKE_DIRECTORY ${VDIR})
set(VERILATOR_COMMAND "${CMAKE_COMMAND}" -E env "VERILATOR_ROOT=${VERILATOR_ROOT}" set(VERILATOR_COMMAND
"${VERILATOR_BIN}" --compiler ${COMPILER} "${CMAKE_COMMAND}"
--prefix ${VERILATE_PREFIX} --Mdir ${VDIR} --make cmake -E
${VERILATOR_ARGS} ${VERILATE_VERILATOR_ARGS} env
${VERILATE_SOURCES}) "VERILATOR_ROOT=${VERILATOR_ROOT}"
"${VERILATOR_BIN}"
--compiler
${COMPILER}
--prefix
${VERILATE_PREFIX}
--Mdir
${VDIR}
--make
cmake
${VERILATOR_ARGS}
${VERILATE_VERILATOR_ARGS}
${VERILATE_SOURCES}
)
set(VARGS_FILE "${VDIR}/verilator_args.txt") set(VARGS_FILE "${VDIR}/verilator_args.txt")
set(VCMAKE "${VDIR}/${VERILATE_PREFIX}.cmake") set(VCMAKE "${VDIR}/${VERILATE_PREFIX}.cmake")
set(VCMAKE_COPY "${VDIR}/${VERILATE_PREFIX}_copy.cmake") set(VCMAKE_COPY "${VDIR}/${VERILATE_PREFIX}_copy.cmake")
if (NOT EXISTS "${VARGS_FILE}" OR NOT EXISTS "${VCMAKE_COPY}") if(NOT EXISTS "${VARGS_FILE}" OR NOT EXISTS "${VCMAKE_COPY}")
set(VERILATOR_OUTDATED ON) set(VERILATOR_OUTDATED ON)
else() else()
file(READ "${VARGS_FILE}" PREVIOUS_VERILATOR_COMMAND) file(READ "${VARGS_FILE}" PREVIOUS_VERILATOR_COMMAND)
@ -233,75 +271,100 @@ function(verilate TARGET)
endif() endif()
endif() endif()
if (VERILATOR_OUTDATED) if(VERILATOR_OUTDATED)
message(STATUS "Executing Verilator...") message(STATUS "Executing Verilator...")
execute_process( execute_process(
COMMAND ${VERILATOR_COMMAND} COMMAND ${VERILATOR_COMMAND}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE _VERILATOR_RC RESULT_VARIABLE _VERILATOR_RC
OUTPUT_VARIABLE _VERILATOR_OUTPUT OUTPUT_VARIABLE _VERILATOR_OUTPUT
ERROR_VARIABLE _VERILATOR_OUTPUT) ERROR_VARIABLE _VERILATOR_OUTPUT
if (_VERILATOR_RC) )
string(REPLACE ";" " " VERILATOR_COMMAND_READABLE "${VERILATOR_COMMAND}") if(_VERILATOR_RC)
string(
REPLACE
";"
" "
VERILATOR_COMMAND_READABLE
"${VERILATOR_COMMAND}"
)
message("Verilator command: \"${VERILATOR_COMMAND_READABLE}\"") message("Verilator command: \"${VERILATOR_COMMAND_READABLE}\"")
message("Output:\n${_VERILATOR_OUTPUT}") message("Output:\n${_VERILATOR_OUTPUT}")
message(FATAL_ERROR "Verilator command failed (return code=${_VERILATOR_RC})") message(
FATAL_ERROR
"Verilator command failed (return code=${_VERILATOR_RC})"
)
endif() endif()
execute_process(COMMAND "${CMAKE_COMMAND}" -E copy "${VCMAKE}" "${VCMAKE_COPY}") execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy "${VCMAKE}" "${VCMAKE_COPY}"
)
endif() endif()
file(WRITE "${VARGS_FILE}" "${VERILATOR_COMMAND}") file(WRITE "${VARGS_FILE}" "${VERILATOR_COMMAND}")
include("${VCMAKE_COPY}") include("${VCMAKE_COPY}")
set(GENERATED_C_SOURCES ${${VERILATE_PREFIX}_CLASSES_FAST} set(GENERATED_C_SOURCES
${${VERILATE_PREFIX}_CLASSES_FAST}
${${VERILATE_PREFIX}_CLASSES_SLOW} ${${VERILATE_PREFIX}_CLASSES_SLOW}
${${VERILATE_PREFIX}_SUPPORT_FAST} ${${VERILATE_PREFIX}_SUPPORT_FAST}
${${VERILATE_PREFIX}_SUPPORT_SLOW}) ${${VERILATE_PREFIX}_SUPPORT_SLOW}
)
# No need for .h's as the .cpp will get written same time # No need for .h's as the .cpp will get written same time
set(GENERATED_SOURCES ${GENERATED_C_SOURCES}) set(GENERATED_SOURCES ${GENERATED_C_SOURCES})
add_custom_command(OUTPUT ${GENERATED_SOURCES} "${VCMAKE}" add_custom_command(
OUTPUT ${GENERATED_SOURCES} "${VCMAKE}"
COMMAND ${VERILATOR_COMMAND} COMMAND ${VERILATOR_COMMAND}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS "${VERILATOR_BIN}" ${${VERILATE_PREFIX}_DEPS} VERBATIM) DEPENDS "${VERILATOR_BIN}" ${${VERILATE_PREFIX}_DEPS}
VERBATIM
)
# Reconfigure if file list has changed # Reconfigure if file list has changed
# (check contents rather than modified time to avoid unnecessary reconfiguration) # (check contents rather than modified time to avoid unnecessary reconfiguration)
add_custom_command(OUTPUT "${VCMAKE_COPY}" add_custom_command(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different OUTPUT "${VCMAKE_COPY}"
"${VCMAKE}" "${VCMAKE_COPY}" COMMAND
DEPENDS "${VCMAKE}" VERBATIM) "${CMAKE_COMMAND}" -E copy_if_different "${VCMAKE}" "${VCMAKE_COPY}"
DEPENDS "${VCMAKE}"
VERBATIM
)
if (${VERILATE_PREFIX}_COVERAGE) if(${VERILATE_PREFIX}_COVERAGE)
# If any verilate() call specifies COVERAGE, define VM_COVERAGE in the final build # If any verilate() call specifies COVERAGE, define VM_COVERAGE in the final build
set_property(TARGET ${TARGET} PROPERTY VERILATOR_COVERAGE ON) set_property(TARGET ${TARGET} PROPERTY VERILATOR_COVERAGE ON)
endif() endif()
if (${VERILATE_PREFIX}_TRACE_VCD) if(${VERILATE_PREFIX}_TRACE_VCD)
# If any verilate() call specifies TRACE, define VM_TRACE in the final build # If any verilate() call specifies TRACE, define VM_TRACE in the final build
set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE ON) set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE ON)
set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_VCD ON) set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_VCD ON)
endif() endif()
if (${VERILATE_PREFIX}_TRACE_FST) if(${VERILATE_PREFIX}_TRACE_FST)
# If any verilate() call specifies TRACE_FST, define VM_TRACE_FST in the final build # If any verilate() call specifies TRACE_FST, define VM_TRACE_FST in the final build
set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE ON) set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE ON)
set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_FST ON) set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_FST ON)
endif() endif()
if (${VERILATE_PREFIX}_SC) if(${VERILATE_PREFIX}_SC)
# If any verilate() call specifies SYSTEMC, define VM_SC in the final build # If any verilate() call specifies SYSTEMC, define VM_SC in the final build
set_property(TARGET ${TARGET} PROPERTY VERILATOR_SYSTEMC ON) set_property(TARGET ${TARGET} PROPERTY VERILATOR_SYSTEMC ON)
endif() endif()
if (${VERILATE_PREFIX}_TRACE_STRUCTS) if(${VERILATE_PREFIX}_TRACE_STRUCTS)
set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_STRUCTS ON) set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_STRUCTS ON)
endif() endif()
# Add the compile flags only on Verilated sources # Add the compile flags only on Verilated sources
target_include_directories(${TARGET} PUBLIC ${VDIR}) target_include_directories(${TARGET} PUBLIC ${VDIR})
target_sources(${TARGET} PRIVATE ${GENERATED_SOURCES} "${VCMAKE_COPY}" target_sources(
${TARGET}
PRIVATE
${GENERATED_SOURCES}
"${VCMAKE_COPY}"
${${VERILATE_PREFIX}_GLOBAL} ${${VERILATE_PREFIX}_GLOBAL}
${${VERILATE_PREFIX}_USER_CLASSES}) ${${VERILATE_PREFIX}_USER_CLASSES}
)
foreach(_VSOURCE ${VERILATE_SOURCES} ${${VERILATE_PREFIX}_DEPS}) foreach(_VSOURCE ${VERILATE_SOURCES} ${${VERILATE_PREFIX}_DEPS})
get_filename_component(_VSOURCE "${_VSOURCE}" ABSOLUTE BASE_DIR) get_filename_component(_VSOURCE "${_VSOURCE}" ABSOLUTE BASE_DIR)
list(APPEND VHD_SOURCES "${_VSOURCE}") list(APPEND VHD_SOURCES "${_VSOURCE}")
@ -309,25 +372,53 @@ function(verilate TARGET)
target_sources(${TARGET} PRIVATE ${VHD_SOURCES}) target_sources(${TARGET} PRIVATE ${VHD_SOURCES})
# Add the compile flags only on Verilated sources # Add the compile flags only on Verilated sources
foreach(VSLOW ${${VERILATE_PREFIX}_CLASSES_SLOW} ${${VERILATE_PREFIX}_SUPPORT_SLOW}) foreach(
VSLOW
${${VERILATE_PREFIX}_CLASSES_SLOW}
${${VERILATE_PREFIX}_SUPPORT_SLOW}
)
foreach(OPT_SLOW ${VERILATE_OPT_SLOW} ${${VERILATE_PREFIX}_USER_CFLAGS}) foreach(OPT_SLOW ${VERILATE_OPT_SLOW} ${${VERILATE_PREFIX}_USER_CFLAGS})
set_property(SOURCE "${VSLOW}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_SLOW}") set_property(
SOURCE "${VSLOW}"
APPEND_STRING
PROPERTY COMPILE_FLAGS " ${OPT_SLOW}"
)
endforeach() endforeach()
endforeach() endforeach()
foreach(VFAST ${${VERILATE_PREFIX}_CLASSES_FAST} ${${VERILATE_PREFIX}_SUPPORT_FAST}) foreach(
VFAST
${${VERILATE_PREFIX}_CLASSES_FAST}
${${VERILATE_PREFIX}_SUPPORT_FAST}
)
foreach(OPT_FAST ${VERILATE_OPT_FAST} ${${VERILATE_PREFIX}_USER_CFLAGS}) foreach(OPT_FAST ${VERILATE_OPT_FAST} ${${VERILATE_PREFIX}_USER_CFLAGS})
set_property(SOURCE "${VFAST}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_FAST}") set_property(
SOURCE "${VFAST}"
APPEND_STRING
PROPERTY COMPILE_FLAGS " ${OPT_FAST}"
)
endforeach() endforeach()
endforeach() endforeach()
foreach(VGLOBAL ${${VERILATE_PREFIX}_GLOBAL}) foreach(VGLOBAL ${${VERILATE_PREFIX}_GLOBAL})
foreach(OPT_GLOBAL ${VERILATE_OPT_GLOBAL} ${${VERILATE_PREFIX}_USER_CFLAGS}) foreach(
set_property(SOURCE "${VGLOBAL}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_GLOBAL}") OPT_GLOBAL
${VERILATE_OPT_GLOBAL}
${${VERILATE_PREFIX}_USER_CFLAGS}
)
set_property(
SOURCE "${VGLOBAL}"
APPEND_STRING
PROPERTY COMPILE_FLAGS " ${OPT_GLOBAL}"
)
endforeach() endforeach()
endforeach() endforeach()
target_include_directories(${TARGET} PUBLIC "${VERILATOR_ROOT}/include" target_include_directories(
"${VERILATOR_ROOT}/include/vltstd") ${TARGET}
target_compile_definitions(${TARGET} PRIVATE PUBLIC "${VERILATOR_ROOT}/include" "${VERILATOR_ROOT}/include/vltstd"
)
target_compile_definitions(
${TARGET}
PRIVATE
VM_COVERAGE=$<BOOL:$<TARGET_PROPERTY:VERILATOR_COVERAGE>> VM_COVERAGE=$<BOOL:$<TARGET_PROPERTY:VERILATOR_COVERAGE>>
VM_SC=$<BOOL:$<TARGET_PROPERTY:VERILATOR_SYSTEMC>> VM_SC=$<BOOL:$<TARGET_PROPERTY:VERILATOR_SYSTEMC>>
VM_TRACE=$<BOOL:$<TARGET_PROPERTY:VERILATOR_TRACE>> VM_TRACE=$<BOOL:$<TARGET_PROPERTY:VERILATOR_TRACE>>
@ -335,24 +426,24 @@ function(verilate TARGET)
VM_TRACE_FST=$<BOOL:$<TARGET_PROPERTY:VERILATOR_TRACE_FST>> VM_TRACE_FST=$<BOOL:$<TARGET_PROPERTY:VERILATOR_TRACE_FST>>
) )
target_link_libraries(${TARGET} PUBLIC target_link_libraries(${TARGET} PUBLIC ${${VERILATE_PREFIX}_USER_LDLIBS})
${${VERILATE_PREFIX}_USER_LDLIBS}
)
target_link_libraries(${TARGET} PUBLIC target_link_libraries(${TARGET} PUBLIC ${VERILATOR_MT_CFLAGS})
${VERILATOR_MT_CFLAGS}
)
target_compile_features(${TARGET} PRIVATE cxx_std_11) target_compile_features(${TARGET} PRIVATE cxx_std_11)
if (${VERILATE_PREFIX}_TIMING) if(${VERILATE_PREFIX}_TIMING)
check_cxx_compiler_flag(-fcoroutines-ts COROUTINES_TS_FLAG) check_cxx_compiler_flag(-fcoroutines-ts COROUTINES_TS_FLAG)
target_compile_options(${TARGET} PRIVATE $<IF:$<BOOL:${COROUTINES_TS_FLAG}>,-fcoroutines-ts,-fcoroutines>) target_compile_options(
${TARGET}
PRIVATE
$<IF:$<BOOL:${COROUTINES_TS_FLAG}>,-fcoroutines-ts,-fcoroutines>
)
endif() endif()
endfunction() endfunction()
function(_verilator_find_systemc) function(_verilator_find_systemc)
if (NOT TARGET Verilator::systemc) if(NOT TARGET Verilator::systemc)
# Find SystemC include file "systemc.h" in the following order: # Find SystemC include file "systemc.h" in the following order:
# 1. SYSTEMC_INCLUDE (environment) variable # 1. SYSTEMC_INCLUDE (environment) variable
# 2. SYSTEMC_ROOT (environment) variable # 2. SYSTEMC_ROOT (environment) variable
@ -360,14 +451,26 @@ function(_verilator_find_systemc)
# 4. Use CMake module provided by SystemC installation # 4. Use CMake module provided by SystemC installation
# (eventually requires CMAKE_PREFIX_PATH set) # (eventually requires CMAKE_PREFIX_PATH set)
find_path(SYSTEMC_INCLUDEDIR NAMES systemc.h find_path(
HINTS "${SYSTEMC_INCLUDE} " ENV SYSTEMC_INCLUDE) SYSTEMC_INCLUDEDIR
find_path(SYSTEMC_INCLUDEDIR NAMES systemc.h NAMES systemc.h
HINTS "${SYSTEMC_ROOT}" ENV SYSTEMC_ROOT HINTS "${SYSTEMC_INCLUDE} "
PATH_SUFFIXES include) ENV SYSTEMC_INCLUDE
find_path(SYSTEMC_INCLUDEDIR NAMES systemc.h )
HINTS "${SYSTEMC}" ENV SYSTEMC find_path(
PATH_SUFFIXES include) SYSTEMC_INCLUDEDIR
NAMES systemc.h
HINTS "${SYSTEMC_ROOT}"
ENV SYSTEMC_ROOT
PATH_SUFFIXES include
)
find_path(
SYSTEMC_INCLUDEDIR
NAMES systemc.h
HINTS "${SYSTEMC}"
ENV SYSTEMC
PATH_SUFFIXES include
)
# Find SystemC library in the following order: # Find SystemC library in the following order:
# 1. SYSTEMC_LIBDIR (environment) variable # 1. SYSTEMC_LIBDIR (environment) variable
@ -377,38 +480,59 @@ function(_verilator_find_systemc)
# (eventually requires CMAKE_PREFIX_PATH set) # (eventually requires CMAKE_PREFIX_PATH set)
# Find SystemC using include and library paths # Find SystemC using include and library paths
find_library(SYSTEMC_LIBRARY NAMES systemc find_library(
HINTS "${SYSTEMC_LIBDIR}" ENV SYSTEMC_LIBDIR) SYSTEMC_LIBRARY
find_library(SYSTEMC_LIBRARY NAMES systemc NAMES systemc
HINTS "${SYSTEMC_ROOT}" ENV SYSTEMC_ROOT HINTS "${SYSTEMC_LIBDIR}"
PATH_SUFFIXES lib) ENV SYSTEMC_LIBDIR
find_library(SYSTEMC_LIBRARY NAMES systemc )
HINTS "${SYSTEMC}" ENV SYSTEMC find_library(
PATH_SUFFIXES lib) SYSTEMC_LIBRARY
NAMES systemc
HINTS "${SYSTEMC_ROOT}"
ENV SYSTEMC_ROOT
PATH_SUFFIXES lib
)
find_library(
SYSTEMC_LIBRARY
NAMES systemc
HINTS "${SYSTEMC}"
ENV SYSTEMC
PATH_SUFFIXES lib
)
if (SYSTEMC_INCLUDEDIR AND SYSTEMC_LIBRARY) if(SYSTEMC_INCLUDEDIR AND SYSTEMC_LIBRARY)
add_library(Verilator::systemc INTERFACE IMPORTED) add_library(Verilator::systemc INTERFACE IMPORTED)
set_target_properties(Verilator::systemc set_target_properties(
Verilator::systemc
PROPERTIES PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SYSTEMC_INCLUDEDIR}" INTERFACE_INCLUDE_DIRECTORIES "${SYSTEMC_INCLUDEDIR}"
INTERFACE_LINK_LIBRARIES "${SYSTEMC_LIBRARY}") INTERFACE_LINK_LIBRARIES "${SYSTEMC_LIBRARY}"
)
return() return()
endif() endif()
find_package(SystemCLanguage QUIET) find_package(SystemCLanguage QUIET)
if (SystemCLanguage_FOUND) if(SystemCLanguage_FOUND)
add_library(Verilator::systemc INTERFACE IMPORTED) add_library(Verilator::systemc INTERFACE IMPORTED)
set_target_properties(Verilator::systemc set_target_properties(
PROPERTIES Verilator::systemc
INTERFACE_LINK_LIBRARIES "SystemC::systemc") PROPERTIES INTERFACE_LINK_LIBRARIES "SystemC::systemc"
)
return() return()
endif() endif()
message("SystemC not found. This can be fixed by doing either of the following steps:") message(
message("- set the SYSTEMC_INCLUDE and SYSTEMC_LIBDIR (environment) variables; or") "SystemC not found. This can be fixed by doing either of the following steps:"
)
message(
"- set the SYSTEMC_INCLUDE and SYSTEMC_LIBDIR (environment) variables; or"
)
message("- set SYSTEMC_ROOT (environment) variable; or") message("- set SYSTEMC_ROOT (environment) variable; or")
message("- set SYSTEMC (environment) variable; or") message("- set SYSTEMC (environment) variable; or")
message("- use the CMake module of your SystemC installation (may require CMAKE_PREFIX_PATH)") message(
"- use the CMake module of your SystemC installation (may require CMAKE_PREFIX_PATH)"
)
message(FATAL_ERROR "SystemC not found") message(FATAL_ERROR "SystemC not found")
endif() endif()
endfunction() endfunction()
@ -416,14 +540,19 @@ endfunction()
function(verilator_link_systemc TARGET) function(verilator_link_systemc TARGET)
_verilator_find_systemc() _verilator_find_systemc()
target_link_libraries("${TARGET}" PUBLIC Verilator::systemc) target_link_libraries("${TARGET}" PUBLIC Verilator::systemc)
target_compile_options(${TARGET} PRIVATE $ENV{SYSTEMC_CXX_FLAGS} ${SYSTEMC_CXX_FLAGS}) target_compile_options(
${TARGET}
PRIVATE $ENV{SYSTEMC_CXX_FLAGS} ${SYSTEMC_CXX_FLAGS}
)
endfunction() endfunction()
function(verilator_generate_key OUTPUT_VARIABLE) function(verilator_generate_key OUTPUT_VARIABLE)
execute_process(COMMAND ${VERILATOR_BIN} --generate-key execute_process(
COMMAND ${VERILATOR_BIN} --generate-key
OUTPUT_VARIABLE KEY_VAL OUTPUT_VARIABLE KEY_VAL
RESULT_VARIABLE KEY_RET) RESULT_VARIABLE KEY_RET
if (KEY_RET) )
if(KEY_RET)
message(FATAL_ERROR "verilator --generate-key failed") message(FATAL_ERROR "verilator --generate-key failed")
endif() endif()
string(STRIP ${KEY_VAL} KEY_VAL) string(STRIP ${KEY_VAL} KEY_VAL)