diff options
author | Chris Robinson <[email protected]> | 2016-12-21 11:41:45 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-12-21 11:41:45 -0800 |
commit | 1b104dd77baeb6d991ec2ff279c87e6e46527d44 (patch) | |
tree | e9e6464bdc6053bb046a81fb5b359753667f1023 | |
parent | e270a9784bdacecedb98312a4e2e9ef75ef7df62 (diff) |
More robustly generate the git commit ID and branch
-rw-r--r-- | CMakeLists.txt | 29 | ||||
-rw-r--r-- | utils/alsoft-config/CMakeLists.txt | 3 | ||||
-rw-r--r-- | version.cmake | 11 |
3 files changed, 29 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e1e9a851..55c832ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1174,23 +1174,24 @@ IF(LIBTYPE STREQUAL "STATIC") SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS}) 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 - EXECUTE_PROCESS( - COMMAND git rev-parse --abbrev-ref HEAD + ADD_CUSTOM_TARGET(version + ${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}" - OUTPUT_VARIABLE GIT_BRANCH - 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 + VERBATIM ) ELSE() SET(GIT_BRANCH "UNKNOWN") SET(GIT_COMMIT_HASH "unknown") + CONFIGURE_FILE( + "${OpenAL_SOURCE_DIR}/version.h.in" + "${OpenAL_BINARY_DIR}/version.h") ENDIF() # Needed for openal.pc.in @@ -1203,9 +1204,6 @@ SET(PACKAGE_VERSION "${LIB_VERSION}") # End configuration CONFIGURE_FILE( - "${OpenAL_SOURCE_DIR}/version.h.in" - "${OpenAL_BINARY_DIR}/version.h") -CONFIGURE_FILE( "${OpenAL_SOURCE_DIR}/config.h.in" "${OpenAL_BINARY_DIR}/config.h") CONFIGURE_FILE( @@ -1296,6 +1294,9 @@ IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC") ENDIF() TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS}) +IF(TARGET version) + ADD_DEPENDENCIES(${LIBNAME} version) +ENDIF() IF(ALSOFT_INSTALL) # Add an install target here diff --git a/utils/alsoft-config/CMakeLists.txt b/utils/alsoft-config/CMakeLists.txt index 578273a5..6d7be8be 100644 --- a/utils/alsoft-config/CMakeLists.txt +++ b/utils/alsoft-config/CMakeLists.txt @@ -21,6 +21,9 @@ if(QT4_FOUND) target_link_libraries(alsoft-config ${QT_LIBRARIES}) set_property(TARGET alsoft-config APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS}) 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 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/version.cmake b/version.cmake new file mode 100644 index 00000000..af7ff0a6 --- /dev/null +++ b/version.cmake @@ -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}) |