Skip to content

Commit 16f83bf

Browse files
committed
add git info to nabla
1 parent a10ab3d commit 16f83bf

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

cmake/scripts/nbl/gitInfo.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# A configure-time and build-time script, that produces source with current git commit info
2+
# required variables: GIT_EXECUTABLE, WORKING_DIRECTORY, INPUT_FILE, OUTPUT_FILE
3+
4+
execute_process( COMMAND ${GIT_EXECUTABLE} log -1 --format=%H
5+
WORKING_DIRECTORY ${WORKING_DIRECTORY}
6+
OUTPUT_VARIABLE NBL_GIT_COMMIT_HASH
7+
OUTPUT_STRIP_TRAILING_WHITESPACE
8+
)
9+
10+
execute_process( COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
11+
WORKING_DIRECTORY ${WORKING_DIRECTORY}
12+
OUTPUT_VARIABLE NBL_GIT_COMMIT_SHORT_HASH
13+
OUTPUT_STRIP_TRAILING_WHITESPACE
14+
)
15+
16+
# since CMake 3.10.3: "The generated file is modified and its timestamp updated on subsequent cmake runs only if its content is changed."
17+
# we can spam this each run/build
18+
configure_file("${INPUT_FILE}" "${OUTPUT_FILE}")

include/nabla.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#ifndef __NABLA_H_INCLUDED__
1818
#define __NABLA_H_INCLUDED__
1919

20+
// meta info
21+
#include "nbl/git_info.h"
22+
2023
// core lib
2124
#include "nbl/core/declarations.h"
2225

include/nbl/git_info.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __GIT_INFO_H_INCLUDED__
2+
#define __GIT_INFO_H_INCLUDED__
3+
4+
namespace nbl {
5+
struct GitInfo {
6+
const char* CommitHash;
7+
const char* ShortCommitHash;
8+
};
9+
extern const GitInfo git;
10+
}
11+
12+
#endif // __GIT_INFO_H_INCLUDED__

src/nbl/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,18 @@ set(NBL_SCENE_SOURCES
284284
${NBL_ROOT_PATH}/src/nbl/scene/ITransformTree.cpp
285285
)
286286

287+
set(NBL_GENERATED_SOURCES
288+
${CMAKE_BINARY_DIR}/src/nbl/git_info.cpp
289+
)
290+
287291
set(NABLA_SRCS_COMMON
288292
${NBL_CORE_SOURCES}
289293
${NBL_SYSTEM_SOURCES}
290294
${NBL_UI_SOURCES}
291295
${NBL_ASSET_SOURCES}
292296
${NBL_VIDEO_SOURCES}
293297
${NBL_SCENE_SOURCES}
298+
${NBL_GENERATED_SOURCES}
294299
)
295300

296301
if(MSVC)
@@ -653,6 +658,20 @@ glue_source_definitions(Nabla _NBL_SOURCE_DEFINITIONS_)
653658
set(_NBL_DEFINE_FILE_WRAPPER_ ${CMAKE_CURRENT_BINARY_DIR}/include/define.h)
654659
write_source_definitions("${_NBL_DEFINE_FILE_WRAPPER_}" "${_NBL_SOURCE_DEFINITIONS_}")
655660

661+
add_custom_target(CheckGit COMMAND ${CMAKE_COMMAND}
662+
-DWORKING_DIRECTORY:PATH=${NBL_ROOT_PATH}
663+
-DGIT_EXECUTABLE:PATH=${GIT_EXECUTABLE}
664+
-DINPUT_FILE:PATH="${NBL_ROOT_PATH}/src/nbl/git_info.cpp.in"
665+
-DOUTPUT_FILE:PATH="${CMAKE_BINARY_DIR}/src/nbl/git_info.cpp"
666+
-P ${NBL_ROOT_PATH}/cmake/scripts/nbl/gitInfo.cmake
667+
BYPRODUCTS ${CMAKE_BINARY_DIR}/src/nbl/git_info.cpp
668+
)
669+
670+
set(INPUT_FILE "${NBL_ROOT_PATH}/src/nbl/git_info.cpp.in")
671+
set(OUTPUT_FILE "${CMAKE_BINARY_DIR}/src/nbl/git_info.cpp")
672+
set(WORKING_DIRECTORY ${NBL_ROOT_PATH})
673+
include("${NBL_ROOT_PATH}/cmake/scripts/nbl/gitInfo.cmake")
674+
656675
#on MSVC it won't compile without this option!
657676
if (MSVC)
658677
target_compile_options(Nabla PUBLIC /bigobj)

src/nbl/git_info.cpp.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "nbl/git_info.h"
2+
3+
namespace nbl
4+
{
5+
const GitInfo git = {
6+
.CommitHash = "@NBL_GIT_COMMIT_HASH@",
7+
.ShortCommitHash = "@NBL_GIT_COMMIT_SHORT_HASH@"
8+
};
9+
}

0 commit comments

Comments
 (0)