Skip to content

Commit

Permalink
Use version set in CMake file for build_logo and func_test
Browse files Browse the repository at this point in the history
Also use this as a macro in PNG render backend rather than build string in C
  • Loading branch information
saxbophone committed Aug 28, 2016
1 parent 8da15f6 commit 422bfa2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ enable_language(C CXX)
project(saxbospiral VERSION 0.9.0 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(
SAXBOSPIRAL_VERSION_STRING
"v${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
)
set(SAXBOSPIRAL_ESCAPED_VERSION_STRING "\"${SAXBOSPIRAL_VERSION_STRING}\"")
# end basic metadata

# pass in version of library as preprocessor definitions
add_definitions(-DSAXBOSPIRAL_VERSION_MAJOR=${PROJECT_VERSION_MAJOR})
add_definitions(-DSAXBOSPIRAL_VERSION_MINOR=${PROJECT_VERSION_MINOR})
add_definitions(-DSAXBOSPIRAL_VERSION_PATCH=${PROJECT_VERSION_PATCH})
add_definitions(-DSAXBOSPIRAL_VERSION_STRING=${SAXBOSPIRAL_ESCAPED_VERSION_STRING})

include(CheckCCompilerFlag)

Expand Down Expand Up @@ -93,11 +99,11 @@ if(COMMAND_INTERPRETER)
add_test(
NAME func_test COMMAND ${COMMAND_INTERPRETER}
# each script needs to know the path to each executable it runs
"func_test.sh" sxp_prepare sxp_generate sxp_render
"func_test.sh" sxp_prepare sxp_generate sxp_render "saxbospiral ${SAXBOSPIRAL_VERSION_STRING}"
)
add_custom_target(
build_logo ${COMMAND_INTERPRETER}
"build_logo.sh" sxp_prepare sxp_generate sxp_render "saxbospiral.png"
"build_logo.sh" sxp_prepare sxp_generate sxp_render "saxbospiral.png" "saxbospiral ${SAXBOSPIRAL_VERSION_STRING}"
)
else()
# warn about skipping of functional test script
Expand Down
7 changes: 4 additions & 3 deletions build_logo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#
# Script for updating the project logo
# The paths of the prepare, generate and render commands are
# passed as the first 3 arguments. The last argument is the
# file to write the PNG output to.
# passed as the first 3 arguments. The 4th argument is the
# file to write the PNG output to and the 5th is the message
# to use for the logo data (of format "saxbospiral vX.Y.Z")
#
echo "Generating logo";
echo -n "saxbospiral `git describe --abbrev=0`" > temp.hex && \
echo -n "$5" > temp.hex && \
./"$1" temp.hex temp.sxp && \
./"$2" temp.sxp && \
./"$3" temp.sxp "$4" && \
Expand Down
5 changes: 3 additions & 2 deletions func_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
# Functional test script.
# Generates a new logo and compares with the current one.
# The paths of the prepare, generate and render commands are
# passed as the first 3 arguments.
# passed as the first 3 arguments. The 4th argument is the
# message to use for the file (see build_logo.sh)
#
./build_logo.sh "$1" "$2" "$3" "test_saxbospiral.png" && \
./build_logo.sh "$1" "$2" "$3" "test_saxbospiral.png" "$4" && \
diff "saxbospiral.png" "test_saxbospiral.png" && \
rm "test_saxbospiral.png";
Binary file modified saxbospiral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions saxbospiral/render_backends/png_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@ write_png_image(FILE * file_handle, bitmap_t bitmap) {
metadata[2].key = "Copyright";
metadata[2].text = "Copyright Joshua Saxby";
metadata[3].key = "Software";
// can't sprintf directly to the text attribute
char software[25];
sprintf(
software, "SAXBOSPIRAL v%i.%i.%i",
VERSION.major, VERSION.minor, VERSION.patch
);
metadata[3].text = software;
// SAXBOSPIRAL_VERSION_STRING is a macro that expands to a double-quoted string
metadata[3].text = "SAXBOSPIRAL " SAXBOSPIRAL_VERSION_STRING;
metadata[4].key = "Comment";
metadata[4].text = "https://github.com/saxbophone/saxbospiral";
// set compression of each metadata key
Expand Down

0 comments on commit 422bfa2

Please sign in to comment.