mirror of
https://git.familie-radermacher.ch/linux/ptouch-print.git
synced 2025-05-13 15:22:56 +00:00
trying to add support for generating version info from git (does not work yet)
This commit is contained in:
parent
8655736e75
commit
cd4e99b9e5
@ -44,7 +44,6 @@ target_compile_definitions(ptouch-print
|
|||||||
USING_CMAKE=1
|
USING_CMAKE=1
|
||||||
VERSION="${VERSION}"
|
VERSION="${VERSION}"
|
||||||
PACKAGE="ptouch"
|
PACKAGE="ptouch"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(ptouch-print
|
target_include_directories(ptouch-print
|
||||||
@ -59,3 +58,12 @@ target_link_libraries(ptouch-print
|
|||||||
${GD_LIBRARIES}
|
${GD_LIBRARIES}
|
||||||
${LIBUSB_LIBRARIES}
|
${LIBUSB_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Add a custom command that produces version.cpp, plus
|
||||||
|
# a dummy output that's not actually produced, in order
|
||||||
|
# to force version.cmake to always be re-run before the build
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/_version.cpp
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)
|
||||||
|
43
cmake/version.cmake
Normal file
43
cmake/version.cmake
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
execute_process(COMMAND git log --pretty=format:'%h' -n 1
|
||||||
|
OUTPUT_VARIABLE GIT_REV
|
||||||
|
ERROR_QUIET)
|
||||||
|
|
||||||
|
# Check whether we got any revision (which isn't
|
||||||
|
# always the case, e.g. when someone downloaded a zip
|
||||||
|
# file from Github instead of a checkout)
|
||||||
|
if ("${GIT_REV}" STREQUAL "")
|
||||||
|
set(GIT_REV "N/A")
|
||||||
|
set(GIT_DIFF "")
|
||||||
|
set(GIT_TAG "N/A")
|
||||||
|
set(GIT_BRANCH "N/A")
|
||||||
|
else()
|
||||||
|
execute_process(
|
||||||
|
COMMAND bash -c "git diff --quiet --exit-code || echo +"
|
||||||
|
OUTPUT_VARIABLE GIT_DIFF)
|
||||||
|
execute_process(
|
||||||
|
COMMAND git describe --exact-match --tags
|
||||||
|
OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
|
||||||
|
execute_process(
|
||||||
|
COMMAND git rev-parse --abbrev-ref HEAD
|
||||||
|
OUTPUT_VARIABLE GIT_BRANCH)
|
||||||
|
|
||||||
|
string(STRIP "${GIT_REV}" GIT_REV)
|
||||||
|
string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
|
||||||
|
string(STRIP "${GIT_DIFF}" GIT_DIFF)
|
||||||
|
string(STRIP "${GIT_TAG}" GIT_TAG)
|
||||||
|
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(VERSION "const char* GIT_REV=\"${GIT_REV}${GIT_DIFF}\";
|
||||||
|
const char* GIT_TAG=\"${GIT_TAG}\";
|
||||||
|
const char* GIT_BRANCH=\"${GIT_BRANCH}\";")
|
||||||
|
|
||||||
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
|
||||||
|
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
|
||||||
|
else()
|
||||||
|
set(VERSION_ "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT "${VERSION}" STREQUAL "${VERSION_}")
|
||||||
|
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}")
|
||||||
|
endif()
|
Loading…
Reference in New Issue
Block a user