From 4598c45d2f0279a2003fdab361685f8cba4eb38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 8 Nov 2021 02:13:57 +0100 Subject: 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. --- CMakeLists.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 17c70ec..12bc35a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) -- cgit v1.2.3