Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame^] | 1 | if(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}}) |
| 6 | endif() |
| 7 | |
| 8 | if(${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}}") |
| 13 | else() |
| 14 | set(${VERSION_VARIABLE}_H |
| 15 | "#define ${VERSION_VARIABLE} \"${FALLBACK_VERSION}\"\n" |
| 16 | ) |
| 17 | message(STATUS "Building ${PROJECT_NAME} version: ${${VERSION_VARIABLE}}") |
| 18 | endif() |
| 19 | |
| 20 | file(WRITE ${PROJECT_BINARY_DIR}/${VERSION_VARIABLE}.h.in ${${VERSION_VARIABLE}_H}) |
| 21 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 22 | ${PROJECT_BINARY_DIR}/${VERSION_VARIABLE}.h.in ${PROJECT_BINARY_DIR}/${VERSION_VARIABLE}.h) |