Fix (some) warnings about implicit uint/int conversions
[trojita.git] / cmake / TrojitaVersion.cmake
blob6074f675a4e10b00442bd262d3726d74194e32af
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})
9 endif()
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})
23         set(${VERNUM4} "0")
24     elseif(VERNUM MATCHES "^_*([0-9]+)_+([0-9]+)")
25         set(${VERNUM1} ${CMAKE_MATCH_1})
26         set(${VERNUM2} ${CMAKE_MATCH_2})
27         set(${VERNUM3} "0")
28         set(${VERNUM4} "0")
29     elseif(VERNUM MATCHES "^_*([0-9]+)")
30         set(${VERNUM1} ${CMAKE_MATCH_1})
31         set(${VERNUM2} "0")
32         set(${VERNUM3} "0")
33         set(${VERNUM4} "0")
34     else()
35         set(${VERNUM1} "0")
36         set(${VERNUM2} "0")
37         set(${VERNUM3} "0")
38         set(${VERNUM4} "0")
39     endif()
40 endmacro()
42 set_win_rc_vernum(${TROJITA_VERSION} TROJITA_VERNUM1 TROJITA_VERNUM2 TROJITA_VERNUM3 TROJITA_VERNUM4)
43 set(TROJITA_VERSION_H
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"
59     )
60 else()
61     set(TROJITA_GIT_VERSION_H "")
62 endif()
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)
72 if(NSIS)
73     if(TROJITA_GIT_VERSION)
74         string(REPLACE "GIT_" "" TROJITA_VERSION_NSI ${TROJITA_GIT_VERSION_H})
75     else()
76         set(TROJITA_VERSION_NSI ${TROJITA_VERSION_H})
77     endif()
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)
82 endif()