Skip to content

Commit 422bfa2

Browse files
committed
Use version set in CMake file for build_logo and func_test
Also use this as a macro in PNG render backend rather than build string in C
1 parent 8da15f6 commit 422bfa2

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ enable_language(C CXX)
55
project(saxbospiral VERSION 0.9.0 LANGUAGES C)
66
set(CMAKE_C_STANDARD 99)
77
set(CMAKE_C_STANDARD_REQUIRED ON)
8+
set(
9+
SAXBOSPIRAL_VERSION_STRING
10+
"v${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
11+
)
12+
set(SAXBOSPIRAL_ESCAPED_VERSION_STRING "\"${SAXBOSPIRAL_VERSION_STRING}\"")
813
# end basic metadata
914

1015
# pass in version of library as preprocessor definitions
1116
add_definitions(-DSAXBOSPIRAL_VERSION_MAJOR=${PROJECT_VERSION_MAJOR})
1217
add_definitions(-DSAXBOSPIRAL_VERSION_MINOR=${PROJECT_VERSION_MINOR})
1318
add_definitions(-DSAXBOSPIRAL_VERSION_PATCH=${PROJECT_VERSION_PATCH})
19+
add_definitions(-DSAXBOSPIRAL_VERSION_STRING=${SAXBOSPIRAL_ESCAPED_VERSION_STRING})
1420

1521
include(CheckCCompilerFlag)
1622

@@ -93,11 +99,11 @@ if(COMMAND_INTERPRETER)
9399
add_test(
94100
NAME func_test COMMAND ${COMMAND_INTERPRETER}
95101
# each script needs to know the path to each executable it runs
96-
"func_test.sh" sxp_prepare sxp_generate sxp_render
102+
"func_test.sh" sxp_prepare sxp_generate sxp_render "saxbospiral ${SAXBOSPIRAL_VERSION_STRING}"
97103
)
98104
add_custom_target(
99105
build_logo ${COMMAND_INTERPRETER}
100-
"build_logo.sh" sxp_prepare sxp_generate sxp_render "saxbospiral.png"
106+
"build_logo.sh" sxp_prepare sxp_generate sxp_render "saxbospiral.png" "saxbospiral ${SAXBOSPIRAL_VERSION_STRING}"
101107
)
102108
else()
103109
# warn about skipping of functional test script

build_logo.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#
33
# Script for updating the project logo
44
# The paths of the prepare, generate and render commands are
5-
# passed as the first 3 arguments. The last argument is the
6-
# file to write the PNG output to.
5+
# passed as the first 3 arguments. The 4th argument is the
6+
# file to write the PNG output to and the 5th is the message
7+
# to use for the logo data (of format "saxbospiral vX.Y.Z")
78
#
89
echo "Generating logo";
9-
echo -n "saxbospiral `git describe --abbrev=0`" > temp.hex && \
10+
echo -n "$5" > temp.hex && \
1011
./"$1" temp.hex temp.sxp && \
1112
./"$2" temp.sxp && \
1213
./"$3" temp.sxp "$4" && \

func_test.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
# Functional test script.
44
# Generates a new logo and compares with the current one.
55
# The paths of the prepare, generate and render commands are
6-
# passed as the first 3 arguments.
6+
# passed as the first 3 arguments. The 4th argument is the
7+
# message to use for the file (see build_logo.sh)
78
#
8-
./build_logo.sh "$1" "$2" "$3" "test_saxbospiral.png" && \
9+
./build_logo.sh "$1" "$2" "$3" "test_saxbospiral.png" "$4" && \
910
diff "saxbospiral.png" "test_saxbospiral.png" && \
1011
rm "test_saxbospiral.png";

saxbospiral.png

26 Bytes
Loading

saxbospiral/render_backends/png_backend.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ write_png_image(FILE * file_handle, bitmap_t bitmap) {
5252
metadata[2].key = "Copyright";
5353
metadata[2].text = "Copyright Joshua Saxby";
5454
metadata[3].key = "Software";
55-
// can't sprintf directly to the text attribute
56-
char software[25];
57-
sprintf(
58-
software, "SAXBOSPIRAL v%i.%i.%i",
59-
VERSION.major, VERSION.minor, VERSION.patch
60-
);
61-
metadata[3].text = software;
55+
// SAXBOSPIRAL_VERSION_STRING is a macro that expands to a double-quoted string
56+
metadata[3].text = "SAXBOSPIRAL " SAXBOSPIRAL_VERSION_STRING;
6257
metadata[4].key = "Comment";
6358
metadata[4].text = "https://github.com/saxbophone/saxbospiral";
6459
// set compression of each metadata key

0 commit comments

Comments
 (0)