aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-08 02:13:57 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-08 06:07:04 +0100
commit4598c45d2f0279a2003fdab361685f8cba4eb38a (patch)
tree8a138385eebf857f433ac9861af9f2cbee1feb97 /CMakeLists.txt
parent66c77c3f8d77019f53675ab392eb26c20b39f457 (diff)
downloadnncmpp-4598c45d2f0279a2003fdab361685f8cba4eb38a.tar.gz
nncmpp-4598c45d2f0279a2003fdab361685f8cba4eb38a.tar.xz
nncmpp-4598c45d2f0279a2003fdab361685f8cba4eb38a.zip
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.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt16
1 files changed, 15 insertions, 1 deletions
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})