blob: 4e4327fe1c29c44a142554f2deba39631e4c56cb [file] [log] [blame]
Jan Kundrátdc2b0722018-03-02 14:13:37 +01001find_package(Git REQUIRED)
2
3macro(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)
18endmacro()