make git build info work with submodules
This commit is contained in:
parent
e06f9b86ec
commit
7dffb0da73
3 changed files with 27 additions and 12 deletions
|
@ -76,23 +76,31 @@ option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
|
||||||
# Build info header
|
# Build info header
|
||||||
#
|
#
|
||||||
|
|
||||||
# Write header template to binary dir to keep source directory clean
|
|
||||||
file(WRITE "${CMAKE_BINARY_DIR}/BUILD_INFO.h.in" "\
|
|
||||||
#ifndef BUILD_INFO_H\n\
|
|
||||||
#define BUILD_INFO_H\n\
|
|
||||||
\n\
|
|
||||||
#define BUILD_NUMBER @BUILD_NUMBER@\n\
|
|
||||||
#define BUILD_COMMIT \"@BUILD_COMMIT@\"\n\
|
|
||||||
\n\
|
|
||||||
#endif // BUILD_INFO_H\n\
|
|
||||||
")
|
|
||||||
|
|
||||||
# Generate initial build-info.h
|
# Generate initial build-info.h
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake)
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
|
set(GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
|
|
||||||
|
# Is git submodule
|
||||||
|
if(NOT IS_DIRECTORY "${GIT_DIR}")
|
||||||
|
file(READ ${GIT_DIR} REAL_GIT_DIR_LINK)
|
||||||
|
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" REAL_GIT_DIR ${REAL_GIT_DIR_LINK})
|
||||||
|
set(GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${REAL_GIT_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Add a custom target for build-info.h
|
# Add a custom target for build-info.h
|
||||||
add_custom_target(BUILD_INFO ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h")
|
add_custom_target(BUILD_INFO ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h")
|
||||||
|
|
||||||
|
# Add a custom command to rebuild build-info.h when .git/index changes
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h"
|
||||||
|
COMMENT "Generating build details from Git"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
DEPENDS "${GIT_DIR}/index"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
message(WARNING "Git repository not found; to enable automatic generation of build info, make sure Git is installed and the project is a Git repository.")
|
message(WARNING "Git repository not found; to enable automatic generation of build info, make sure Git is installed and the project is a Git repository.")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
set(TEMPLATE_FILE "${CMAKE_BINARY_DIR}/BUILD_INFO.h.in")
|
set(TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.h.in")
|
||||||
set(HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h")
|
set(HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/build-info.h")
|
||||||
set(BUILD_NUMBER 0)
|
set(BUILD_NUMBER 0)
|
||||||
set(BUILD_COMMIT "unknown")
|
set(BUILD_COMMIT "unknown")
|
||||||
|
|
7
scripts/build-info.h.in
Normal file
7
scripts/build-info.h.in
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef BUILD_INFO_H
|
||||||
|
#define BUILD_INFO_H
|
||||||
|
|
||||||
|
#define BUILD_NUMBER @BUILD_NUMBER@
|
||||||
|
#define BUILD_COMMIT "@BUILD_COMMIT@"
|
||||||
|
|
||||||
|
#endif // BUILD_INFO_H
|
Loading…
Add table
Add a link
Reference in a new issue