cmake: Add convenience wrappers for tag generation.
authorMathias Preiner <mathias.preiner@gmail.com>
Thu, 6 Sep 2018 23:16:51 +0000 (16:16 -0700)
committerMathias Preiner <mathias.preiner@gmail.com>
Sat, 22 Sep 2018 23:30:59 +0000 (16:30 -0700)
src/base/CMakeLists.txt
src/base/genheader.sh [new file with mode: 0755]
src/base/gentags.sh [new file with mode: 0755]
src/base/gentmptags.sh [new file with mode: 0755]

index dc0b7c09c31490df31417fa24c5df33e36364611..d54564ca668cfcfe2650307d08d0735695d7db6d 100644 (file)
@@ -25,80 +25,58 @@ add_dependencies(base tags_headers)
 #
 # Generate code for debug/trace tags
 #
-set(mktags_script ${CMAKE_CURRENT_LIST_DIR}/mktags)
-set(mktagheaders_script ${CMAKE_CURRENT_LIST_DIR}/mktagheaders)
-file(GLOB_RECURSE source_files ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*.cc ${PROJECT_SOURCE_DIR}/src/*.h ${PROJECT_SOURCE_DIR}/src/*.g)
+set(gentmptags_script ${CMAKE_CURRENT_LIST_DIR}/gentmptags.sh)
+set(gentags_script ${CMAKE_CURRENT_LIST_DIR}/gentags.sh)
+set(genheader_script ${CMAKE_CURRENT_LIST_DIR}/genheader.sh)
+
+file(GLOB_RECURSE source_files
+     ${PROJECT_SOURCE_DIR}/src/*.cpp
+     ${PROJECT_SOURCE_DIR}/src/*.cc
+     ${PROJECT_SOURCE_DIR}/src/*.h
+     ${PROJECT_SOURCE_DIR}/src/*.g)
 string(REPLACE ";" " " source_files_list "${source_files}")
 
 add_custom_command(
-  OUTPUT Debug_tags.tmp
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.tmp
   COMMAND
-    ${mktags_script}
-    "Debug"
-    ${source_files_list}
-    > ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.tmp
+    ${gentmptags_script} ${CMAKE_CURRENT_LIST_DIR} Debug ${source_files_list}
   DEPENDS mktags
 )
 
 add_custom_command(
-  OUTPUT Trace_tags.tmp
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.tmp
   COMMAND
-    ${mktags_script}
-    "Trace"
-    ${source_files_list}
-    > ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.tmp
+    ${gentmptags_script} ${CMAKE_CURRENT_LIST_DIR} Trace ${source_files_list}
   DEPENDS mktags
 )
 
 add_custom_command(
-  OUTPUT Debug_tags
-  COMMAND
-    diff -q
-    ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.tmp
-    ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags
-    &> /dev/null
-    || mv
-    ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.tmp
-    ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags
-    || true
-  DEPENDS Debug_tags.tmp
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags
+  COMMAND ${gentags_script} Debug
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.tmp
 )
 
 add_custom_command(
-  OUTPUT Trace_tags
-  COMMAND
-    diff -q
-    ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.tmp
-    ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags
-    &> /dev/null
-    || mv
-    ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.tmp
-    ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags
-    || true
-  DEPENDS Trace_tags.tmp
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags
+  COMMAND ${gentags_script} Trace
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.tmp
 )
 
 add_custom_command(
-  OUTPUT Debug_tags.h
-  COMMAND
-    ${mktagheaders_script}
-    "Debug_tags"
-    ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags
-    > ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.h
-  DEPENDS Debug_tags
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.h
+  COMMAND ${genheader_script} ${CMAKE_CURRENT_LIST_DIR} Debug
+  DEPENDS mktagheaders ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags
 )
 
 add_custom_command(
-  OUTPUT Trace_tags.h
-  COMMAND
-    ${mktagheaders_script}
-    "Trace_tags"
-    ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags
-    > ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.h
-  DEPENDS Trace_tags
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.h
+  COMMAND ${genheader_script} ${CMAKE_CURRENT_LIST_DIR} Trace
+  DEPENDS mktagheaders ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags
 )
 
 add_custom_target(
   tags_headers
-  DEPENDS Debug_tags.h Trace_tags.h
+  DEPENDS
+    ${CMAKE_CURRENT_BINARY_DIR}/Debug_tags.h
+    ${CMAKE_CURRENT_BINARY_DIR}/Trace_tags.h
 )
diff --git a/src/base/genheader.sh b/src/base/genheader.sh
new file mode 100755 (executable)
index 0000000..a4bff73
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# Convenience wrapper for cmake in src/base/CMakeLists.txt
+#
+# Create Debug_tags.h/Trace_tags.h header files.
+#
+# Usage: genheader.sh <directory-mktags> Debug|Trace
+
+path="$1"
+shift
+tags_type="$1" # Debug/Trace
+tags_file="${tags_type}_tags"
+
+if [ "${tags_type}" != "Debug" -a "${tags_type}" != "Trace" ]; then
+  echo "$0: Invalid tags type '${tags_type}' (must be 'Debug' or 'Trace')"
+  exit 1
+fi
+
+[ ! -e "${tags_file}" ] && echo "$0: ${tags_file} does not exist" && exit 1
+
+${path}/mktagheaders ${tags_file} ${tags_file} > ${tags_file}.h
diff --git a/src/base/gentags.sh b/src/base/gentags.sh
new file mode 100755 (executable)
index 0000000..8c180e4
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Convenience wrapper for cmake in src/base/CMakeLists.txt
+#
+# Update Debug_tags/Trace_tags in case that debug/trace tags have been
+# modified. Use diff to compare the contents of the *.tmp files with the
+# corresponding *_tags file.
+#
+# Usage: gentags.sh Debug|Trace
+
+tags_type="$1" # Debug/Trace
+tags_file="${tags_type}_tags"
+
+if [ "${tags_type}" != "Debug" -a "${tags_type}" != "Trace" ]; then
+  echo "$0: Invalid tags type '${tags_type}' (must be 'Debug' or 'Trace')"
+  exit 1
+fi
+
+[ ! -e "${tags_file}.tmp" ] && \
+    echo "$0: ${tags_file}.tmp does not exist" && exit 1
+
+if [ -e "${tags_file}" ]; then
+  # Do not update file if tags didn't change.
+  diff -q ${tags_file}.tmp ${tags_file} &> /dev/null && exit 0
+fi
+mv ${tags_file}.tmp ${tags_file}
diff --git a/src/base/gentmptags.sh b/src/base/gentmptags.sh
new file mode 100755 (executable)
index 0000000..31404a1
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# Convenience wrapper for cmake in src/base/CMakeLists.txt
+#
+# Create Debug_tags.tmp/Trace_tags.tmp files from given source files.
+#
+# Usage: gentmptags.sh <directory-mktags> Debug|Trace <source files ...>
+
+path="$1"
+shift
+tags_type="$1"
+tags_file="${tags_type}_tags"
+shift
+source_files_list="$@"
+
+if [ "${tags_type}" != "Debug" -a "${tags_type}" != "Trace" ]; then
+  echo "$0: Invalid tags type '${tags_type}' (must be 'Debug' or 'Trace')"
+  exit 1
+fi
+
+${path}/mktags ${tags_type} ${source_files_list} > ${tags_file}.tmp