blob: 38fdf283b28f81c1739e4612a55d64432f921100 [file] [log] [blame]
Tomáš Pecka5123e002020-06-05 15:29:21 +02001if(GIT_EXECUTABLE AND EXISTS ${PROJECT_SOURCE_DIR}/.git)
2 execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty --long --always --tags
3 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
4 OUTPUT_VARIABLE ${VERSION_VARIABLE})
5 string(REPLACE "\n" "" "${VERSION_VARIABLE}" ${${VERSION_VARIABLE}})
6endif()
7
8if(${VERSION_VARIABLE})
9 set(${VERSION_VARIABLE}_H
10 "#define ${VERSION_VARIABLE} \"${${VERSION_VARIABLE}}\"\n"
11 )
12 message(STATUS "Building ${PROJECT_NAME} Git version ${${VERSION_VARIABLE}}")
13else()
14 set(${VERSION_VARIABLE}_H
15 "#define ${VERSION_VARIABLE} \"${FALLBACK_VERSION}\"\n"
16 )
17 message(STATUS "Building ${PROJECT_NAME} version: ${${VERSION_VARIABLE}}")
18endif()
19
20file(WRITE ${PROJECT_BINARY_DIR}/${VERSION_VARIABLE}.h.in ${${VERSION_VARIABLE}_H})
21execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
22 ${PROJECT_BINARY_DIR}/${VERSION_VARIABLE}.h.in ${PROJECT_BINARY_DIR}/${VERSION_VARIABLE}.h)