@@ -21,6 +21,29 @@ if(NOT BUILD_COMPILER)
21
21
MESSAGE ( STATUS "Compiler: " ${BUILD_COMPILER} )
22
22
endif ()
23
23
24
+ # Check for git repository information
25
+ IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /.git)
26
+ FIND_PACKAGE (Git)
27
+ IF (GIT_FOUND)
28
+ EXECUTE_PROCESS (
29
+ COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
30
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} "
31
+ OUTPUT_VARIABLE "BUILD_VERSION"
32
+ ERROR_QUIET
33
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
34
+ SET (BUILD_VERSION "${BUILD_VERSION} " )
35
+ MESSAGE ( STATUS "Git commit: ${BUILD_VERSION} " )
36
+ ENDIF (GIT_FOUND)
37
+ ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /.git)
38
+
39
+ # Force re-run CMake to set BUILD_VERSION on any git commit
40
+ set_property (
41
+ DIRECTORY
42
+ APPEND
43
+ PROPERTY CMAKE_CONFIGURE_DEPENDS
44
+ .git/index
45
+ )
46
+
24
47
# Check if has parent directory
25
48
get_directory_property (hasParent PARENT_DIRECTORY )
26
49
@@ -130,3 +153,11 @@ endif()
130
153
add_executable ( picode_example picode_example.cpp )
131
154
target_link_libraries ( picode_example PRIVATE ${PROJECT_NAME} )
132
155
set_target_properties ( picode_example PROPERTIES EXCLUDE_FROM_ALL TRUE )
156
+
157
+ # If git info available adds to picode_example executable as environment var
158
+ if (DEFINED BUILD_VERSION)
159
+ target_compile_definitions ( picode_example PRIVATE BUILD_VERSION=${BUILD_VERSION} )
160
+ endif (DEFINED BUILD_VERSION)
161
+
162
+ # Add complier identification to picode_example executable as environment var
163
+ target_compile_definitions ( picode_example PRIVATE BUILD_COMPILER=${BUILD_COMPILER} )
0 commit comments