summaryrefslogtreecommitdiffhomepage
path: root/cmake/opentrack-version.cmake
blob: 9a496ebedceca74ac73319b95c70504e79c560d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
include(GetGitRevisionDescription)

find_package(Git QUIET)
if(GIT_FOUND)
    git_describe(OPENTRACK_COMMIT --tags --always --dirty)
    git_describe(OPENTRACK_TAG_EXACT --tag --exact)
endif()

file(WRITE ${CMAKE_BINARY_DIR}/opentrack-version.h "#define OPENTRACK_VERSION \"${OPENTRACK_COMMIT}\"")

add_library(opentrack-version STATIC ${CMAKE_BINARY_DIR}/version.cc)
opentrack_compat(opentrack-version)

set(version-string "
#define BUILD_compat
#include \"opentrack-compat/export.hpp\"

#ifdef __cplusplus
extern \"C\"
#endif
OPENTRACK_COMPAT_EXPORT
const char* opentrack_version;

const char* opentrack_version = \"${OPENTRACK_COMMIT}\";
")

set(crapola-ver)
if(EXISTS ${CMAKE_BINARY_DIR}/version.cc)
    file(READ ${CMAKE_BINARY_DIR}/version.cc crapola-ver)
endif()

if(NOT (crapola-ver STREQUAL version-string))
    file(WRITE ${CMAKE_BINARY_DIR}/version.cc "${version-string}")
endif()