Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 1 | find_package(Git REQUIRED) |
| 2 | |
| 3 | macro(prepare_git_version VERSION_VARIABLE FALLBACK_VERSION) |
| 4 | set(${VERSION_VARIABLE}-version_files ${PROJECT_BINARY_DIR}/${VERSION_VARIABLE}.h) |
| 5 | add_custom_target(target-${VERSION_VARIABLE} DEPENDS build_version_fake_file-${VERSION_VARIABLE}) |
| 6 | add_custom_command(OUTPUT build_version_fake_file-${VERSION_VARIABLE} ${${VERSION_VARIABLE}-version_files} |
| 7 | COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} |
| 8 | -DVERSION_VARIABLE=${VERSION_VARIABLE} |
| 9 | -DFALLBACK_VERSION=${FALLBACK_VERSION} |
| 10 | -DPROJECT_NAME=${PROJECT_NAME} |
| 11 | -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} |
| 12 | -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} |
| 13 | -P ${PROJECT_SOURCE_DIR}/cmake/ProjectGitVersionRunner.cmake) |
| 14 | set_source_files_properties(${PROJECT_BINARY_DIR}/${${VERSION_VARIABLE}.h} |
| 15 | PROPERTIES |
| 16 | GENERATED TRUE |
| 17 | HEADER_FILE_ONLY TRUE) |
| 18 | endmacro() |