Skip to content

Commit cc88575

Browse files
tanxiaoP33M
authored andcommitted
add version string to binary info
1 parent d1cd911 commit cc88575

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ pico_generate_pio_header(debugprobe ${CMAKE_CURRENT_LIST_DIR}/src/autobaud.pio)
4747

4848
target_include_directories(debugprobe PRIVATE src)
4949

50+
# add version
51+
add_custom_target(version
52+
${CMAKE_SOURCE_DIR}/get-version.sh
53+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
54+
)
55+
56+
target_include_directories(debugprobe PRIVATE
57+
${CMAKE_BINARY_DIR}/generated
58+
)
59+
60+
add_dependencies(debugprobe version)
61+
5062
target_compile_definitions (debugprobe PRIVATE
5163
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
5264
)

get-version.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
if command -v git &>/dev/null
3+
then
4+
VERSION=$(git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD)
5+
else
6+
VERSION="unknown"
7+
fi
8+
9+
if [ ! -e generated/probe ]
10+
then
11+
mkdir -p generated/probe
12+
fi
13+
14+
cat > generated/probe/version.h << EOF
15+
#ifndef _PROBE_VERSION_H
16+
#define _PROBE_VERSION_H
17+
18+
#define PROBE_VERSION "${VERSION}"
19+
20+
#endif
21+
EOF

src/probe_config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include "probe_config.h"
22
#include "pico/binary_info.h"
3-
3+
#include "probe/version.h"
44

55
#define STR_HELPER(x) #x
66
#define STR(x) STR_HELPER(x)
77

88

99
void bi_decl_config()
1010
{
11+
bi_decl(bi_program_version_string(PROBE_VERSION));
1112
#ifdef PROBE_PIN_RESET
1213
bi_decl(bi_1pin_with_name(PROBE_PIN_RESET, "PROBE RESET"));
1314
#endif

0 commit comments

Comments
 (0)