1 file(READ ${SOURCE_DIR}/src/trojita-version TROJITA_VERSION)
2 string(REPLACE "\n" "" TROJITA_VERSION ${TROJITA_VERSION})
4 if(GIT_EXECUTABLE AND EXISTS ${SOURCE_DIR}/.git)
5 execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty --long --always
6 WORKING_DIRECTORY ${SOURCE_DIR}
7 OUTPUT_VARIABLE TROJITA_GIT_VERSION)
8 string(REPLACE "\n" "" TROJITA_GIT_VERSION ${TROJITA_GIT_VERSION})
11 # Windows resources using four 16bit integers as version number, so prepare these numbers in VERNUMX variables from VERSION
12 macro(set_win_rc_vernum VERSION VERNUM1 VERNUM2 VERNUM3 VERNUM4)
13 string(REGEX REPLACE "[^0-9-]" "_" VERNUM ${VERSION})
14 if(VERNUM MATCHES "^_*([0-9]+)_+([0-9]+)_+([0-9]+)_+([0-9]+)")
15 set(${VERNUM1} ${CMAKE_MATCH_1})
16 set(${VERNUM2} ${CMAKE_MATCH_2})
17 set(${VERNUM3} ${CMAKE_MATCH_3})
18 set(${VERNUM4} ${CMAKE_MATCH_4})
19 elseif(VERNUM MATCHES "^_*([0-9]+)_+([0-9]+)_+([0-9]+)")
20 set(${VERNUM1} ${CMAKE_MATCH_1})
21 set(${VERNUM2} ${CMAKE_MATCH_2})
22 set(${VERNUM3} ${CMAKE_MATCH_3})
24 elseif(VERNUM MATCHES "^_*([0-9]+)_+([0-9]+)")
25 set(${VERNUM1} ${CMAKE_MATCH_1})
26 set(${VERNUM2} ${CMAKE_MATCH_2})
29 elseif(VERNUM MATCHES "^_*([0-9]+)")
30 set(${VERNUM1} ${CMAKE_MATCH_1})
42 set_win_rc_vernum(${TROJITA_VERSION} TROJITA_VERNUM1 TROJITA_VERNUM2 TROJITA_VERNUM3 TROJITA_VERNUM4)
44 "#define TROJITA_VERSION \"${TROJITA_VERSION}\"\n"
45 "#define TROJITA_VERNUM1 ${TROJITA_VERNUM1}\n"
46 "#define TROJITA_VERNUM2 ${TROJITA_VERNUM2}\n"
47 "#define TROJITA_VERNUM3 ${TROJITA_VERNUM3}\n"
48 "#define TROJITA_VERNUM4 ${TROJITA_VERNUM4}\n"
51 if(TROJITA_GIT_VERSION)
52 set_win_rc_vernum(${TROJITA_GIT_VERSION} TROJITA_GIT_VERNUM1 TROJITA_GIT_VERNUM2 TROJITA_GIT_VERNUM3 TROJITA_GIT_VERNUM4)
53 set(TROJITA_GIT_VERSION_H
54 "#define TROJITA_GIT_VERSION \"${TROJITA_GIT_VERSION}\"\n"
55 "#define TROJITA_GIT_VERNUM1 ${TROJITA_GIT_VERNUM1}\n"
56 "#define TROJITA_GIT_VERNUM2 ${TROJITA_GIT_VERNUM2}\n"
57 "#define TROJITA_GIT_VERNUM3 ${TROJITA_GIT_VERNUM3}\n"
58 "#define TROJITA_GIT_VERNUM4 ${TROJITA_GIT_VERNUM4}\n"
61 set(TROJITA_GIT_VERSION_H "")
64 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h.in ${TROJITA_VERSION_H})
65 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
66 ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h)
68 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h.in ${TROJITA_GIT_VERSION_H})
69 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
70 ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h)
73 if(TROJITA_GIT_VERSION)
74 string(REPLACE "GIT_" "" TROJITA_VERSION_NSI ${TROJITA_GIT_VERSION_H})
76 set(TROJITA_VERSION_NSI ${TROJITA_VERSION_H})
78 string(REPLACE "#" "!" TROJITA_VERSION_NSI ${TROJITA_VERSION_NSI})
79 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.nsi.in ${TROJITA_VERSION_NSI})
80 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
81 ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.nsi.in ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.nsi)