More robustly generate the git commit ID and branch
This commit is contained in:
parent
e270a9784b
commit
1b104dd77b
@ -1174,23 +1174,24 @@ IF(LIBTYPE STREQUAL "STATIC")
|
|||||||
SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
|
SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
IF(EXISTS "${OpenAL_SOURCE_DIR}/.git")
|
FIND_PACKAGE(Git)
|
||||||
|
IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
|
||||||
# Get the current working branch and its latest abbreviated commit hash
|
# Get the current working branch and its latest abbreviated commit hash
|
||||||
EXECUTE_PROCESS(
|
ADD_CUSTOM_TARGET(version
|
||||||
COMMAND git rev-parse --abbrev-ref HEAD
|
${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
|
||||||
|
-D LIB_VERSION=${LIB_VERSION}
|
||||||
|
-D SRC=${OpenAL_SOURCE_DIR}/version.h.in
|
||||||
|
-D DST=${OpenAL_BINARY_DIR}/version.h
|
||||||
|
-P ${OpenAL_SOURCE_DIR}/version.cmake
|
||||||
WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
|
WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
|
||||||
OUTPUT_VARIABLE GIT_BRANCH
|
VERBATIM
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
EXECUTE_PROCESS(
|
|
||||||
COMMAND git log -1 --format=%h
|
|
||||||
WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
|
|
||||||
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
)
|
||||||
ELSE()
|
ELSE()
|
||||||
SET(GIT_BRANCH "UNKNOWN")
|
SET(GIT_BRANCH "UNKNOWN")
|
||||||
SET(GIT_COMMIT_HASH "unknown")
|
SET(GIT_COMMIT_HASH "unknown")
|
||||||
|
CONFIGURE_FILE(
|
||||||
|
"${OpenAL_SOURCE_DIR}/version.h.in"
|
||||||
|
"${OpenAL_BINARY_DIR}/version.h")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# Needed for openal.pc.in
|
# Needed for openal.pc.in
|
||||||
@ -1202,9 +1203,6 @@ SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
|||||||
SET(PACKAGE_VERSION "${LIB_VERSION}")
|
SET(PACKAGE_VERSION "${LIB_VERSION}")
|
||||||
|
|
||||||
# End configuration
|
# End configuration
|
||||||
CONFIGURE_FILE(
|
|
||||||
"${OpenAL_SOURCE_DIR}/version.h.in"
|
|
||||||
"${OpenAL_BINARY_DIR}/version.h")
|
|
||||||
CONFIGURE_FILE(
|
CONFIGURE_FILE(
|
||||||
"${OpenAL_SOURCE_DIR}/config.h.in"
|
"${OpenAL_SOURCE_DIR}/config.h.in"
|
||||||
"${OpenAL_BINARY_DIR}/config.h")
|
"${OpenAL_BINARY_DIR}/config.h")
|
||||||
@ -1296,6 +1294,9 @@ IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
|
|||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
|
TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
|
||||||
|
IF(TARGET version)
|
||||||
|
ADD_DEPENDENCIES(${LIBNAME} version)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
IF(ALSOFT_INSTALL)
|
IF(ALSOFT_INSTALL)
|
||||||
# Add an install target here
|
# Add an install target here
|
||||||
|
@ -21,6 +21,9 @@ if(QT4_FOUND)
|
|||||||
target_link_libraries(alsoft-config ${QT_LIBRARIES})
|
target_link_libraries(alsoft-config ${QT_LIBRARIES})
|
||||||
set_property(TARGET alsoft-config APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
|
set_property(TARGET alsoft-config APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
|
||||||
set_target_properties(alsoft-config PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OpenAL_BINARY_DIR})
|
set_target_properties(alsoft-config PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OpenAL_BINARY_DIR})
|
||||||
|
if(TARGET version)
|
||||||
|
add_dependencies(alsoft-config version)
|
||||||
|
endif()
|
||||||
|
|
||||||
install(TARGETS alsoft-config
|
install(TARGETS alsoft-config
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
11
version.cmake
Normal file
11
version.cmake
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
EXECUTE_PROCESS(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
||||||
|
OUTPUT_VARIABLE GIT_BRANCH
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
EXECUTE_PROCESS(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
|
||||||
|
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
CONFIGURE_FILE(${SRC} ${DST})
|
Loading…
x
Reference in New Issue
Block a user