Skip to content

Commit 49b2928

Browse files
committed
feat: Implement unified version management system
- Consolidate version information into ccap_config.h header file - Define CCAP_VERSION_MAJOR, CCAP_VERSION_MINOR, CCAP_VERSION_PATCH macros - Add CCAP_VERSION_STRING for convenient version reference - Update CMakeLists.txt for dynamic version detection - CMake now reads version directly from header file at configure time - Add robust error handling: defaults to 0.0.9999 if version parsing fails - Print warnings when version cannot be determined or header is missing - Create scripts/update_version.sh for one-command version updates - Automatically updates all version references across the project - Properly handles relative paths by detecting project root - Supports X.Y.Z semantic versioning format - Updates: ccap_config.h, ccap.podspec, conanfile.py, BUILD_AND_INSTALL.md - Update src/ccap_c.cpp to use generated version macro - ccap_get_version() now returns CCAP_VERSION_STRING from header - Update configuration files to reflect new version scheme - ccap.podspec: version bumped to 1.3.2 - BUILD_AND_INSTALL.md: current version updated to 1.3.2 - conanfile.py: version field maintained at 1.3.2 Benefits: - Single source of truth for version information in header file - Eliminates manual synchronization errors across multiple files - CI/CD friendly: version automatically picked up during build - Fallback mechanism ensures build robustness - Script provides convenient version bump workflow
1 parent e8be4ed commit 49b2928

6 files changed

Lines changed: 81 additions & 5 deletions

File tree

BUILD_AND_INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,6 @@ git clean -fdx install/
250250

251251
## Version Information
252252

253-
Current version: 1.0.0
253+
Current version: 1.3.2
254254

255255
This is the first official release of the ccap project, including complete CMake configuration and cross-platform build support.

CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,29 @@ if(CCAP_IS_ROOT_PROJECT)
2222
set(CMAKE_FETCHCONTENT_BASE_DIR "${CMAKE_SOURCE_DIR}/build" CACHE PATH "FetchContent base dir" FORCE)
2323
endif()
2424

25-
project(ccap VERSION 1.1.0 LANGUAGES C CXX)
25+
# Read version from header file
26+
set(CCAP_CONFIG_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/ccap_config.h")
27+
if(EXISTS "${CCAP_CONFIG_HEADER}")
28+
file(READ "${CCAP_CONFIG_HEADER}" ver_h)
29+
string(REGEX MATCH "#define CCAP_VERSION_MAJOR ([0-9]+)" _ "${ver_h}")
30+
set(ver_major ${CMAKE_MATCH_1})
31+
string(REGEX MATCH "#define CCAP_VERSION_MINOR ([0-9]+)" _ "${ver_h}")
32+
set(ver_minor ${CMAKE_MATCH_1})
33+
string(REGEX MATCH "#define CCAP_VERSION_PATCH ([0-9]+)" _ "${ver_h}")
34+
set(ver_patch ${CMAKE_MATCH_1})
35+
36+
if("${ver_major}" STREQUAL "" OR "${ver_minor}" STREQUAL "" OR "${ver_patch}" STREQUAL "")
37+
set(PROJECT_VERSION "0.0.9999")
38+
message(WARNING "Could not parse version from ${CCAP_CONFIG_HEADER}, using default version ${PROJECT_VERSION}")
39+
else()
40+
set(PROJECT_VERSION "${ver_major}.${ver_minor}.${ver_patch}")
41+
endif()
42+
else()
43+
set(PROJECT_VERSION "0.0.9999")
44+
message(WARNING "${CCAP_CONFIG_HEADER} not found, using default version ${PROJECT_VERSION}")
45+
endif()
46+
47+
project(ccap VERSION ${PROJECT_VERSION} LANGUAGES C CXX)
2648

2749
# Installation options
2850
option(CCAP_INSTALL "Generate installation target" ${CCAP_IS_ROOT_PROJECT})

ccap.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ccap"
3-
s.version = "1.0.0"
3+
s.version = "1.3.2"
44
s.summary = "CameraCapture And Player"
55
s.description = <<-DESC
66
Pod of https://github.com/wysaid/CameraCapture

include/ccap_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
#ifndef CCAP_CONFIG_H
1313
#define CCAP_CONFIG_H
1414

15+
/* ========== Version Information ========== */
16+
17+
#define CCAP_VERSION_MAJOR 1
18+
#define CCAP_VERSION_MINOR 3
19+
#define CCAP_VERSION_PATCH 2
20+
#define CCAP_VERSION_STRING "1.3.2"
21+
1522
/* ========== Export/Import Macro Definitions ========== */
1623

1724
// Define CCAP_EXPORT macro for symbol export/import

scripts/update_version.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Check if version argument is provided
4+
if [ -z "$1" ]; then
5+
echo "Usage: $0 <new_version>"
6+
echo "Example: $0 1.2.0"
7+
exit 1
8+
fi
9+
10+
NEW_VERSION=$1
11+
12+
# Extract major, minor, patch from version string
13+
IFS='.' read -r -a VERSION_PARTS <<< "$NEW_VERSION"
14+
MAJOR=${VERSION_PARTS[0]}
15+
MINOR=${VERSION_PARTS[1]}
16+
PATCH=${VERSION_PARTS[2]}
17+
18+
if [ -z "$MAJOR" ] || [ -z "$MINOR" ] || [ -z "$PATCH" ]; then
19+
echo "Error: Invalid version format. Expected X.Y.Z"
20+
exit 1
21+
fi
22+
23+
echo "Updating version to $NEW_VERSION (Major: $MAJOR, Minor: $MINOR, Patch: $PATCH)..."
24+
25+
# Get the project root directory (assuming script is in scripts/ folder)
26+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
27+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
28+
29+
# 1. Update include/ccap_config.h
30+
sed -i "" "s/#define CCAP_VERSION_MAJOR .*/#define CCAP_VERSION_MAJOR $MAJOR/" "$PROJECT_ROOT/include/ccap_config.h"
31+
sed -i "" "s/#define CCAP_VERSION_MINOR .*/#define CCAP_VERSION_MINOR $MINOR/" "$PROJECT_ROOT/include/ccap_config.h"
32+
sed -i "" "s/#define CCAP_VERSION_PATCH .*/#define CCAP_VERSION_PATCH $PATCH/" "$PROJECT_ROOT/include/ccap_config.h"
33+
sed -i "" "s/#define CCAP_VERSION_STRING .*/#define CCAP_VERSION_STRING \"$NEW_VERSION\"/" "$PROJECT_ROOT/include/ccap_config.h"
34+
echo "Updated include/ccap_config.h"
35+
36+
# 2. Update ccap.podspec
37+
sed -i "" "s/s.version = \".*\"/s.version = \"$NEW_VERSION\"/" "$PROJECT_ROOT/ccap.podspec"
38+
echo "Updated ccap.podspec"
39+
40+
# 3. Update conanfile.py
41+
sed -i "" "s/version = \".*\"/version = \"$NEW_VERSION\"/" "$PROJECT_ROOT/conanfile.py"
42+
echo "Updated conanfile.py"
43+
44+
# 4. Update BUILD_AND_INSTALL.md
45+
sed -i "" "s/Current version: .*/Current version: $NEW_VERSION/" "$PROJECT_ROOT/BUILD_AND_INSTALL.md"
46+
echo "Updated BUILD_AND_INSTALL.md"
47+
48+
echo "Version update complete!"

src/ccap_c.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ const char* ccap_error_code_to_string(CcapErrorCode errorCode) {
398398
}
399399

400400
const char* ccap_get_version(void) {
401-
// You may want to define this version string elsewhere
402-
return "1.0.0";
401+
return CCAP_VERSION_STRING;
403402
}
404403

405404
bool ccap_pixel_format_is_rgb(CcapPixelFormat format) {

0 commit comments

Comments
 (0)