From: Mathias Preiner Date: Thu, 6 Sep 2018 23:16:51 +0000 (-0700) Subject: cmake: Add convenience wrappers for tag generation. X-Git-Tag: cvc5-1.0.0~4574 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8b0870f933986c29bb40e685d7f3f3fa56ef6b7b;p=cvc5.git cmake: Add convenience wrappers for tag generation. --- diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index dc0b7c09c..d54564ca6 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -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 index 000000000..a4bff7306 --- /dev/null +++ b/src/base/genheader.sh @@ -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 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 index 000000000..8c180e410 --- /dev/null +++ b/src/base/gentags.sh @@ -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 index 000000000..31404a16a --- /dev/null +++ b/src/base/gentmptags.sh @@ -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 Debug|Trace + +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