# Syntax: # # pmgen_command( # [...] # [PREFIX ] # [DEBUG] # ) # # Builds `_pm.h` in the current binary directory from pmgen source files ``, which must have # the `*.pmg` extension. If `...` contains more than one file, `` must be provided. # # Defines the following variables: # - `PMGEN__DEFINED`: Boolean indicating whether this command was successfully invoked. # - `PMGEN__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 ${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 ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE pmgen_output_rel) add_custom_command( DEPENDS ${pmgen_script} ${arg_INPUTS} OUTPUT ${pmgen_output} COMMAND ${Python3_EXECUTABLE} ${pmgen_script} "$<$:-g>" "$<$:-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()