Allow lexers to build into kicommon
This commit is contained in:
parent
8d9185919a
commit
23f35e1c8b
|
@ -56,6 +56,10 @@
|
|||
# *.h lexfer file. If not defined, the output path is the same
|
||||
# path as the token list file path, with a file name of *_lexer.h
|
||||
#
|
||||
# exportMacro - Optional, the name of the macro used for dllexport/dllimport and is used
|
||||
# to mark the class for export
|
||||
# exportMacroInclude - Optional, a include that is added for use of the export macro
|
||||
#
|
||||
# Use the max_lexer() CMake function from functions.cmake for invocation convenience.
|
||||
|
||||
|
||||
|
@ -92,6 +96,10 @@ if( NOT DEFINED outHeaderFile )
|
|||
set( outHeaderFile "${outputPath}/${result}_lexer.h" )
|
||||
endif()
|
||||
|
||||
if( exportMacro )
|
||||
set( exportMacro "${exportMacro} ")
|
||||
endif()
|
||||
|
||||
# Create tag for generating header file.
|
||||
set( headerTag "${LEXERCLASS}_H_" )
|
||||
|
||||
|
@ -105,7 +113,18 @@ set( includeFileHeader
|
|||
#define ${headerTag}
|
||||
|
||||
#include <dsnlexer.h>
|
||||
")
|
||||
|
||||
if( exportMacroInclude )
|
||||
set( includeFileHeader
|
||||
"${includeFileHeader}
|
||||
#include <${exportMacroInclude}>
|
||||
"
|
||||
)
|
||||
endif()
|
||||
|
||||
set( includeFileHeader
|
||||
"${includeFileHeader}
|
||||
/**
|
||||
* C++ does not put enum _values_ in separate namespaces unless the enum itself
|
||||
* is in a separate namespace. All the token enums must be in separate namespaces
|
||||
|
@ -234,7 +253,7 @@ file( APPEND "${outHeaderFile}"
|
|||
* technology, based on keywords provided by file:
|
||||
* ${inputFile}
|
||||
*/
|
||||
class ${LEXERCLASS} : public DSNLEXER
|
||||
class ${exportMacro}${LEXERCLASS} : public DSNLEXER
|
||||
{
|
||||
/// Auto generated lexer keywords table and length:
|
||||
static const KEYWORD keywords[];
|
||||
|
@ -397,7 +416,7 @@ const char* ${LEXERCLASS}::TokenName( T aTok )
|
|||
)
|
||||
|
||||
|
||||
file( APPEND "${outCppFile}"
|
||||
file( APPEND "${outCppFile}"
|
||||
"
|
||||
|
||||
const KEYWORD_MAP ${LEXERCLASS}::keywords_hash({
|
||||
|
@ -410,7 +429,7 @@ math( EXPR tokensAfter "${tokensAfter} - 1" )
|
|||
|
||||
foreach( token ${tokens} )
|
||||
file(APPEND "${outCppFile}" " { \"${token}\", ${TOKEN_NUM} }" )
|
||||
|
||||
|
||||
if( TOKEN_NUM EQUAL tokensAfter )
|
||||
file( APPEND "${outCppFile}" "\n" )
|
||||
else( TOKEN_NUM EQUAL tokensAfter )
|
||||
|
|
|
@ -19,19 +19,12 @@
|
|||
# or you may search the http://www.gnu.org website for the version 2 license,
|
||||
# or you may write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
#
|
||||
|
||||
|
||||
# Function make_lexer
|
||||
# is a standard way to invoke TokenList2DsnLexer.cmake.
|
||||
# Extra arguments are treated as source files which depend on the generated
|
||||
# files. Some detail here on the indirection:
|
||||
# - Parallel builds all depend on the same files, and CMake will generate the same file multiple times in the same location.
|
||||
# This can be problematic if the files are generated at the same time and overwrite each other.
|
||||
# - To fix this, we create a custom target (outputTarget) that the parallel builds depend on.
|
||||
# AND build dependencies. This creates the needed rebuild for appropriate source object changes.
|
||||
function( make_lexer outputTarget inputFile outHeaderFile outCppFile enum )
|
||||
|
||||
# make_lexer_export
|
||||
# This function performs the same job as make_lexer but with two additional parameters to specify
|
||||
# the export macro
|
||||
function( make_lexer_export outputTarget inputFile outHeaderFile outCppFile enum exportMacro exportMacroInclude )
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${outHeaderFile}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${outCppFile}
|
||||
|
@ -40,6 +33,8 @@ function( make_lexer outputTarget inputFile outHeaderFile outCppFile enum )
|
|||
-DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/${inputFile}
|
||||
-DoutHeaderFile=${CMAKE_CURRENT_BINARY_DIR}/${outHeaderFile}
|
||||
-DoutCppFile=${CMAKE_CURRENT_BINARY_DIR}/${outCppFile}
|
||||
-DexportMacro=${exportMacro}
|
||||
-DexportMacroInclude=${exportMacroInclude}
|
||||
-P ${KICAD_CMAKE_MODULE_PATH}/BuildSteps/TokenList2DsnLexer.cmake
|
||||
COMMENT "TokenList2DsnLexer.cmake creating:
|
||||
${outHeaderFile} and
|
||||
|
@ -54,6 +49,19 @@ function( make_lexer outputTarget inputFile outHeaderFile outCppFile enum )
|
|||
endfunction()
|
||||
|
||||
|
||||
# Function make_lexer
|
||||
# is a standard way to invoke TokenList2DsnLexer.cmake.
|
||||
# Extra arguments are treated as source files which depend on the generated
|
||||
# files. Some detail here on the indirection:
|
||||
# - Parallel builds all depend on the same files, and CMake will generate the same file multiple times in the same location.
|
||||
# This can be problematic if the files are generated at the same time and overwrite each other.
|
||||
# - To fix this, we create a custom target (outputTarget) that the parallel builds depend on.
|
||||
# AND build dependencies. This creates the needed rebuild for appropriate source object changes.
|
||||
function( make_lexer outputTarget inputFile outHeaderFile outCppFile enum )
|
||||
make_lexer_export( ${outputTarget} ${inputFile} ${outHeaderFile} ${outCppFile} ${enum} "" "" )
|
||||
endfunction()
|
||||
|
||||
|
||||
# Function generate_lemon_grammar
|
||||
#
|
||||
# This is a function to create a custom command to generate a parser grammar using lemon.
|
||||
|
|
|
@ -781,21 +781,25 @@ generate_lemon_grammar(
|
|||
# Called twice one for common and one for gal, to ensure the files are created
|
||||
# on all devel tools ( Linux and msys2 )
|
||||
# works on Linux:
|
||||
make_lexer(
|
||||
common
|
||||
make_lexer_export(
|
||||
kicommon
|
||||
stroke_params.keywords
|
||||
stroke_params_lexer.h
|
||||
stroke_params_keywords.cpp
|
||||
STROKEPARAMS_T
|
||||
KICOMMON_API
|
||||
kicommon.h
|
||||
)
|
||||
|
||||
# auto-generate netlist_lexer.h and netlist_keywords.cpp
|
||||
make_lexer(
|
||||
common
|
||||
make_lexer_export(
|
||||
kicommon
|
||||
netlist.keywords
|
||||
netlist_lexer.h
|
||||
netlist_keywords.cpp
|
||||
NL_T
|
||||
KICOMMON_API
|
||||
kicommon.h
|
||||
)
|
||||
|
||||
# auto-generate pcb_plot_params_lexer.h and pcb_plot_params_keywords.cpp
|
||||
|
@ -808,12 +812,14 @@ make_lexer(
|
|||
)
|
||||
|
||||
# auto-generate drc_rules_lexer.h and drc_rules_keywords.cpp
|
||||
make_lexer(
|
||||
common
|
||||
make_lexer_export(
|
||||
kicommon
|
||||
drc_rules.keywords
|
||||
drc_rules_lexer.h
|
||||
drc_rules_keywords.cpp
|
||||
DRCRULE_T
|
||||
KICOMMON_API
|
||||
kicommon.h
|
||||
)
|
||||
|
||||
|
||||
|
@ -827,31 +833,37 @@ make_lexer(
|
|||
)
|
||||
|
||||
# auto-generate s-expression library table code.
|
||||
make_lexer(
|
||||
common
|
||||
make_lexer_export(
|
||||
kicommon
|
||||
lib_table.keywords
|
||||
lib_table_lexer.h
|
||||
lib_table_keywords.cpp
|
||||
LIB_TABLE_T
|
||||
KICOMMON_API
|
||||
kicommon.h
|
||||
)
|
||||
|
||||
# auto-generate s-expression template fieldnames lexer and keywords.
|
||||
make_lexer(
|
||||
common
|
||||
make_lexer_export(
|
||||
kicommon
|
||||
template_fieldnames.keywords
|
||||
template_fieldnames_lexer.h
|
||||
template_fieldnames_keywords.cpp
|
||||
TFIELD_T
|
||||
KICOMMON_API
|
||||
kicommon.h
|
||||
)
|
||||
|
||||
# auto-generate page layout reader s-expression page_layout_reader_lexer.h
|
||||
# and title_block_reader_keywords.cpp.
|
||||
make_lexer(
|
||||
common
|
||||
make_lexer_export(
|
||||
kicommon
|
||||
drawing_sheet/drawing_sheet.keywords
|
||||
drawing_sheet/drawing_sheet_lexer.h
|
||||
drawing_sheet/drawing_sheet_keywords.cpp
|
||||
DRAWINGSHEET_T
|
||||
KICOMMON_API
|
||||
kicommon.h
|
||||
)
|
||||
|
||||
# This one gets made only when testing.
|
||||
|
|
Loading…
Reference in New Issue