← Back to team overview

kicad-developers team mailing list archive

TokenList2DsnLexer.cmake

 

Wayne,

Attached is a patch against TokenList2DsnLexer.cmake that I would like
to commit.

The script takes an additional *optional* parameter named "enum" which
if provided will give the name of the enum which is declared.  It seemed
like if multiple generated headers were included into a single source
file then you would have a collision on the formerly hard coded enum
name.  This lets the invoker name the enum anything he/she wants.

Also changed the use case documentation to show the *.cpp file as an
OUTPUT.  This is required for the calling CMake script to be happy WRT
how that *.cpp file comes into being.

OK to commit, or something very similar to it?

I thought I'd actually use it to hold the template fieldnames into a DSN
single line record that goes into the eeschema config file.  It was a
way to handle variable length quantities of template fields, yet still
have them in the master config file.

Each record now holds fieldname, visibility and an optional initial
value, times an unlimited number of fields.  wxConfig may break after a
few gillion fields, but this is my first plan.  I will check the source
to wxConfig before I settle on this idea. I wanted an actual small use
case to use DSNLEXER and richio showing how to use them efficiently and
unobtrusively.

Dick

=== modified file 'CMakeModules/TokenList2DsnLexer.cmake'
--- CMakeModules/TokenList2DsnLexer.cmake	2010-04-06 14:09:52 +0000
+++ CMakeModules/TokenList2DsnLexer.cmake	2010-06-14 21:22:06 +0000
@@ -39,23 +39,29 @@
 # Usage:
 #
 #     add_custom_command(
-#         OUTPUT ${CMAKE_BINARY_DIR}/cmp_library_base.h
+#         OUTPUT  ${CMAKE_BINARY_DIR}/cmp_library_base.h
+#                 ${CMAKE_BINARY_DIR}/cmp_library_base.cpp
 #         COMMAND ${CMAKE_COMMAND}
-#                 -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/token_list_file
+#                 -Denum=YOURTOK_T
+#                 -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst
 #                 -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake
 #         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst
 #    )
 #
 # Input parameters:
 #
-#     inputFile - The name of the token list file.
+#     enum       - The name of the enum to generate, defaults to DSN_T, but
+#                  you'll get collisions if you don't override it.
+#     inputFile  - The name of the token list file.
 #     outputPath - Optional output path to save the generated files.  If not defined,
 #                  the output path is the same path as the token list file path.
-#
+
 
 set( tokens "" )
 set( lineCount 0 )
 set( dsnErrorMsg "DSN token file generator failure:" )
+
+
 if( NOT EXISTS ${inputFile} )
     message( FATAL_ERROR "${dsnErrorMsg} file ${inputFile} cannot be found." )
 endif( NOT EXISTS ${inputFile} )
@@ -64,6 +70,12 @@
     get_filename_component( outputPath "${inputFile}" PATH )
 endif( NOT EXISTS ${outputPath} )
 
+if( NOT DEFINED enum )
+    set( enum DSN_T )
+endif()
+#message( STATUS "enum: ${enum}" )
+
+
 # Separate the file name without extension from the full file path.
 get_filename_component( result "${inputFile}" NAME_WE )
 
@@ -91,7 +103,7 @@
 
 namespace DSN {
 
-enum DSN_T {
+enum ${enum} {
 
     // these first few are negative special ones for syntax, and are
     // inherited from DSNLEXER.
@@ -130,7 +142,6 @@
 #define TOKDEF(x)    { #x, T_##x }
 
 const KEYWORD ${result}_keywords[] = {
-
 "
 )
 
@@ -194,7 +205,7 @@
 "};
 
 
-}        // End namespace DSN
+}   // End namespace DSN
 
 
 #endif   // End ${headerTag}
@@ -208,6 +219,6 @@
 const unsigned ${result}_keyword_count = DIM( ${result}_keywords );
 
 
-}        // End namespace DSN
+}   // End namespace DSN
 "
 )


Follow ups