Files
yosys/cmake/PmgenCommand.cmake
tangxifan 02dc5a82d7 [core] add a cmake option to disable unit test during compilation; Use cmake_current_source for submodule integration
[core] debug yosys version extraction

[core] debug

[core] now cache the cmake source dir

[core] debug

[core] debug kernel dependencies

[core] debug common include directories

[core] debug

[core] debug simlib_help.inc

[core] debug pmgen py path in cmake

[core] syntax

[core] debug flex source

[core] restore

[core] debug executable output as it now shows linking to .

[core] debug yosys-abc directory

[core] debug cmake share directory

[core] debug yosys abc

[core] restore shared directory location as yosys requires fixed location

[core] rework link target to yosys sub dir under build

[core] fixed the bug on yosys-config.install location for install

[core] cmake syntax

[core] correct the location for share directory

[core] debug

[core] debug

[core] debug

[core] enforce internal attributes; rename the YOSYS_ENABLE_UNIT_TESTS; use YOSYS_CMAKE_BINARY_DIR for all

[core] apply review comments

[core] rename

[core] change all the CMAKE_BINARY_DIR to YOSYS_CMAKE_BINARY_DIR

[core] replace CMAKE_SOURCE_DIR to YOSYS_CMAKE_SOURCE_DIR
2026-08-21 12:09:04 -07:00

61 lines
1.7 KiB
CMake

# Syntax:
#
# pmgen_command(<output>
# [<input>...]
# [PREFIX <prefix>]
# [DEBUG]
# )
#
# Builds `<output>_pm.h` in the current binary directory from pmgen source files `<input>`, which must have
# the `*.pmg` extension. If `<input>...` contains more than one file, `<prefix>` must be provided.
#
# Defines the following variables:
# - `PMGEN_<output>_DEFINED`: Boolean indicating whether this command was successfully invoked.
# - `PMGEN_<output>_OUTPUT`: The header file generated by `pmgen`.
#
# Usage example:
#
# pmgen_command(my_dsp
# my_dsp.pmg
# )
# yosys_pass(my_dsp
# my_dsp.cc
# ${PMGEN_my_dsp_OUTPUT}
# )
#
# Usage example with multiple files:
#
# pmgen_command(my_dsp
# my_dsp_macc.pmg
# my_dsp_carry.pmg
# PREFIX
# my_dsp
# )
#
function(pmgen_command arg_NAME)
cmake_parse_arguments(PARSE_ARGV 1 arg "DEBUG" "PREFIX" "")
set(arg_INPUTS ${arg_UNPARSED_ARGUMENTS})
set(pmgen_script ${YOSYS_CMAKE_SOURCE_DIR}/passes/pmgen/pmgen.py)
set(pmgen_output ${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}_pm.h)
cmake_path(RELATIVE_PATH pmgen_output BASE_DIRECTORY ${YOSYS_CMAKE_BINARY_DIR} OUTPUT_VARIABLE pmgen_output_rel)
add_custom_command(
DEPENDS ${pmgen_script} ${arg_INPUTS}
OUTPUT ${pmgen_output}
COMMAND ${Python3_EXECUTABLE}
${pmgen_script}
"$<$<BOOL:${arg_DEBUG}>:-g>"
"$<$<BOOL:${arg_PREFIX}>:-p;${arg_PREFIX}>"
-o ${pmgen_output}
${arg_INPUTS}
COMMAND_EXPAND_LISTS
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
COMMENT "Compiling pattern matcher ${pmgen_output_rel}"
)
# The usage of this command is somewhat inspired by `flex_target()` and `bison_target()`.
set(PMGEN_${arg_NAME}_DEFINED TRUE)
set(PMGEN_${arg_NAME}_OUTPUT ${pmgen_output} PARENT_SCOPE)
endfunction()