Skip to content

Commit

Permalink
update:删除不必要的文件,调整version.h的文件内容和构建方式
Browse files Browse the repository at this point in the history
  • Loading branch information
GengGode committed Dec 3, 2023
1 parent 4b629b2 commit ccd7809
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 175 deletions.
35 changes: 24 additions & 11 deletions cmake/parse_version.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
function(parse_version_file version_file)
file(READ "${version_file}" version_file_content)
string(STRIP "${version_file_content}" version_file_content)
message(STATUS "当前编译版本: ${version_file}: ${version_file_content}")
message(STATUS "当前编译版本: ${version_file_content}")
string(REPLACE "." ";" version_content_list "${version_file_content}")
list(GET version_content_list 0 version_major)
list(GET version_content_list 1 version_minor)
list(GET version_content_list 2 version_patch)
set(VERSION_MAJOR ${version_major} PARENT_SCOPE)
set(VERSION_MINOR ${version_minor} PARENT_SCOPE)
set(VERSION_PATCH ${version_patch} PARENT_SCOPE)
message(STATUS "parse_version_file: VERSION_MAJOR: ${version_major}")
endfunction(parse_version_file)

function(version_file_patch_update version_file)
Expand All @@ -25,17 +24,31 @@ endfunction(version_file_patch_update)

function(get_commit_hash hash_value)
find_package(Git QUIET)
if(NOT GIT_FOUND)
message(STATUS "git not found, skip get_commit_hash")
return()
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
OUTPUT_VARIABLE git_last_commit_hash
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
set(${hash_value} ${git_last_commit_hash} PARENT_SCOPE)
if(NOT GIT_FOUND)
message(STATUS "git not found, skip get_commit_hash")
return()
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
OUTPUT_VARIABLE git_last_commit_hash
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
set(${hash_value} ${git_last_commit_hash} PARENT_SCOPE)
endfunction(get_commit_hash)

function(get_git_branch branch_name)
find_package(Git QUIET)
if(NOT GIT_FOUND)
message(STATUS "git not found, skip get_git_branch")
return()
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE git_branch_name
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
set(${branch_name} ${git_branch_name} PARENT_SCOPE)
endfunction(get_git_branch)


function(check_commit_hash_is_dirty is_dirty)
execute_process(
COMMAND git diff-index --quiet HEAD --
Expand Down
31 changes: 13 additions & 18 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,29 @@ include_directories(src)

file(GLOB_RECURSE CppFiles "src/*.cpp")
file(GLOB_RECURSE HppFiles "src/*.h")
file(GLOB_RECURSE RcFiles "resource/*.rc")
set(VerRcFile "${CMAKE_BINARY_DIR}/resource/version.rc")
set(VerRcFile "${CMAKE_CURRENT_SOURCE_DIR}/resource/version.rc")
set(VerHppFile "${CMAKE_CURRENT_SOURCE_DIR}/resource/version.h")

auto_increment_version_file(src/version/version_hash.hash src/version/version.ver)
parse_version_file(src/version/version.ver)
auto_increment_version_file("resource/version_hash.hash" "resource/version.ver")
parse_version_file("resource/version.ver")
get_commit_hash(PROJECT_VERSION_HASH)
get_git_branch(PROJECT_VERSION_BRANCH)
set(PROJECT_VERSION_MAJOR ${VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${VERSION_PATCH})
set(PROJECT_VERSION_BUILD ${VERSION_BUILD})


# version.rc
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/resource/version.rc.in"
"${VerRcFile}"
)
configure_file("${VerRcFile}.in" "${VerRcFile}")
configure_file("${VerHppFile}.in" "${VerHppFile}")

add_definitions(-DCVAUTOTRACK_EXPORTS)
add_definitions(-DUSED_BINARY_IMAGE)
if(BUILD_CAPTURE_DXGI)
add_definitions(-DBUILD_CAPTURE_DXGI)
# file(GLOB_RECURSE DxgiCaptureCppFiles "src/dxgi/*.cpp")
# file(GLOB_RECURSE DxgiCaptureHppFiles "src/dxgi/*.h")
# list(APPEND CppFiles ${DxgiCaptureCppFiles})
# list(APPEND HppFiles ${DxgiCaptureHppFiles})
endif()


# define CVAUTOTRACK_EXPORTS
add_definitions(-DCVAUTOTRACK_EXPORTS)
add_definitions(-DUSED_BINARY_IMAGE)

source_group("include" FILES include/cvAutoTrack.h)
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${CppFiles} ${HppFiles} ${RcFiles} ${RcFile} ${VerRcFile})
source_group("version" FILES ${VerRcFile})
Expand Down Expand Up @@ -100,4 +95,4 @@ if(WITH_DYNAMIC_OPENCV)
add_custom_command(TARGET cvAutoTrack POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OpenCV_CONFIG_PATH}/../bin/opencv_world480$<$<CONFIG:Debug>:d>.dll" "$<TARGET_FILE_DIR:cvAutoTrack>")
endif()

add_custom_target(copy_version_file ALL COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/src/version/version.ver" "$<TARGET_FILE_DIR:cvAutoTrack>/version")
add_custom_target(copy_version_file ALL COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/resource/version.ver" "$<TARGET_FILE_DIR:cvAutoTrack>/version")
109 changes: 0 additions & 109 deletions source/cvAutoTrack.rc

This file was deleted.

34 changes: 0 additions & 34 deletions source/src/resource.h

This file was deleted.

1 change: 0 additions & 1 deletion source/src/resources/Resources.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "pch.h"
#include "Resources.h"
#include "resource.h"
#include "resources/import/resources.import.h"
#include "utils/convect.string.h"
#include "resources/trackCache.h"
Expand Down
1 change: 0 additions & 1 deletion source/src/version/version.ver

This file was deleted.

1 change: 0 additions & 1 deletion source/src/version/version_hash.hash

This file was deleted.

0 comments on commit ccd7809

Please sign in to comment.