forked from github/verilator
Support Windows-native builds using cmake (#3814)
This commit is contained in:
parent
299261714b
commit
65daf99bf4
123
CMakeLists.txt
Normal file
123
CMakeLists.txt
Normal file
@ -0,0 +1,123 @@
|
||||
#*****************************************************************************
|
||||
#
|
||||
# DESCRIPTION: Script for build tool cmake on both unix and windows
|
||||
#
|
||||
#*****************************************************************************
|
||||
#
|
||||
# Copyright 2003-2022 by Wilson Snyder. This program is free software; you
|
||||
# can redistribute it and/or modify it under the terms of either the GNU
|
||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||
# Version 2.0.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
#
|
||||
#****************************************************************************/
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
cmake_policy(SET CMP0091 NEW) # Use MSVC_RUNTIME_LIBRARY to select the runtime
|
||||
project(Verilator
|
||||
VERSION 5.003
|
||||
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.")
|
||||
|
||||
set(PYTHON3 python)
|
||||
set(CMAKE_INSTALL_DATADIR ${CMAKE_INSTALL_PREFIX})
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(CheckStructHasMember)
|
||||
include(ExternalProject)
|
||||
|
||||
if (NOT WIN32)
|
||||
message(WARNING "CMake support on Linux/OSX is experimental.")
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
if (DEFINED ENV{WIN_FLEX_BISON})
|
||||
set(WIN_FLEX_BISON "$ENV{WIN_FLEX_BISON}")
|
||||
endif()
|
||||
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.")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20")
|
||||
else()
|
||||
if (NOT DEFINED ENV{FLEX_INCLUDE})
|
||||
message(FATAL_ERROR "Please set environment variable FLEX_INCLUDE to the directory containing FlexLexer.h")
|
||||
endif()
|
||||
set(WIN_FLEX_BISON "$ENV{FLEX_INCLUDE}")
|
||||
if (WIN32 AND NOT MINGW)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(BISON)
|
||||
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 ")
|
||||
error("%Error: The DEBUG_AND_RELEASE_AND_COVERAGE option is not supported in MSBuild-based builds.")
|
||||
endif()
|
||||
set(saved_build_type ${CMAKE_BUILD_TYPE})
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
add_subdirectory(src build-Debug)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
add_subdirectory(src build-Release)
|
||||
set(CMAKE_BUILD_TYPE Coverage)
|
||||
add_subdirectory(src build-Coverage)
|
||||
set(CMAKE_BUILD_TYPE ${saved_build_type})
|
||||
else()
|
||||
add_subdirectory(src)
|
||||
endif()
|
||||
|
||||
# Configuration and Installation
|
||||
|
||||
set(PACKAGE_NAME ${PROJECT_NAME})
|
||||
set(PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
|
||||
configure_file(include/verilated_config.h.in include/verilated_config.h @ONLY)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/verilated_config.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
|
||||
|
||||
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})
|
||||
|
||||
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})
|
||||
|
||||
foreach (program
|
||||
verilator_gantt
|
||||
verilator_ccache_report
|
||||
verilator_difftree
|
||||
verilator_profcfunc
|
||||
)
|
||||
install(PROGRAMS bin/${program} TYPE BIN)
|
||||
endforeach()
|
||||
|
||||
install(DIRECTORY examples TYPE DATA FILES_MATCHING
|
||||
PATTERN "examples/*/*.[chv]*"
|
||||
PATTERN "examples/*/Makefile*"
|
||||
PATTERN "examples/*/CMakeLists.txt"
|
||||
)
|
||||
|
||||
install(DIRECTORY include TYPE DATA FILES_MATCHING
|
||||
PATTERN "include/verilated_config.h"
|
||||
PATTERN "include/verilated.mk"
|
||||
PATTERN "include/*.[chv]"
|
||||
PATTERN "include/*.cpp"
|
||||
PATTERN "include/gtkwave/*.[chv]*"
|
||||
PATTERN "include/vltstd/*.[chv]*"
|
||||
)
|
@ -12,6 +12,7 @@ Verilator User's Guide
|
||||
overview.rst
|
||||
examples.rst
|
||||
install.rst
|
||||
install-cmake.rst
|
||||
|
||||
|
||||
.. toctree::
|
||||
|
70
docs/guide/install-cmake.rst
Normal file
70
docs/guide/install-cmake.rst
Normal file
@ -0,0 +1,70 @@
|
||||
.. Copyright 2003-2022 by Wilson Snyder.
|
||||
.. SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
.. _CMakeInstallation:
|
||||
|
||||
******************
|
||||
CMake Installation
|
||||
******************
|
||||
|
||||
This section discusses how to build and install Verilator using cmake.
|
||||
Currently cmake is only officially supported for Windows builds (not Linux).
|
||||
|
||||
.. _Tools Install:
|
||||
|
||||
Quick Install
|
||||
=============
|
||||
|
||||
1. Install Python for your platform from https://www.python.org/downloads/.
|
||||
2. Install CMake for your platform from https://cmake.org/download/ or build it from source.
|
||||
3. If the compiler of your choice is MSVC, then install https://visualstudio.microsoft.com/downloads/.
|
||||
If the compiler of your choice is Clang, then install https://releases.llvm.org/download.html or build it from source.
|
||||
4. For flex and bison use https://github.com/lexxmark/winflexbison to build and install.
|
||||
5. For build on Windows using MSVC set environment variable WIN_FLEX_BISON to install directory.
|
||||
For build on Windows/Linux/OSX using ninja set environment variable FLEX_INCLUDE to directory
|
||||
containing FlexLexer.h and ensure flex/bison is available on the path.
|
||||
|
||||
To obtain verilator sources download https://github.com/verilator/verilator/archive/refs/heads/master.zip
|
||||
or clone https://github.com/verilator/verilator using git :ref:`Obtain Sources`.
|
||||
|
||||
To build using msvc
|
||||
|
||||
::
|
||||
|
||||
cd verilator # directory containing source files of verilator
|
||||
mkdir build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release --install-prefix $PWD/../install
|
||||
cmake --build . --config Release
|
||||
cmake --install . --prefix $PWD/../install
|
||||
|
||||
|
||||
To build using ninja
|
||||
|
||||
::
|
||||
|
||||
cd verilator
|
||||
mkdir build
|
||||
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release --install-prefix $PWD/../install -DCMAKE_MAKE_PROGRAM=<path to ninja binary> -DBISON_EXECUTABLE=<path to bison> -DFLEX_EXECUTABLE=<path to flex>
|
||||
<path to ninja binary> #execute ninja
|
||||
cmake --install . --prefix $PWD/../install
|
||||
|
||||
.. _CMake Usage:
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
To use verilator set the environment variable ``VERILATOR_ROOT`` to install directory
|
||||
of the above build
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
::
|
||||
|
||||
cd verilator/examples
|
||||
cd cmake_hello_c
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. # cmake -G Ninja ..
|
||||
cmake --build . --config Release # ninja
|
||||
# execute the generated binary
|
@ -150,6 +150,8 @@ To make use of Verilator FST tracing you will want `GTKwave
|
||||
required at Verilator build time.
|
||||
|
||||
|
||||
.. _Obtain Sources:
|
||||
|
||||
Obtain Sources
|
||||
--------------
|
||||
|
||||
|
497
src/CMakeLists.txt
Normal file
497
src/CMakeLists.txt
Normal file
@ -0,0 +1,497 @@
|
||||
#*****************************************************************************
|
||||
#
|
||||
# DESCRIPTION: Script for build tool cmake on both unix and windows
|
||||
#
|
||||
#*****************************************************************************
|
||||
#
|
||||
# Copyright 2003-2022 by Wilson Snyder. This program is free software; you
|
||||
# can redistribute it and/or modify it under the terms of either the GNU
|
||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||
# Version 2.0.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
#
|
||||
#****************************************************************************/
|
||||
|
||||
#
|
||||
# Utilities
|
||||
macro (addBuildType sourceConfig newConfig)
|
||||
get_cmake_property(variableNames VARIABLES)
|
||||
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}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
#
|
||||
# Sources and headers for the verilator binary
|
||||
|
||||
set(HEADERS
|
||||
V3Active.h
|
||||
V3ActiveTop.h
|
||||
V3Assert.h
|
||||
V3AssertPre.h
|
||||
V3Ast.h
|
||||
V3AstConstOnly.h
|
||||
V3AstInlines.h
|
||||
V3AstNodeDType.h
|
||||
V3AstNodeExpr.h
|
||||
V3AstNodeOther.h
|
||||
V3AstUserAllocator.h
|
||||
V3Begin.h
|
||||
V3Branch.h
|
||||
V3Broken.h
|
||||
V3Case.h
|
||||
V3Cast.h
|
||||
V3CCtors.h
|
||||
V3Cdc.h
|
||||
V3Class.h
|
||||
V3Clean.h
|
||||
V3Clock.h
|
||||
V3Combine.h
|
||||
V3Common.h
|
||||
V3Config.h
|
||||
V3Const.h
|
||||
V3Coverage.h
|
||||
V3CoverageJoin.h
|
||||
V3CUse.h
|
||||
V3Dead.h
|
||||
V3Delayed.h
|
||||
V3Depth.h
|
||||
V3DepthBlock.h
|
||||
V3Descope.h
|
||||
V3Dfg.h
|
||||
V3DfgOptimizer.h
|
||||
V3DfgPasses.h
|
||||
V3DfgPeephole.h
|
||||
V3DfgVertices.h
|
||||
V3DupFinder.h
|
||||
V3EmitC.h
|
||||
V3EmitCBase.h
|
||||
V3EmitCConstInit.h
|
||||
V3EmitCFunc.h
|
||||
V3EmitCMain.h
|
||||
V3EmitCMake.h
|
||||
V3EmitMk.h
|
||||
V3EmitV.h
|
||||
V3EmitXml.h
|
||||
V3Error.h
|
||||
V3Expand.h
|
||||
V3File.h
|
||||
V3FileLine.h
|
||||
V3Force.h
|
||||
V3FunctionTraits.h
|
||||
V3Gate.h
|
||||
V3Global.h
|
||||
V3Graph.h
|
||||
V3GraphAlg.h
|
||||
V3GraphPathChecker.h
|
||||
V3GraphStream.h
|
||||
V3Hash.h
|
||||
V3Hasher.h
|
||||
V3HierBlock.h
|
||||
V3Inline.h
|
||||
V3Inst.h
|
||||
V3InstrCount.h
|
||||
V3LangCode.h
|
||||
V3LanguageWords.h
|
||||
V3Life.h
|
||||
V3LifePost.h
|
||||
V3LinkCells.h
|
||||
V3LinkDot.h
|
||||
V3LinkInc.h
|
||||
V3LinkJump.h
|
||||
V3LinkLevel.h
|
||||
V3LinkLValue.h
|
||||
V3LinkParse.h
|
||||
V3LinkResolve.h
|
||||
V3List.h
|
||||
V3Localize.h
|
||||
V3MergeCond.h
|
||||
V3Name.h
|
||||
V3Number.h
|
||||
V3OptionParser.h
|
||||
V3Options.h
|
||||
V3Order.h
|
||||
V3OrderGraph.h
|
||||
V3OrderMoveGraph.h
|
||||
V3Os.h
|
||||
V3PairingHeap.h
|
||||
V3Param.h
|
||||
V3Parse.h
|
||||
V3ParseImp.h
|
||||
V3ParseSym.h
|
||||
V3Partition.h
|
||||
V3PartitionGraph.h
|
||||
V3PreLex.h
|
||||
V3Premit.h
|
||||
V3PreProc.h
|
||||
V3PreShell.h
|
||||
V3ProtectLib.h
|
||||
V3Randomize.h
|
||||
V3Reloop.h
|
||||
V3Sched.h
|
||||
V3Scope.h
|
||||
V3Scoreboard.h
|
||||
V3SenExprBuilder.h
|
||||
V3SenTree.h
|
||||
V3Simulate.h
|
||||
V3Slice.h
|
||||
V3Split.h
|
||||
V3SplitAs.h
|
||||
V3SplitVar.h
|
||||
V3Stats.h
|
||||
V3StdFuture.h
|
||||
V3String.h
|
||||
V3Subst.h
|
||||
V3SymTable.h
|
||||
V3Table.h
|
||||
V3Task.h
|
||||
V3Timing.h
|
||||
V3Trace.h
|
||||
V3TraceDecl.h
|
||||
V3Tristate.h
|
||||
V3TSP.h
|
||||
V3Undriven.h
|
||||
V3UniqueNames.h
|
||||
V3Unknown.h
|
||||
V3Unroll.h
|
||||
V3VariableOrder.h
|
||||
V3Waiver.h
|
||||
V3Width.h
|
||||
V3WidthCommit.h
|
||||
VlcBucket.h
|
||||
VlcOptions.h
|
||||
VlcPoint.h
|
||||
VlcSource.h
|
||||
VlcTest.h
|
||||
VlcTop.h
|
||||
)
|
||||
|
||||
set(COMMON_SOURCES
|
||||
Verilator.cpp
|
||||
V3Active.cpp
|
||||
V3ActiveTop.cpp
|
||||
V3Assert.cpp
|
||||
V3AssertPre.cpp
|
||||
V3Ast.cpp
|
||||
V3AstNodes.cpp
|
||||
V3Begin.cpp
|
||||
V3Branch.cpp
|
||||
V3Broken.cpp
|
||||
V3CCtors.cpp
|
||||
V3Cuse.cpp
|
||||
V3Case.cpp
|
||||
V3Cast.cpp
|
||||
V3Cdc.cpp
|
||||
V3Class.cpp
|
||||
V3Clean.cpp
|
||||
V3Clock.cpp
|
||||
V3Combine.cpp
|
||||
V3Common.cpp
|
||||
V3Config.cpp
|
||||
V3Const__gen.cpp
|
||||
V3Coverage.cpp
|
||||
V3CoverageJoin.cpp
|
||||
V3Dead.cpp
|
||||
V3Delayed.cpp
|
||||
V3Depth.cpp
|
||||
V3DepthBlock.cpp
|
||||
V3Descope.cpp
|
||||
V3Dfg.cpp
|
||||
V3DfgAstToDfg.cpp
|
||||
V3DfgDecomposition.cpp
|
||||
V3DfgDfgToAst.cpp
|
||||
V3DfgOptimizer.cpp
|
||||
V3DfgPasses.cpp
|
||||
V3DfgPeephole.cpp
|
||||
V3DupFinder.cpp
|
||||
V3Timing.cpp
|
||||
V3EmitCBase.cpp
|
||||
V3EmitCConstPool.cpp
|
||||
V3EmitCFunc.cpp
|
||||
V3EmitCHeaders.cpp
|
||||
V3EmitCImp.cpp
|
||||
V3EmitCInlines.cpp
|
||||
V3EmitCMain.cpp
|
||||
V3EmitCMake.cpp
|
||||
V3EmitCModel.cpp
|
||||
V3EmitCSyms.cpp
|
||||
V3EmitMk.cpp
|
||||
V3EmitV.cpp
|
||||
V3EmitXml.cpp
|
||||
V3Error.cpp
|
||||
V3Expand.cpp
|
||||
V3File.cpp
|
||||
V3FileLine.cpp
|
||||
V3Force.cpp
|
||||
V3Gate.cpp
|
||||
V3Global.cpp
|
||||
V3Graph.cpp
|
||||
V3GraphAcyc.cpp
|
||||
V3GraphAlg.cpp
|
||||
V3GraphPathChecker.cpp
|
||||
V3GraphTest.cpp
|
||||
V3Hash.cpp
|
||||
V3Hasher.cpp
|
||||
V3HierBlock.cpp
|
||||
V3Inline.cpp
|
||||
V3Inst.cpp
|
||||
V3InstrCount.cpp
|
||||
V3Life.cpp
|
||||
V3LifePost.cpp
|
||||
V3LinkCells.cpp
|
||||
V3LinkDot.cpp
|
||||
V3LinkInc.cpp
|
||||
V3LinkJump.cpp
|
||||
V3LinkLevel.cpp
|
||||
V3LinkLValue.cpp
|
||||
V3LinkParse.cpp
|
||||
V3LinkResolve.cpp
|
||||
V3Localize.cpp
|
||||
V3MergeCond.cpp
|
||||
V3Name.cpp
|
||||
V3Number.cpp
|
||||
V3OptionParser.cpp
|
||||
V3Options.cpp
|
||||
V3Order.cpp
|
||||
V3Os.cpp
|
||||
V3Param.cpp
|
||||
V3Partition.cpp
|
||||
V3PreShell.cpp
|
||||
V3Premit.cpp
|
||||
V3ProtectLib.cpp
|
||||
V3Randomize.cpp
|
||||
V3Reloop.cpp
|
||||
V3Sched.cpp
|
||||
V3SchedAcyclic.cpp
|
||||
V3SchedPartition.cpp
|
||||
V3SchedReplicate.cpp
|
||||
V3SchedTiming.cpp
|
||||
V3Scope.cpp
|
||||
V3Scoreboard.cpp
|
||||
V3Slice.cpp
|
||||
V3Split.cpp
|
||||
V3SplitAs.cpp
|
||||
V3SplitVar.cpp
|
||||
V3Stats.cpp
|
||||
V3StatsReport.cpp
|
||||
V3String.cpp
|
||||
V3Subst.cpp
|
||||
V3Table.cpp
|
||||
V3Task.cpp
|
||||
V3Trace.cpp
|
||||
V3TraceDecl.cpp
|
||||
V3Tristate.cpp
|
||||
V3TSP.cpp
|
||||
V3Undriven.cpp
|
||||
V3Unknown.cpp
|
||||
V3Unroll.cpp
|
||||
V3VariableOrder.cpp
|
||||
V3Waiver.cpp
|
||||
V3Width.cpp
|
||||
V3WidthSel.cpp
|
||||
V3ParseImp.cpp
|
||||
V3ParseGrammar.cpp
|
||||
V3ParseLex.cpp
|
||||
V3PreProc.cpp
|
||||
)
|
||||
|
||||
SET(COVERAGE_SOURCES
|
||||
VlcMain.cpp
|
||||
)
|
||||
|
||||
# Note about tests:
|
||||
# VlcMain.cpp #includes the following files:
|
||||
# V3Error.cpp, V3String.cpp, V3Os.cpp and VlcTop.cpp
|
||||
# V3Number_test.cpp #includes the following files:
|
||||
# V3FileLine.cpp
|
||||
|
||||
#
|
||||
# Generated sources and headers for the verilator binary
|
||||
|
||||
set(srcdir ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
file(TO_NATIVE_PATH ${srcdir}/astgen ASTGEN)
|
||||
file(TO_NATIVE_PATH ${srcdir}/bisonpre BISONPRE)
|
||||
file(TO_NATIVE_PATH ${srcdir}/flexfix FLEXFIX)
|
||||
file(TO_NATIVE_PATH ${srcdir}/../bin/verilator_includer VERILATOR_INCLUDER)
|
||||
file(TO_NATIVE_PATH ${srcdir}/vlcovgen VLCOVGEN)
|
||||
file(TO_NATIVE_PATH ${srcdir}/config_rev CONFIG_REV)
|
||||
|
||||
configure_file(config_build.h.in config_build.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
|
||||
)
|
||||
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")
|
||||
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}"
|
||||
)
|
||||
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")
|
||||
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}"
|
||||
)
|
||||
# Output used by another command
|
||||
|
||||
set(FLEX_V3Lexer_OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/V3Lexer.yy.cpp)
|
||||
add_custom_command(
|
||||
OUTPUT V3Lexer.yy.cpp
|
||||
MAIN_DEPENDENCY ${FLEX_V3Lexer_pregen_OUTPUTS}
|
||||
DEPENDS ${FLEXFIX}
|
||||
COMMAND ${PYTHON3} 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})
|
||||
# Output included by another source file
|
||||
|
||||
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"
|
||||
)
|
||||
# Output used by another command
|
||||
|
||||
set(FLEX_V3PreLex_OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/V3PreLex.yy.cpp)
|
||||
add_custom_command(
|
||||
OUTPUT V3PreLex.yy.cpp
|
||||
MAIN_DEPENDENCY ${FLEX_V3PreLex_pregen_OUTPUTS}
|
||||
DEPENDS ${FLEXFIX}
|
||||
COMMAND ${PYTHON3} 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})
|
||||
# Output included by another source file
|
||||
|
||||
set(gitHead ${srcdir}/../.git/logs/HEAD)
|
||||
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}" > "$<SHELL_PATH:${CMAKE_CURRENT_BINARY_DIR}/config_rev.h>"
|
||||
)
|
||||
list(APPEND GENERATED_FILES config_rev.h)
|
||||
# Output used directly by the `verilator` target
|
||||
|
||||
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
|
||||
)
|
||||
list(APPEND GENERATED_FILES ${astgen_name}__gen.cpp)
|
||||
endforeach()
|
||||
|
||||
#
|
||||
# Set up the Coverage build type
|
||||
|
||||
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
|
||||
# a phony target (it doesn't exist as a file).
|
||||
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}
|
||||
)
|
||||
|
||||
#
|
||||
# Set up the verilator binary target
|
||||
|
||||
set(verilator verilator${CMAKE_BUILD_TYPE})
|
||||
|
||||
add_executable(${verilator}
|
||||
$<$<NOT:$<CONFIG:COVERAGE>>:${COMMON_SOURCES}>
|
||||
$<$<NOT:$<CONFIG:COVERAGE>>:${GENERATED_FILES}>
|
||||
$<$<CONFIG:COVERAGE>:${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 $<IF:$<CONFIG:DEBUG>,FALSE,${CMAKE_UNITY_BUILD}>
|
||||
MSVC_RUNTIME_LIBRARY MultiThreaded$<IF:$<CONFIG:Release>,,DebugDLL>
|
||||
#JOB_POOL_LINK one_job # Linking takes lots of resources
|
||||
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
||||
)
|
||||
|
||||
add_dependencies(${verilator}
|
||||
V3Lexer_yy_cpp${CMAKE_BUILD_TYPE}
|
||||
V3PreLex_yy_cpp${CMAKE_BUILD_TYPE}
|
||||
)
|
||||
|
||||
# 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)
|
||||
add_dependencies(${verilator} vlcovgen.d${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
|
||||
if (NOT MSVC)
|
||||
target_compile_features(${verilator} PRIVATE cxx_std_11)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${verilator} PRIVATE
|
||||
YYDEBUG # Required to get nice error messages
|
||||
$<$<CONFIG:DEBUG>:VL_DEBUG>
|
||||
$<$<CONFIG:DEBUG>:_GLIBCXX_DEBUG>
|
||||
)
|
||||
|
||||
target_include_directories(${verilator}
|
||||
PRIVATE
|
||||
../include
|
||||
${WIN_FLEX_BISON}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
target_compile_definitions(${verilator} PRIVATE
|
||||
YY_NO_UNISTD_H
|
||||
)
|
||||
target_include_directories(${verilator} PRIVATE ../platform/win32)
|
||||
target_link_libraries(${verilator} PRIVATE bcrypt psapi)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${verilator})
|
Loading…
Reference in New Issue
Block a user