Generate actions from a text file
Mostly because I wanted to nest preprocessing. This makes the build more complex and slightly less portable, but the code itself is much cleaner.
This commit is contained in:
@@ -90,8 +90,22 @@ configure_file (${PROJECT_SOURCE_DIR}/config.h.in
|
||||
${PROJECT_BINARY_DIR}/config.h)
|
||||
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
|
||||
|
||||
# Assuming a Unix-compatible system with a standalone preprocessor
|
||||
set (actions ${PROJECT_BINARY_DIR}/nncmpp-actions.h)
|
||||
add_custom_command (OUTPUT ${actions}
|
||||
COMMAND cpp -I${PROJECT_BINARY_DIR} -P ${PROJECT_SOURCE_DIR}/nncmpp.actions
|
||||
| grep . | tr [[\n]] [[\t]] | sed -ne [[y/\t/\n/]] > ${actions}
|
||||
-e [[h; s/,[^\n]*/,/g]] -e [[s/$/COUNT/]]
|
||||
-e [[s/[^\n]*/\tACTION_&/g]] -e [[s/.*/enum action {\n&\n};\n/p]]
|
||||
-e [[g; s/,[^\n]*//g; y/_/-/]] -e [[s/[^\n]\{1,\}/\t"&",/g]]
|
||||
-e [[s/.*/static const char *g_action_names[] = {\n&};\n/p]]
|
||||
-e [[g; s/[^\n]*, //g;]] -e [[s/[^\n]\{1,\}/\t"&",/g]]
|
||||
-e [[s/.*/static const char *g_action_descriptions[] = {\n&};/p]]
|
||||
COMMAND test -s ${actions}
|
||||
DEPENDS ${PROJECT_BINARY_DIR}/config.h VERBATIM)
|
||||
|
||||
# Build the main executable and link it
|
||||
add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c)
|
||||
add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c ${actions})
|
||||
target_link_libraries (${PROJECT_NAME} ${Unistring_LIBRARIES}
|
||||
${Ncursesw_LIBRARIES} termo-static ${curl_LIBRARIES} ${extra_libraries})
|
||||
add_threads (${PROJECT_NAME})
|
||||
|
||||
Reference in New Issue
Block a user