Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ option(USE_OPENMP "Build with OpenMP support." ON)
option(BUILD_STATIC_LIB "Build static library" OFF)
option(BUILD_DEPRECATED_CLI "Build the deprecated command line interface" OFF)
option(FORCE_SHARED_CRT "Build with dynamic CRT on Windows (/MD)" OFF)
option(BUILD_WITH_GIT_HASH "Add a short git hash to the build info." OFF)
## Bindings
option(JVM_BINDINGS "Build JVM bindings" OFF)
option(R_LIB "Build shared library for R package" OFF)
Expand Down
17 changes: 17 additions & 0 deletions cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ function(set_default_configuration_release)
endif()
endfunction()

if(BUILD_WITH_GIT_HASH)
execute_process(COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${xgboost_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE XGBOOST_GIT_HASH
ERROR_VARIABLE XGBOOST_GIT_ERROR
RESULT_VARIABLE GIT_COMMAND_RESULT)

if(NOT GIT_COMMAND_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to retrieve the git hash:\n${XGBOOST_GIT_ERROR}")
endif()
message(STATUS "Git hash: ${XGBOOST_GIT_HASH}")
endif()

# Generate CMAKE_CUDA_ARCHITECTURES form a list of architectures
# Also generates PTX for the most recent architecture for forwards compatibility
function(compute_cmake_cuda_archs archs)
Expand Down Expand Up @@ -240,6 +254,9 @@ macro(xgboost_target_defs target)
if(USE_NVCOMP)
target_compile_definitions(objxgboost PUBLIC -DXGBOOST_USE_NVCOMP=1)
endif()
if(BUILD_WITH_GIT_HASH)
target_compile_definitions(objxgboost PUBLIC -DXGBOOST_GIT_HASH="${XGBOOST_GIT_HASH}")
endif()
endmacro()

# handles dependencies
Expand Down
5 changes: 5 additions & 0 deletions src/c_api/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ XGB_DLL int XGBuildInfo(char const **out) {
info["USE_FEDERATED"] = Boolean{false};
#endif

#if defined(XGBOOST_GIT_HASH)
char const *git_hash = XGBOOST_GIT_HASH;
info["GIT_HASH"] = String{git_hash};
#endif

XGBBuildInfoDevice(&info);

auto &out_str = GlobalConfigAPIThreadLocalStore::Get()->ret_str;
Expand Down
Loading