diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d4b946a9..88afe9d75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,14 +14,17 @@ cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0091 NEW) # Use MSVC_RUNTIME_LIBRARY to select the runtime -project(Verilator +project( + Verilator VERSION 5.029 HOMEPAGE_URL https://verilator.org LANGUAGES CXX ) -option(DEBUG_AND_RELEASE_AND_COVERAGE - "Builds both the debug and release binaries, overriding CMAKE_BUILD_TYPE. Not supported under MSBuild.") +option( + 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) set(PYTHON3 ${Python3_EXECUTABLE}) @@ -32,19 +35,22 @@ include(CheckStructHasMember) include(ExternalProject) include(FindThreads) -if (NOT WIN32) +if(NOT WIN32) message(WARNING "CMake support on Linux/OSX is experimental.") endif() -if (WIN32) - if (DEFINED ENV{WIN_FLEX_BISON}) +if(WIN32) + if(DEFINED ENV{WIN_FLEX_BISON}) set(WIN_FLEX_BISON "$ENV{WIN_FLEX_BISON}") endif() - if (EXISTS ${WIN_FLEX_BISON}) + if(EXISTS ${WIN_FLEX_BISON}) list(APPEND CMAKE_PREFIX_PATH ${WIN_FLEX_BISON}) endif() - 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.") + 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." + ) endif() set(CMAKE_CXX_STANDARD 20) endif() @@ -52,20 +58,25 @@ endif() set(OBJCACHE "" CACHE STRING "Path for ccache, auto-detected if empty") option(OBJCACHE_ENABLED "Compile Verilator with ccache" ON) -if (OBJCACHE_ENABLED) - if (OBJCACHE STREQUAL "") +if(OBJCACHE_ENABLED) + if(OBJCACHE STREQUAL "") find_program(OBJCACHE_PATH ccache) - if (OBJCACHE_PATH STREQUAL "OBJCACHE_PATH-NOTFOUND") + if(OBJCACHE_PATH STREQUAL "OBJCACHE_PATH-NOTFOUND") set(OBJCACHE_PATH "") endif() else() set(OBJCACHE_PATH "${OBJCACHE}") endif() - if (NOT OBJCACHE_PATH STREQUAL "") - execute_process(COMMAND "${OBJCACHE_PATH}" --version - OUTPUT_VARIABLE objcache_version) + if(NOT OBJCACHE_PATH STREQUAL "") + execute_process( + COMMAND "${OBJCACHE_PATH}" --version + OUTPUT_VARIABLE 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}") endif() endif() @@ -76,8 +87,8 @@ find_package(FLEX) # Build #set_property(GLOBAL PROPERTY JOB_POOLS one_job=1) -if (DEBUG_AND_RELEASE_AND_COVERAGE) - if (CMAKE_GENERATOR MATCHES "^Visual Studio ") +if(DEBUG_AND_RELEASE_AND_COVERAGE) + if(CMAKE_GENERATOR MATCHES "^Visual Studio ") error("%Error: The DEBUG_AND_RELEASE_AND_COVERAGE option is not supported in MSBuild-based builds.") endif() 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.mk.in include/verilated.mk @ONLY) -install(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) +install( + 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(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(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_gantt verilator_ccache_report @@ -128,13 +156,19 @@ foreach (program install(PROGRAMS bin/${program} TYPE BIN) endforeach() -install(DIRECTORY examples TYPE DATA FILES_MATCHING +install( + DIRECTORY examples + TYPE DATA + FILES_MATCHING PATTERN "examples/*/*.[chv]*" PATTERN "examples/*/Makefile*" 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/*.[chv]" PATTERN "include/*.cpp" diff --git a/Makefile.in b/Makefile.in index 3535e5037..1a90b46ab 100644 --- a/Makefile.in +++ b/Makefile.in @@ -463,6 +463,14 @@ YAMLFIX = YAMLFIX_WHITELINES=1 YAMLFIX_LINE_LENGTH=130 YAMLFIX_preserve_quotes=t 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 PY_PROGRAMS = \ bin/verilator_ccache_report \ @@ -508,6 +516,12 @@ YAPF_FLAGS = -i --parallel yapf: $(YAPF) $(YAPF_FLAGS) $(PY_FILES) +GERSEMI = gersemi +GERSEMI_FLAGS = -i + +format-cmake: + $(GERSEMI) $(GERSEMI_FLAGS) $(CMAKE_FILES) + PYLINT = pylint 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 diff --git a/examples/cmake_hello_c/CMakeLists.txt b/examples/cmake_hello_c/CMakeLists.txt index 0bd119277..338cacc85 100644 --- a/examples/cmake_hello_c/CMakeLists.txt +++ b/examples/cmake_hello_c/CMakeLists.txt @@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW) project(cmake_hello_c) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) -if (NOT verilator_FOUND) - message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") +if(NOT verilator_FOUND) + message( + FATAL_ERROR + "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable" + ) endif() # 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 verilate(example INCLUDE_DIRS "../make_hello_c" - SOURCES ../make_hello_c/top.v) + SOURCES ../make_hello_c/top.v +) diff --git a/examples/cmake_hello_sc/CMakeLists.txt b/examples/cmake_hello_sc/CMakeLists.txt index 647e7cf07..58d434439 100644 --- a/examples/cmake_hello_sc/CMakeLists.txt +++ b/examples/cmake_hello_sc/CMakeLists.txt @@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW) project(cmake_hello_sc CXX) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) -if (NOT verilator_FOUND) - message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") +if(NOT verilator_FOUND) + message( + FATAL_ERROR + "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable" + ) endif() # SystemC dependencies @@ -39,14 +42,12 @@ find_package(SystemCLanguage QUIET) add_executable(example ../make_hello_sc/sc_main.cpp) target_compile_features(example PUBLIC cxx_std_14) -set_property( - TARGET example - PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD} - ) +set_property(TARGET example PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD}) # Add the Verilated circuit to the target verilate(example SYSTEMC INCLUDE_DIRS "../make_hello_sc" - SOURCES ../make_hello_sc/top.v) + SOURCES ../make_hello_sc/top.v +) verilator_link_systemc(example) diff --git a/examples/cmake_protect_lib/CMakeLists.txt b/examples/cmake_protect_lib/CMakeLists.txt index eb581a3c8..ec07f0716 100644 --- a/examples/cmake_protect_lib/CMakeLists.txt +++ b/examples/cmake_protect_lib/CMakeLists.txt @@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW) project(cmake_protect_lib) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) -if (NOT verilator_FOUND) - message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") +if(NOT verilator_FOUND) + message( + FATAL_ERROR + "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable" + ) endif() # Create the main executable target @@ -55,9 +58,11 @@ verilate(verilated_secret VERILATOR_ARGS --protect-lib verilated_secret --protect-key ${PROTECT_KEY} 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 verilate(example VERILATOR_ARGS "-I${CMAKE_CURRENT_BINARY_DIR}/verilated_secret" - SOURCES ../make_protect_lib/top.v) + SOURCES ../make_protect_lib/top.v +) diff --git a/examples/cmake_tracing_c/CMakeLists.txt b/examples/cmake_tracing_c/CMakeLists.txt index 6d605b93b..312c8d2b9 100644 --- a/examples/cmake_tracing_c/CMakeLists.txt +++ b/examples/cmake_tracing_c/CMakeLists.txt @@ -24,8 +24,11 @@ cmake_policy(SET CMP0074 NEW) project(cmake_tracing_c) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) -if (NOT verilator_FOUND) - message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") +if(NOT verilator_FOUND) + message( + FATAL_ERROR + "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable" + ) endif() # 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 INCLUDE_DIRS "../make_tracing_c" VERILATOR_ARGS -f ../make_tracing_c/input.vc -x-assign fast - SOURCES ../make_tracing_c/top.v) + SOURCES ../make_tracing_c/top.v +) diff --git a/examples/cmake_tracing_sc/CMakeLists.txt b/examples/cmake_tracing_sc/CMakeLists.txt index 4ad12f861..1ce7870d2 100644 --- a/examples/cmake_tracing_sc/CMakeLists.txt +++ b/examples/cmake_tracing_sc/CMakeLists.txt @@ -25,8 +25,11 @@ cmake_policy(SET CMP0074 NEW) project(cmake_tracing_sc_example CXX) find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT}) -if (NOT verilator_FOUND) - message(FATAL_ERROR "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable") +if(NOT verilator_FOUND) + message( + FATAL_ERROR + "Verilator was not found. Either install it, or set the VERILATOR_ROOT environment variable" + ) endif() # SystemC dependencies @@ -40,15 +43,13 @@ find_package(SystemCLanguage QUIET) add_executable(example ../make_tracing_sc/sc_main.cpp) target_compile_features(example PUBLIC cxx_std_14) -set_property( - TARGET example - PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD} - ) +set_property(TARGET example PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD}) # Add the Verilated circuit to the target verilate(example SYSTEMC COVERAGE TRACE INCLUDE_DIRS "../make_tracing_sc" 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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3107f1dfe..e0b1792a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,14 +14,23 @@ # # Utilities -macro (addBuildType sourceConfig newConfig) +macro(addBuildType sourceConfig newConfig) get_cmake_property(variableNames VARIABLES) - foreach (variableName ${variableNames}) - if (variableName MATCHES "^CMAKE_.*_${sourceConfig}(|_.*)$") - string(REPLACE _${sourceConfig} _${newConfig} newVariableName ${variableName}) + foreach(variableName ${variableNames}) + if(variableName MATCHES "^CMAKE_.*_${sourceConfig}(|_.*)$") + string( + REPLACE + _${sourceConfig} + _${newConfig} + newVariableName + ${variableName} + ) set(${newVariableName} ${${variableName}}) mark_as_advanced(${newVariableName}) - message(DEBUG " Propagating ${variableName} to ${newVariableName} = ${${newVariableName}}") + message( + DEBUG + " Propagating ${variableName} to ${newVariableName} = ${${newVariableName}}" + ) endif() endforeach() endmacro() @@ -327,9 +336,7 @@ set(COMMON_SOURCES V3PreProc.cpp ) -SET(COVERAGE_SOURCES - VlcMain.cpp -) +set(COVERAGE_SOURCES VlcMain.cpp) # Note about tests: # VlcMain.cpp #includes the following files: @@ -352,34 +359,49 @@ configure_file(config_package.h.in config_package.h @ONLY) add_custom_command( OUTPUT V3Ast__gen_forward_class_decls.h V3Dfg__gen_forward_class_decls.h DEPENDS ./V3Ast.h ${ASTGEN} - COMMAND ${PYTHON3} ARGS - ${ASTGEN} -I "${srcdir}" --astdef V3AstNodeDType.h --astdef V3AstNodeExpr.h --astdef V3AstNodeOther.h --dfgdef V3DfgVertices.h --classes + COMMAND ${PYTHON3} + 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 -set(verilog_y "${srcdir}/verilog.y" ) -set(BISON_V3ParseBison_OUTPUT_HEADER "${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.h") -set(BISON_V3ParseBison_OUTPUT_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.c") +set(verilog_y "${srcdir}/verilog.y") +set(BISON_V3ParseBison_OUTPUT_HEADER + "${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.h" +) +set(BISON_V3ParseBison_OUTPUT_SOURCE + "${CMAKE_CURRENT_BINARY_DIR}/V3ParseBison.c" +) add_custom_command( OUTPUT V3ParseBison.c V3ParseBison.h MAIN_DEPENDENCY ./verilog.y DEPENDS ${BISONPRE} - COMMAND ${PYTHON3} ARGS - ${BISONPRE} --yacc "${BISON_EXECUTABLE}" -d -v - -o "${BISON_V3ParseBison_OUTPUT_SOURCE}" "${verilog_y}" + COMMAND ${PYTHON3} + ARGS + ${BISONPRE} --yacc "${BISON_EXECUTABLE}" -d -v -o + "${BISON_V3ParseBison_OUTPUT_SOURCE}" "${verilog_y}" ) list(APPEND GENERATED_FILES V3ParseBison.c V3ParseBison.h) # Output used directly by the `verilator` target 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( OUTPUT V3Lexer_pregen.yy.cpp MAIN_DEPENDENCY ./verilog.l DEPENDS ${BISON_V3ParseBison_OUTPUT_HEADER} ${HEADERS} - COMMAND ${FLEX_EXECUTABLE} ARGS - ${LFLAGS} -o "${FLEX_V3Lexer_pregen_OUTPUTS}" "${verilog_l}" + COMMAND ${FLEX_EXECUTABLE} + ARGS ${LFLAGS} -o "${FLEX_V3Lexer_pregen_OUTPUTS}" "${verilog_l}" ) # Output used by another command @@ -388,19 +410,26 @@ add_custom_command( OUTPUT V3Lexer.yy.cpp MAIN_DEPENDENCY ${FLEX_V3Lexer_pregen_OUTPUTS} DEPENDS ${FLEXFIX} - COMMAND ${PYTHON3} ARGS - ${FLEXFIX} V3Lexer < "$" > "$" + COMMAND ${PYTHON3} + ARGS + ${FLEXFIX} V3Lexer < "$" > + "$" +) +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 -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( OUTPUT V3PreLex_pregen.yy.cpp MAIN_DEPENDENCY ./V3PreLex.l DEPENDS ${HEADERS} - COMMAND ${FLEX_EXECUTABLE} ARGS - ${LFLAGS} -o "${FLEX_V3PreLex_pregen_OUTPUTS}" "${srcdir}/V3PreLex.l" + COMMAND ${FLEX_EXECUTABLE} + ARGS ${LFLAGS} -o "${FLEX_V3PreLex_pregen_OUTPUTS}" "${srcdir}/V3PreLex.l" ) # Output used by another command @@ -409,37 +438,45 @@ add_custom_command( OUTPUT V3PreLex.yy.cpp MAIN_DEPENDENCY ${FLEX_V3PreLex_pregen_OUTPUTS} DEPENDS ${FLEXFIX} - COMMAND ${PYTHON3} ARGS - ${FLEXFIX} V3PreLex < "$" > "$" + COMMAND ${PYTHON3} + ARGS + ${FLEXFIX} V3PreLex < "$" > + "$" +) +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 set(gitHead ${srcdir}/../.git/logs/HEAD) -if (NOT EXISTS ${githead}) +if(NOT EXISTS ${githead}) set(gitHead "") endif() add_custom_command( OUTPUT config_rev.h MAIN_DEPENDENCY ${gitHead} DEPENDS ${CONFIG_REV} - COMMAND ${PYTHON3} ARGS - ${CONFIG_REV} "${srcdir}" > "$" + COMMAND ${PYTHON3} + ARGS + ${CONFIG_REV} "${srcdir}" > + "$" ) list(APPEND GENERATED_FILES config_rev.h) # Output used directly by the `verilator` target -set(ASTGENERATED_NAMES - V3Const -) +set(ASTGENERATED_NAMES V3Const) foreach(astgen_name ${ASTGENERATED_NAMES}) add_custom_command( OUTPUT ${astgen_name}__gen.cpp MAIN_DEPENDENCY ${astgen_name}.cpp DEPENDS ${ASTGEN} V3Ast.h - COMMAND ${PYTHON3} ARGS - ${ASTGEN} -I "${srcdir}" --astdef V3AstNodeDType.h --astdef V3AstNodeExpr.h --astdef V3AstNodeOther.h --dfgdef V3DfgVertices.h ${astgen_name}.cpp + COMMAND ${PYTHON3} + 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) endforeach() @@ -447,7 +484,7 @@ endforeach() # # Set up the Coverage build type -addBuildType(DEBUG COVERAGE) +addbuildtype(DEBUG COVERAGE) # This regenerates include/verilated_cov_key.h in the source tree. # It is a custom_target, not custom_command, because vlcovgen.d is @@ -456,8 +493,7 @@ add_custom_target( vlcovgen.d${CMAKE_BUILD_TYPE} DEPENDS ../include/verilated_cov_key.h ${VLCOVGEN} COMMENT "Updating include/verilated_cov_key.h" - COMMAND ${PYTHON3} - ${VLCOVGEN} --srcdir ${srcdir} + COMMAND ${PYTHON3} ${VLCOVGEN} --srcdir ${srcdir} ) # @@ -465,24 +501,29 @@ add_custom_target( set(verilator verilator${CMAKE_BUILD_TYPE}) -add_executable(${verilator} +add_executable( + ${verilator} $<$>:${COMMON_SOURCES}> $<$>:${GENERATED_FILES}> - $<$:${COVERAGE_SOURCES} config_rev.h> + $<$:${COVERAGE_SOURCES} + config_rev.h> ) -set_target_properties(${verilator} PROPERTIES - OUTPUT_NAME_RELEASE verilator_bin - OUTPUT_NAME_DEBUG verilator_bin_dbg - OUTPUT_NAME_COVERAGE verilator_coverage_bin_dbg - #UNITY_BUILD $,FALSE,${CMAKE_UNITY_BUILD}> - MSVC_RUNTIME_LIBRARY MultiThreaded$,,DebugDLL> - #JOB_POOL_LINK one_job # Linking takes lots of resources - INTERPROCEDURAL_OPTIMIZATION_RELEASE $ - INCLUDE_DIRECTORIES ${FLEX_INCLUDE_DIR} +set_target_properties( + ${verilator} + PROPERTIES + OUTPUT_NAME_RELEASE verilator_bin + OUTPUT_NAME_DEBUG verilator_bin_dbg + OUTPUT_NAME_COVERAGE verilator_coverage_bin_dbg + #UNITY_BUILD $,FALSE,${CMAKE_UNITY_BUILD}> + MSVC_RUNTIME_LIBRARY MultiThreaded$,,DebugDLL> + #JOB_POOL_LINK one_job # Linking takes lots of resources + INTERPROCEDURAL_OPTIMIZATION_RELEASE $ + INCLUDE_DIRECTORIES ${FLEX_INCLUDE_DIR} ) -add_dependencies(${verilator} +add_dependencies( + ${verilator} V3Lexer_yy_cpp${CMAKE_BUILD_TYPE} V3PreLex_yy_cpp${CMAKE_BUILD_TYPE} ) @@ -492,41 +533,49 @@ target_link_libraries(${verilator} PRIVATE Threads::Threads) # verilated_cov_key.h is only regenerated in a single-configuration environment. # This limitation can be lifted when `add_dependencies` will support generator # 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}) endif() -if (NOT MSVC) +if(NOT MSVC) target_compile_features(${verilator} PRIVATE cxx_std_11) endif() -target_compile_definitions(${verilator} PRIVATE - YYDEBUG # Required to get nice error messages - $<$:VL_DEBUG> - $<$:_GLIBCXX_DEBUG> -) - -target_include_directories(${verilator} +target_compile_definitions( + ${verilator} PRIVATE - ../include - ${WIN_FLEX_BISON} - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR} + YYDEBUG # Required to get nice error messages + $<$:VL_DEBUG> + $<$:_GLIBCXX_DEBUG> ) -if (WIN32) +target_include_directories( + ${verilator} + PRIVATE + ../include + ${WIN_FLEX_BISON} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/../include + ${CMAKE_CURRENT_SOURCE_DIR} +) + +if(WIN32) if(MINGW) 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() target_compile_options(${verilator} PRIVATE /bigobj) target_link_options(${verilator} PRIVATE /STACK:10000000) endif() - target_compile_definitions(${verilator} PRIVATE - YY_NO_UNISTD_H - ) + target_compile_definitions(${verilator} PRIVATE YY_NO_UNISTD_H) target_include_directories(${verilator} PRIVATE ../platform/win32) target_link_libraries(${verilator} PRIVATE bcrypt psapi) endif() diff --git a/test_regress/CMakeLists.txt b/test_regress/CMakeLists.txt index be1adb6ed..bc75319c7 100644 --- a/test_regress/CMakeLists.txt +++ b/test_regress/CMakeLists.txt @@ -14,19 +14,31 @@ cmake_minimum_required(VERSION 3.12) cmake_policy(SET CMP0074 NEW) -set(TEST_REQUIRED_VARS NAME CSOURCES OPT_FAST OPT_GLOBAL - VERILATOR_ROOT VERILATOR_ARGS - VERILATOR_SOURCES SYSTEMC VERBOSE VERILATION) +set(TEST_REQUIRED_VARS + NAME + CSOURCES + OPT_FAST + OPT_GLOBAL + VERILATOR_ROOT + VERILATOR_ARGS + VERILATOR_SOURCES + SYSTEMC + VERBOSE + VERILATION +) foreach(var ${TEST_REQUIRED_VARS}) - if (NOT DEFINED TEST_${var}) - message(FATAL_ERROR "TEST_${var} not defined. This CMakeLists.txt file is meant to be run by driver.py.") - endif() + if(NOT DEFINED TEST_${var}) + message( + FATAL_ERROR + "TEST_${var} not defined. This CMakeLists.txt file is meant to be run by driver.py." + ) + endif() endforeach() project("${TEST_NAME}") if(TEST_VERBOSE) - add_definitions(-DTEST_VERBOSE=1) + add_definitions(-DTEST_VERBOSE=1) endif() separate_arguments(TEST_VERILATOR_ARGS UNIX_COMMAND "${TEST_VERILATOR_ARGS}") @@ -38,33 +50,49 @@ set(TEST_PREFIX ${TEST_NAME}) # If --ARG is present, set OUT = function(getarg LST ARG OUT) - list(FIND ${LST} ${ARG} _INDEX) - if(NOT _INDEX EQUAL -1) - list(REMOVE_AT ${LST} ${_INDEX}) - list(GET ${LST} ${_INDEX} VAL) - set(${OUT} ${VAL} PARENT_SCOPE) - endif() + list(FIND ${LST} ${ARG} _INDEX) + if(NOT _INDEX EQUAL -1) + list(REMOVE_AT ${LST} ${_INDEX}) + list(GET ${LST} ${_INDEX} VAL) + set(${OUT} ${VAL} PARENT_SCOPE) + endif() endfunction() # Normalise -- to - -string(REGEX REPLACE "(^|;)--" "\\1-" - TEST_VERILATOR_ARGS_NORM - "${TEST_VERILATOR_ARGS}") +string( + REGEX REPLACE + "(^|;)--" + "\\1-" + TEST_VERILATOR_ARGS_NORM + "${TEST_VERILATOR_ARGS}" +) getarg(TEST_VERILATOR_ARGS_NORM "-prefix" TEST_PREFIX) getarg(TEST_VERILATOR_ARGS_NORM "-threads" TEST_THREADS) getarg(TEST_VERILATOR_ARGS_NORM "-trace-threads" TEST_TRACE_THREADS) # Strip unwanted args with 1 parameter -string(REGEX REPLACE "(^|;)--?(Mdir|make|prefix|threads|trace-threads);[^;]*" "" - TEST_VERILATOR_ARGS - "${TEST_VERILATOR_ARGS}") +string( + REGEX REPLACE + "(^|;)--?(Mdir|make|prefix|threads|trace-threads);[^;]*" + "" + TEST_VERILATOR_ARGS + "${TEST_VERILATOR_ARGS}" +) # Strip unwanted args -string(REGEX REPLACE "(^|;)--?(sc|cc)" "" - TEST_VERILATOR_ARGS - "${TEST_VERILATOR_ARGS}") +string( + REGEX REPLACE + "(^|;)--?(sc|cc)" + "" + 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 list(FILTER TEST_VERILATOR_SOURCES EXCLUDE REGEX "$^") @@ -72,22 +100,22 @@ find_package(verilator REQUIRED HINTS ${TEST_VERILATOR_ROOT}) set(verilate_ARGS MAIN) if(TEST_PREFIX) - list(APPEND verilate_ARGS PREFIX ${TEST_PREFIX}) + list(APPEND verilate_ARGS PREFIX ${TEST_PREFIX}) endif() if(TEST_OPT_FAST) - list(APPEND verilate_ARGS OPT_FAST ${TEST_OPT_FAST}) + list(APPEND verilate_ARGS OPT_FAST ${TEST_OPT_FAST}) endif() if(TEST_OPT_GLOBAL) - list(APPEND verilate_ARGS OPT_GLOBAL ${TEST_OPT_GLOBAL}) + list(APPEND verilate_ARGS OPT_GLOBAL ${TEST_OPT_GLOBAL}) endif() if(TEST_THREADS) - list(APPEND verilate_ARGS THREADS ${TEST_THREADS}) + list(APPEND verilate_ARGS THREADS ${TEST_THREADS}) endif() if(TEST_TRACE_THREADS) - list(APPEND verilate_ARGS TRACE_THREADS ${TEST_TRACE_THREADS}) + list(APPEND verilate_ARGS TRACE_THREADS ${TEST_TRACE_THREADS}) endif() if(TEST_SYSTEMC) - list(APPEND verilate_ARGS SYSTEMC) + list(APPEND verilate_ARGS SYSTEMC) endif() set(TARGET_NAME "V${TEST_NAME}") @@ -95,21 +123,24 @@ set(TARGET_NAME "V${TEST_NAME}") add_executable(${TARGET_NAME} ${TEST_CSOURCES}) if(TEST_VERILATION) - verilate(${TARGET_NAME} ${verilate_ARGS} - VERILATOR_ARGS ${TEST_VERILATOR_ARGS} - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - SOURCES ${TEST_VERILATOR_SOURCES}) + verilate(${TARGET_NAME} ${verilate_ARGS} + VERILATOR_ARGS ${TEST_VERILATOR_ARGS} + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${TEST_VERILATOR_SOURCES} + ) endif() if(TEST_SYSTEMC) - verilator_link_systemc("${TARGET_NAME}") + verilator_link_systemc("${TARGET_NAME}") endif() string(TOUPPER "${TEST_NAME}" TEST_NAME_UC) -target_compile_definitions(${TARGET_NAME} PRIVATE - "TEST_OBJ_DIR=${CMAKE_CURRENT_BINARY_DIR}" - "VM_PREFIX=${TEST_PREFIX}" - "VM_PREFIX_INCLUDE=<${TEST_PREFIX}.h>" - "${TEST_NAME_UC}" +target_compile_definitions( + ${TARGET_NAME} + PRIVATE + "TEST_OBJ_DIR=${CMAKE_CURRENT_BINARY_DIR}" + "VM_PREFIX=${TEST_PREFIX}" + "VM_PREFIX_INCLUDE=<${TEST_PREFIX}.h>" + "${TEST_NAME_UC}" ) diff --git a/verilator-config-version.cmake.in b/verilator-config-version.cmake.in index 55a9ae285..5ce5987b9 100644 --- a/verilator-config-version.cmake.in +++ b/verilator-config-version.cmake.in @@ -18,10 +18,10 @@ set(PACKAGE_VERSION "@PACKAGE_VERSION_NUMBER@") if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) - set(PACKAGE_VERSION_COMPATIBLE FALSE) + set(PACKAGE_VERSION_COMPATIBLE FALSE) else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) - set(PACKAGE_VERSION_EXACT TRUE) - endif() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() endif() diff --git a/verilator-config.cmake.in b/verilator-config.cmake.in index ebf14380b..f14a3096a 100644 --- a/verilator-config.cmake.in +++ b/verilator-config.cmake.in @@ -22,410 +22,539 @@ cmake_minimum_required(VERSION 3.13) # Prefer VERILATOR_ROOT from environment -if (DEFINED ENV{VERILATOR_ROOT}) - set(VERILATOR_ROOT "$ENV{VERILATOR_ROOT}" CACHE PATH "VERILATOR_ROOT") +if(DEFINED ENV{VERILATOR_ROOT}) + set(VERILATOR_ROOT "$ENV{VERILATOR_ROOT}" CACHE PATH "VERILATOR_ROOT") endif() set(VERILATOR_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "VERILATOR_ROOT") -find_program(VERILATOR_BIN NAMES verilator_bin verilator_bin.exe - HINTS ${VERILATOR_ROOT}/bin ENV VERILATOR_ROOT - NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) +find_program( + VERILATOR_BIN + 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) - 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.") +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." + ) endif() -if (NOT VERILATOR_BIN) - message(FATAL_ERROR "Cannot find verilator_bin excecutable.") +if(NOT VERILATOR_BIN) + message(FATAL_ERROR "Cannot find verilator_bin excecutable.") endif() set(verilator_FOUND 1) include(CheckCXXSourceCompiles) function(_verilator_check_cxx_libraries LIBRARIES RESVAR) - # Check whether a particular link option creates a valid executable - set(_VERILATOR_CHECK_CXX_LINK_OPTIONS_SRC "int main() {return 0;}\n") - set(CMAKE_REQUIRED_FLAGS) - set(CMAKE_REQUIRED_DEFINITIONS) - set(CMAKE_REQUIRED_INCLUDES) - set(CMAKE_REQUIRED_LINK_OPTIONS) - set(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES}) - set(CMAKE_REQUIRED_QUIET) - check_cxx_source_compiles("${_VERILATOR_CHECK_CXX_LINK_OPTIONS_SRC}" "${RESVAR}") - set("${RESVAR}" "${${RESVAR}}" PARENT_SCOPE) + # Check whether a particular link option creates a valid executable + set(_VERILATOR_CHECK_CXX_LINK_OPTIONS_SRC "int main() {return 0;}\n") + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_DEFINITIONS) + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_LINK_OPTIONS) + set(CMAKE_REQUIRED_LIBRARIES ${LIBRARIES}) + set(CMAKE_REQUIRED_QUIET) + check_cxx_source_compiles( + "${_VERILATOR_CHECK_CXX_LINK_OPTIONS_SRC}" + "${RESVAR}" + ) + set("${RESVAR}" "${${RESVAR}}" PARENT_SCOPE) endfunction() # Check compiler flag support. Skip on MSVC, these are all GCC flags. -if (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC) - if (NOT DEFINED VERILATOR_CFLAGS OR NOT DEFINED VERILATOR_MT_CFLAGS) - include(CheckCXXCompilerFlag) - foreach (FLAG @CFG_CXX_FLAGS_CMAKE@) - string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME) - check_cxx_compiler_flag(${FLAG} ${FLAGNAME}) - if (${FLAGNAME}) - list(APPEND VERILATOR_CFLAGS ${FLAG}) - endif() - endforeach() - foreach (FLAG @CFG_LDFLAGS_THREADS_CMAKE@) - string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME) - _verilator_check_cxx_libraries("${FLAG}" ${FLAGNAME}) - if (${FLAGNAME}) - list(APPEND VERILATOR_MT_CFLAGS ${FLAG}) - endif() - endforeach() - endif() +if(NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC) + if(NOT DEFINED VERILATOR_CFLAGS OR NOT DEFINED VERILATOR_MT_CFLAGS) + include(CheckCXXCompilerFlag) + foreach(FLAG @CFG_CXX_FLAGS_CMAKE@) + string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME) + check_cxx_compiler_flag(${FLAG} ${FLAGNAME}) + if(${FLAGNAME}) + list(APPEND VERILATOR_CFLAGS ${FLAG}) + endif() + endforeach() + foreach(FLAG @CFG_LDFLAGS_THREADS_CMAKE@) + string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME) + _verilator_check_cxx_libraries("${FLAG}" ${FLAGNAME}) + if(${FLAGNAME}) + list(APPEND VERILATOR_MT_CFLAGS ${FLAG}) + endif() + endforeach() + endif() endif() -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang") - add_link_options(-Wl,-U,__Z15vl_time_stamp64v,-U,__Z13sc_time_stampv) +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang") + add_link_options(-Wl,-U,__Z15vl_time_stamp64v,-U,__Z13sc_time_stampv) endif() -define_property(TARGET - PROPERTY VERILATOR_THREADED - BRIEF_DOCS "Deprecated and has no effect (ignored)" - FULL_DOCS "Deprecated and has no effect (ignored)" +define_property( + TARGET + PROPERTY VERILATOR_THREADED + BRIEF_DOCS "Deprecated and has no effect (ignored)" + FULL_DOCS "Deprecated and has no effect (ignored)" ) -define_property(TARGET - PROPERTY VERILATOR_TRACE_THREADED - BRIEF_DOCS "Verilator multithread tracing enabled" - FULL_DOCS "Verilator multithread tracing enabled" +define_property( + TARGET + PROPERTY VERILATOR_TRACE_THREADED + BRIEF_DOCS "Verilator multithread tracing enabled" + FULL_DOCS "Verilator multithread tracing enabled" ) -define_property(TARGET - PROPERTY VERILATOR_TIMING - BRIEF_DOCS "Verilator timing enabled" - FULL_DOCS "Verilator timing enabled" +define_property( + TARGET + PROPERTY VERILATOR_TIMING + BRIEF_DOCS "Verilator timing enabled" + FULL_DOCS "Verilator timing enabled" ) -define_property(TARGET - PROPERTY VERILATOR_COVERAGE - BRIEF_DOCS "Verilator coverage enabled" - FULL_DOCS "Verilator coverage enabled" +define_property( + TARGET + PROPERTY VERILATOR_COVERAGE + BRIEF_DOCS "Verilator coverage enabled" + FULL_DOCS "Verilator coverage enabled" ) -define_property(TARGET - PROPERTY VERILATOR_TRACE - BRIEF_DOCS "Verilator trace enabled" - FULL_DOCS "Verilator trace enabled" +define_property( + TARGET + PROPERTY VERILATOR_TRACE + BRIEF_DOCS "Verilator trace enabled" + FULL_DOCS "Verilator trace enabled" ) -define_property(TARGET - PROPERTY VERILATOR_TRACE_VCD - BRIEF_DOCS "Verilator VCD trace enabled" - FULL_DOCS "Verilator VCD trace enabled" +define_property( + TARGET + PROPERTY VERILATOR_TRACE_VCD + BRIEF_DOCS "Verilator VCD trace enabled" + FULL_DOCS "Verilator VCD trace enabled" ) -define_property(TARGET - PROPERTY VERILATOR_TRACE_FST - BRIEF_DOCS "Verilator FST trace enabled" - FULL_DOCS "Verilator FST trace enabled" +define_property( + TARGET + PROPERTY VERILATOR_TRACE_FST + BRIEF_DOCS "Verilator FST trace enabled" + FULL_DOCS "Verilator FST trace enabled" ) -define_property(TARGET - PROPERTY VERILATOR_SYSTEMC - BRIEF_DOCS "Verilator SystemC enabled" - FULL_DOCS "Verilator SystemC enabled" +define_property( + TARGET + PROPERTY VERILATOR_SYSTEMC + BRIEF_DOCS "Verilator SystemC enabled" + FULL_DOCS "Verilator SystemC enabled" ) -define_property(TARGET +define_property( + TARGET PROPERTY VERILATOR_TRACE_STRUCTS BRIEF_DOCS "Verilator trace structs enabled" FULL_DOCS "Verilator trace structs enabled" ) - function(verilate TARGET) - cmake_parse_arguments(VERILATE "COVERAGE;TRACE;TRACE_FST;SYSTEMC;TRACE_STRUCTS" - "PREFIX;TOP_MODULE;THREADS;TRACE_THREADS;DIRECTORY" - "SOURCES;VERILATOR_ARGS;INCLUDE_DIRS;OPT_SLOW;OPT_FAST;OPT_GLOBAL" - ${ARGN}) - if (NOT VERILATE_SOURCES) - message(FATAL_ERROR "Need at least one source") - endif() - - if (NOT VERILATE_PREFIX) - list(LENGTH VERILATE_SOURCES NUM_SOURCES) - if (${NUM_SOURCES} GREATER 1) - message(WARNING "Specify PREFIX if there are multiple SOURCES") + cmake_parse_arguments( + VERILATE + "COVERAGE;TRACE;TRACE_FST;SYSTEMC;TRACE_STRUCTS" + "PREFIX;TOP_MODULE;THREADS;TRACE_THREADS;DIRECTORY" + "SOURCES;VERILATOR_ARGS;INCLUDE_DIRS;OPT_SLOW;OPT_FAST;OPT_GLOBAL" + ${ARGN} + ) + if(NOT VERILATE_SOURCES) + message(FATAL_ERROR "Need at least one source") endif() - list(GET VERILATE_SOURCES 0 TOPSRC) - get_filename_component(_SRC_NAME ${TOPSRC} NAME_WE) - string(MAKE_C_IDENTIFIER V${_SRC_NAME} VERILATE_PREFIX) - endif() - if (VERILATE_TOP_MODULE) - list(APPEND VERILATOR_ARGS --top ${VERILATE_TOP_MODULE}) - endif() - - if (VERILATE_THREADS) - list(APPEND VERILATOR_ARGS --threads ${VERILATE_THREADS}) - endif() - - if (VERILATE_TRACE_THREADS) - list(APPEND VERILATOR_ARGS --trace-threads ${VERILATE_TRACE_THREADS}) - endif() - - if (VERILATE_COVERAGE) - list(APPEND VERILATOR_ARGS --coverage) - endif() - - if (VERILATE_TRACE AND VERILATE_TRACE_FST) - message(FATAL_ERROR "Cannot have both TRACE and TRACE_FST") - endif() - - if (VERILATE_TRACE) - list(APPEND VERILATOR_ARGS --trace) - endif() - - if (VERILATE_TRACE_FST) - list(APPEND VERILATOR_ARGS --trace-fst) - endif() - - if (VERILATE_SYSTEMC) - list(APPEND VERILATOR_ARGS --sc) - else() - list(APPEND VERILATOR_ARGS --cc) - endif() - - if (VERILATE_TRACE_STRUCTS) - list(APPEND VERILATOR_ARGS --trace-structs) - endif() - - foreach(INC ${VERILATE_INCLUDE_DIRS}) - list(APPEND VERILATOR_ARGS -y "${INC}") - endforeach() - - string(TOLOWER ${CMAKE_CXX_COMPILER_ID} COMPILER) - if (COMPILER STREQUAL "appleclang") - set(COMPILER clang) - elseif (NOT COMPILER MATCHES "^msvc$|^clang$") - set(COMPILER gcc) - endif() - - get_target_property(BINARY_DIR "${TARGET}" BINARY_DIR) - get_target_property(TARGET_NAME "${TARGET}" NAME) - set(VDIR "${BINARY_DIR}/CMakeFiles/${TARGET_NAME}.dir/${VERILATE_PREFIX}.dir") - - if (VERILATE_DIRECTORY) - set(VDIR "${VERILATE_DIRECTORY}") - endif() - - file(MAKE_DIRECTORY ${VDIR}) - - set(VERILATOR_COMMAND "${CMAKE_COMMAND}" -E env "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(VCMAKE "${VDIR}/${VERILATE_PREFIX}.cmake") - set(VCMAKE_COPY "${VDIR}/${VERILATE_PREFIX}_copy.cmake") - - if (NOT EXISTS "${VARGS_FILE}" OR NOT EXISTS "${VCMAKE_COPY}") - set(VERILATOR_OUTDATED ON) - else() - file(READ "${VARGS_FILE}" PREVIOUS_VERILATOR_COMMAND) - if(NOT VERILATOR_COMMAND STREQUAL PREVIOUS_VERILATOR_COMMAND) - set(VERILATOR_OUTDATED ON) + if(NOT VERILATE_PREFIX) + list(LENGTH VERILATE_SOURCES NUM_SOURCES) + if(${NUM_SOURCES} GREATER 1) + message(WARNING "Specify PREFIX if there are multiple SOURCES") + endif() + list(GET VERILATE_SOURCES 0 TOPSRC) + get_filename_component(_SRC_NAME ${TOPSRC} NAME_WE) + string(MAKE_C_IDENTIFIER V${_SRC_NAME} VERILATE_PREFIX) endif() - endif() - if (VERILATOR_OUTDATED) - message(STATUS "Executing Verilator...") - execute_process( - COMMAND ${VERILATOR_COMMAND} - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - RESULT_VARIABLE _VERILATOR_RC - OUTPUT_VARIABLE _VERILATOR_OUTPUT - ERROR_VARIABLE _VERILATOR_OUTPUT) - if (_VERILATOR_RC) - string(REPLACE ";" " " VERILATOR_COMMAND_READABLE "${VERILATOR_COMMAND}") - message("Verilator command: \"${VERILATOR_COMMAND_READABLE}\"") - message("Output:\n${_VERILATOR_OUTPUT}") - message(FATAL_ERROR "Verilator command failed (return code=${_VERILATOR_RC})") + if(VERILATE_TOP_MODULE) + list(APPEND VERILATOR_ARGS --top ${VERILATE_TOP_MODULE}) endif() - execute_process(COMMAND "${CMAKE_COMMAND}" -E copy "${VCMAKE}" "${VCMAKE_COPY}") - endif() - file(WRITE "${VARGS_FILE}" "${VERILATOR_COMMAND}") - include("${VCMAKE_COPY}") + if(VERILATE_THREADS) + list(APPEND VERILATOR_ARGS --threads ${VERILATE_THREADS}) + endif() - set(GENERATED_C_SOURCES ${${VERILATE_PREFIX}_CLASSES_FAST} - ${${VERILATE_PREFIX}_CLASSES_SLOW} - ${${VERILATE_PREFIX}_SUPPORT_FAST} - ${${VERILATE_PREFIX}_SUPPORT_SLOW}) - # No need for .h's as the .cpp will get written same time - set(GENERATED_SOURCES ${GENERATED_C_SOURCES}) + if(VERILATE_TRACE_THREADS) + list(APPEND VERILATOR_ARGS --trace-threads ${VERILATE_TRACE_THREADS}) + endif() - add_custom_command(OUTPUT ${GENERATED_SOURCES} "${VCMAKE}" - COMMAND ${VERILATOR_COMMAND} - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - DEPENDS "${VERILATOR_BIN}" ${${VERILATE_PREFIX}_DEPS} VERBATIM) - # Reconfigure if file list has changed - # (check contents rather than modified time to avoid unnecessary reconfiguration) - add_custom_command(OUTPUT "${VCMAKE_COPY}" - COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${VCMAKE}" "${VCMAKE_COPY}" - DEPENDS "${VCMAKE}" VERBATIM) + if(VERILATE_COVERAGE) + list(APPEND VERILATOR_ARGS --coverage) + endif() - if (${VERILATE_PREFIX}_COVERAGE) - # If any verilate() call specifies COVERAGE, define VM_COVERAGE in the final build - set_property(TARGET ${TARGET} PROPERTY VERILATOR_COVERAGE ON) - endif() + if(VERILATE_TRACE AND VERILATE_TRACE_FST) + message(FATAL_ERROR "Cannot have both TRACE and TRACE_FST") + endif() - if (${VERILATE_PREFIX}_TRACE_VCD) - # 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_VCD ON) - endif() + if(VERILATE_TRACE) + list(APPEND VERILATOR_ARGS --trace) + endif() - if (${VERILATE_PREFIX}_TRACE_FST) - # 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_FST ON) - endif() + if(VERILATE_TRACE_FST) + list(APPEND VERILATOR_ARGS --trace-fst) + endif() - if (${VERILATE_PREFIX}_SC) - # If any verilate() call specifies SYSTEMC, define VM_SC in the final build - set_property(TARGET ${TARGET} PROPERTY VERILATOR_SYSTEMC ON) - endif() + if(VERILATE_SYSTEMC) + list(APPEND VERILATOR_ARGS --sc) + else() + list(APPEND VERILATOR_ARGS --cc) + endif() - if (${VERILATE_PREFIX}_TRACE_STRUCTS) - set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_STRUCTS ON) - endif() + if(VERILATE_TRACE_STRUCTS) + list(APPEND VERILATOR_ARGS --trace-structs) + endif() + + foreach(INC ${VERILATE_INCLUDE_DIRS}) + list(APPEND VERILATOR_ARGS -y "${INC}") + endforeach() + + string(TOLOWER ${CMAKE_CXX_COMPILER_ID} COMPILER) + if(COMPILER STREQUAL "appleclang") + set(COMPILER clang) + elseif(NOT COMPILER MATCHES "^msvc$|^clang$") + set(COMPILER gcc) + endif() + + get_target_property(BINARY_DIR "${TARGET}" BINARY_DIR) + get_target_property(TARGET_NAME "${TARGET}" NAME) + set(VDIR + "${BINARY_DIR}/CMakeFiles/${TARGET_NAME}.dir/${VERILATE_PREFIX}.dir" + ) + + if(VERILATE_DIRECTORY) + set(VDIR "${VERILATE_DIRECTORY}") + endif() + + file(MAKE_DIRECTORY ${VDIR}) + + set(VERILATOR_COMMAND + "${CMAKE_COMMAND}" + -E + env + "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(VCMAKE "${VDIR}/${VERILATE_PREFIX}.cmake") + set(VCMAKE_COPY "${VDIR}/${VERILATE_PREFIX}_copy.cmake") + + if(NOT EXISTS "${VARGS_FILE}" OR NOT EXISTS "${VCMAKE_COPY}") + set(VERILATOR_OUTDATED ON) + else() + file(READ "${VARGS_FILE}" PREVIOUS_VERILATOR_COMMAND) + if(NOT VERILATOR_COMMAND STREQUAL PREVIOUS_VERILATOR_COMMAND) + set(VERILATOR_OUTDATED ON) + endif() + endif() + + if(VERILATOR_OUTDATED) + message(STATUS "Executing Verilator...") + execute_process( + COMMAND ${VERILATOR_COMMAND} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE _VERILATOR_RC + OUTPUT_VARIABLE _VERILATOR_OUTPUT + ERROR_VARIABLE _VERILATOR_OUTPUT + ) + if(_VERILATOR_RC) + string( + REPLACE + ";" + " " + VERILATOR_COMMAND_READABLE + "${VERILATOR_COMMAND}" + ) + message("Verilator command: \"${VERILATOR_COMMAND_READABLE}\"") + message("Output:\n${_VERILATOR_OUTPUT}") + message( + FATAL_ERROR + "Verilator command failed (return code=${_VERILATOR_RC})" + ) + endif() + execute_process( + COMMAND "${CMAKE_COMMAND}" -E copy "${VCMAKE}" "${VCMAKE_COPY}" + ) + endif() + file(WRITE "${VARGS_FILE}" "${VERILATOR_COMMAND}") + + include("${VCMAKE_COPY}") + + set(GENERATED_C_SOURCES + ${${VERILATE_PREFIX}_CLASSES_FAST} + ${${VERILATE_PREFIX}_CLASSES_SLOW} + ${${VERILATE_PREFIX}_SUPPORT_FAST} + ${${VERILATE_PREFIX}_SUPPORT_SLOW} + ) + # No need for .h's as the .cpp will get written same time + set(GENERATED_SOURCES ${GENERATED_C_SOURCES}) + + add_custom_command( + OUTPUT ${GENERATED_SOURCES} "${VCMAKE}" + COMMAND ${VERILATOR_COMMAND} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + DEPENDS "${VERILATOR_BIN}" ${${VERILATE_PREFIX}_DEPS} + VERBATIM + ) + # Reconfigure if file list has changed + # (check contents rather than modified time to avoid unnecessary reconfiguration) + add_custom_command( + OUTPUT "${VCMAKE_COPY}" + COMMAND + "${CMAKE_COMMAND}" -E copy_if_different "${VCMAKE}" "${VCMAKE_COPY}" + DEPENDS "${VCMAKE}" + VERBATIM + ) + + if(${VERILATE_PREFIX}_COVERAGE) + # If any verilate() call specifies COVERAGE, define VM_COVERAGE in the final build + set_property(TARGET ${TARGET} PROPERTY VERILATOR_COVERAGE ON) + endif() + + if(${VERILATE_PREFIX}_TRACE_VCD) + # 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_VCD ON) + endif() + + if(${VERILATE_PREFIX}_TRACE_FST) + # 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_FST ON) + endif() + + if(${VERILATE_PREFIX}_SC) + # If any verilate() call specifies SYSTEMC, define VM_SC in the final build + set_property(TARGET ${TARGET} PROPERTY VERILATOR_SYSTEMC ON) + endif() + + if(${VERILATE_PREFIX}_TRACE_STRUCTS) + set_property(TARGET ${TARGET} PROPERTY VERILATOR_TRACE_STRUCTS ON) + endif() # Add the compile flags only on Verilated sources - target_include_directories(${TARGET} PUBLIC ${VDIR}) - target_sources(${TARGET} PRIVATE ${GENERATED_SOURCES} "${VCMAKE_COPY}" - ${${VERILATE_PREFIX}_GLOBAL} - ${${VERILATE_PREFIX}_USER_CLASSES}) - foreach(_VSOURCE ${VERILATE_SOURCES} ${${VERILATE_PREFIX}_DEPS}) - get_filename_component(_VSOURCE "${_VSOURCE}" ABSOLUTE BASE_DIR) - list(APPEND VHD_SOURCES "${_VSOURCE}") - endforeach() - target_sources(${TARGET} PRIVATE ${VHD_SOURCES}) - - # Add the compile flags only on Verilated sources - foreach(VSLOW ${${VERILATE_PREFIX}_CLASSES_SLOW} ${${VERILATE_PREFIX}_SUPPORT_SLOW}) - foreach(OPT_SLOW ${VERILATE_OPT_SLOW} ${${VERILATE_PREFIX}_USER_CFLAGS}) - set_property(SOURCE "${VSLOW}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_SLOW}") + target_include_directories(${TARGET} PUBLIC ${VDIR}) + target_sources( + ${TARGET} + PRIVATE + ${GENERATED_SOURCES} + "${VCMAKE_COPY}" + ${${VERILATE_PREFIX}_GLOBAL} + ${${VERILATE_PREFIX}_USER_CLASSES} + ) + foreach(_VSOURCE ${VERILATE_SOURCES} ${${VERILATE_PREFIX}_DEPS}) + get_filename_component(_VSOURCE "${_VSOURCE}" ABSOLUTE BASE_DIR) + list(APPEND VHD_SOURCES "${_VSOURCE}") endforeach() - endforeach() - foreach(VFAST ${${VERILATE_PREFIX}_CLASSES_FAST} ${${VERILATE_PREFIX}_SUPPORT_FAST}) - foreach(OPT_FAST ${VERILATE_OPT_FAST} ${${VERILATE_PREFIX}_USER_CFLAGS}) - set_property(SOURCE "${VFAST}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_FAST}") + target_sources(${TARGET} PRIVATE ${VHD_SOURCES}) + + # Add the compile flags only on Verilated sources + foreach( + VSLOW + ${${VERILATE_PREFIX}_CLASSES_SLOW} + ${${VERILATE_PREFIX}_SUPPORT_SLOW} + ) + foreach(OPT_SLOW ${VERILATE_OPT_SLOW} ${${VERILATE_PREFIX}_USER_CFLAGS}) + set_property( + SOURCE "${VSLOW}" + APPEND_STRING + PROPERTY COMPILE_FLAGS " ${OPT_SLOW}" + ) + endforeach() endforeach() - endforeach() - foreach(VGLOBAL ${${VERILATE_PREFIX}_GLOBAL}) - foreach(OPT_GLOBAL ${VERILATE_OPT_GLOBAL} ${${VERILATE_PREFIX}_USER_CFLAGS}) - set_property(SOURCE "${VGLOBAL}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${OPT_GLOBAL}") + foreach( + VFAST + ${${VERILATE_PREFIX}_CLASSES_FAST} + ${${VERILATE_PREFIX}_SUPPORT_FAST} + ) + foreach(OPT_FAST ${VERILATE_OPT_FAST} ${${VERILATE_PREFIX}_USER_CFLAGS}) + set_property( + SOURCE "${VFAST}" + APPEND_STRING + PROPERTY COMPILE_FLAGS " ${OPT_FAST}" + ) + endforeach() + endforeach() + foreach(VGLOBAL ${${VERILATE_PREFIX}_GLOBAL}) + foreach( + OPT_GLOBAL + ${VERILATE_OPT_GLOBAL} + ${${VERILATE_PREFIX}_USER_CFLAGS} + ) + set_property( + SOURCE "${VGLOBAL}" + APPEND_STRING + PROPERTY COMPILE_FLAGS " ${OPT_GLOBAL}" + ) + endforeach() endforeach() - endforeach() - target_include_directories(${TARGET} PUBLIC "${VERILATOR_ROOT}/include" - "${VERILATOR_ROOT}/include/vltstd") - target_compile_definitions(${TARGET} PRIVATE - VM_COVERAGE=$> - VM_SC=$> - VM_TRACE=$> - VM_TRACE_VCD=$> - VM_TRACE_FST=$> - ) + target_include_directories( + ${TARGET} + PUBLIC "${VERILATOR_ROOT}/include" "${VERILATOR_ROOT}/include/vltstd" + ) + target_compile_definitions( + ${TARGET} + PRIVATE + VM_COVERAGE=$> + VM_SC=$> + VM_TRACE=$> + VM_TRACE_VCD=$> + VM_TRACE_FST=$> + ) - target_link_libraries(${TARGET} PUBLIC - ${${VERILATE_PREFIX}_USER_LDLIBS} - ) + target_link_libraries(${TARGET} PUBLIC ${${VERILATE_PREFIX}_USER_LDLIBS}) - target_link_libraries(${TARGET} PUBLIC - ${VERILATOR_MT_CFLAGS} - ) + target_link_libraries(${TARGET} PUBLIC ${VERILATOR_MT_CFLAGS}) - target_compile_features(${TARGET} PRIVATE cxx_std_11) + target_compile_features(${TARGET} PRIVATE cxx_std_11) - if (${VERILATE_PREFIX}_TIMING) - check_cxx_compiler_flag(-fcoroutines-ts COROUTINES_TS_FLAG) - target_compile_options(${TARGET} PRIVATE $,-fcoroutines-ts,-fcoroutines>) - endif() + if(${VERILATE_PREFIX}_TIMING) + check_cxx_compiler_flag(-fcoroutines-ts COROUTINES_TS_FLAG) + target_compile_options( + ${TARGET} + PRIVATE + $,-fcoroutines-ts,-fcoroutines> + ) + endif() endfunction() function(_verilator_find_systemc) - if (NOT TARGET Verilator::systemc) - # Find SystemC include file "systemc.h" in the following order: - # 1. SYSTEMC_INCLUDE (environment) variable - # 2. SYSTEMC_ROOT (environment) variable - # 3. SYSTEMC (environment) variable - # 4. Use CMake module provided by SystemC installation - # (eventually requires CMAKE_PREFIX_PATH set) + if(NOT TARGET Verilator::systemc) + # Find SystemC include file "systemc.h" in the following order: + # 1. SYSTEMC_INCLUDE (environment) variable + # 2. SYSTEMC_ROOT (environment) variable + # 3. SYSTEMC (environment) variable + # 4. Use CMake module provided by SystemC installation + # (eventually requires CMAKE_PREFIX_PATH set) - find_path(SYSTEMC_INCLUDEDIR NAMES systemc.h - HINTS "${SYSTEMC_INCLUDE} " ENV SYSTEMC_INCLUDE) - find_path(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_path( + SYSTEMC_INCLUDEDIR + NAMES systemc.h + HINTS "${SYSTEMC_INCLUDE} " + ENV SYSTEMC_INCLUDE + ) + find_path( + 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: - # 1. SYSTEMC_LIBDIR (environment) variable - # 2. SYSTEMC_ROOT (environment) variable - # 3. SYSTEMC (environment) variable - # 4. Use CMake module provided by SystemC installation - # (eventually requires CMAKE_PREFIX_PATH set) + # Find SystemC library in the following order: + # 1. SYSTEMC_LIBDIR (environment) variable + # 2. SYSTEMC_ROOT (environment) variable + # 3. SYSTEMC (environment) variable + # 4. Use CMake module provided by SystemC installation + # (eventually requires CMAKE_PREFIX_PATH set) - # Find SystemC using include and library paths - find_library(SYSTEMC_LIBRARY NAMES systemc - HINTS "${SYSTEMC_LIBDIR}" ENV SYSTEMC_LIBDIR) - find_library(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) + # Find SystemC using include and library paths + find_library( + SYSTEMC_LIBRARY + NAMES systemc + HINTS "${SYSTEMC_LIBDIR}" + ENV SYSTEMC_LIBDIR + ) + find_library( + 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) - add_library(Verilator::systemc INTERFACE IMPORTED) - set_target_properties(Verilator::systemc - PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${SYSTEMC_INCLUDEDIR}" - INTERFACE_LINK_LIBRARIES "${SYSTEMC_LIBRARY}") - return() + if(SYSTEMC_INCLUDEDIR AND SYSTEMC_LIBRARY) + add_library(Verilator::systemc INTERFACE IMPORTED) + set_target_properties( + Verilator::systemc + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SYSTEMC_INCLUDEDIR}" + INTERFACE_LINK_LIBRARIES "${SYSTEMC_LIBRARY}" + ) + return() + endif() + + find_package(SystemCLanguage QUIET) + if(SystemCLanguage_FOUND) + add_library(Verilator::systemc INTERFACE IMPORTED) + set_target_properties( + Verilator::systemc + PROPERTIES INTERFACE_LINK_LIBRARIES "SystemC::systemc" + ) + return() + endif() + + message( + "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 (environment) variable; or") + message( + "- use the CMake module of your SystemC installation (may require CMAKE_PREFIX_PATH)" + ) + message(FATAL_ERROR "SystemC not found") endif() - - find_package(SystemCLanguage QUIET) - if (SystemCLanguage_FOUND) - add_library(Verilator::systemc INTERFACE IMPORTED) - set_target_properties(Verilator::systemc - PROPERTIES - INTERFACE_LINK_LIBRARIES "SystemC::systemc") - return() - endif() - - message("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 (environment) variable; or") - message("- use the CMake module of your SystemC installation (may require CMAKE_PREFIX_PATH)") - message(FATAL_ERROR "SystemC not found") - endif() endfunction() function(verilator_link_systemc TARGET) - _verilator_find_systemc() - target_link_libraries("${TARGET}" PUBLIC Verilator::systemc) - target_compile_options(${TARGET} PRIVATE $ENV{SYSTEMC_CXX_FLAGS} ${SYSTEMC_CXX_FLAGS}) + _verilator_find_systemc() + target_link_libraries("${TARGET}" PUBLIC Verilator::systemc) + target_compile_options( + ${TARGET} + PRIVATE $ENV{SYSTEMC_CXX_FLAGS} ${SYSTEMC_CXX_FLAGS} + ) endfunction() function(verilator_generate_key OUTPUT_VARIABLE) - execute_process(COMMAND ${VERILATOR_BIN} --generate-key - OUTPUT_VARIABLE KEY_VAL - RESULT_VARIABLE KEY_RET) - if (KEY_RET) - message(FATAL_ERROR "verilator --generate-key failed") - endif() - string(STRIP ${KEY_VAL} KEY_VAL) - set(${OUTPUT_VARIABLE} ${KEY_VAL} PARENT_SCOPE) + execute_process( + COMMAND ${VERILATOR_BIN} --generate-key + OUTPUT_VARIABLE KEY_VAL + RESULT_VARIABLE KEY_RET + ) + if(KEY_RET) + message(FATAL_ERROR "verilator --generate-key failed") + endif() + string(STRIP ${KEY_VAL} KEY_VAL) + set(${OUTPUT_VARIABLE} ${KEY_VAL} PARENT_SCOPE) endfunction()