1# cmakefile executed within a makefile target
2
3# If we find ReleaseInfo.cmake we use the info from there and don't need Git to be installed
4find_file(REL_INFO_FILE ReleaseInfo.cmake PATHS "${PROJECT_SOURCE_DIR}" NO_DEFAULT_PATH)
5if(REL_INFO_FILE STREQUAL REL_INFO_FILE-NOTFOUND)
6    # we look for the git command in this paths by order of preference
7    if(WIN32)
8        find_program(GIT_CMD git.exe HINTS ENV Path PATH_SUFFIXES ../)
9    elseif(APPLE)
10        find_program(GIT_CMD git PATHS "/opt/local/bin" "/usr/local/bin" "/usr/bin")
11        find_program(GIT_CMD git)
12        set(SHELL "/bin/bash")
13    else(WIN32) # Linux
14        find_program(GIT_CMD git)
15        set(SHELL "/bin/bash")
16    endif(WIN32)
17
18    # Fail if Git is not installed
19    if(GIT_CMD STREQUAL GIT_CMD-NOTFOUND)
20        message(FATAL_ERROR "git command not found!")
21    else()
22        message(STATUS "git command found: ${GIT_CMD}")
23    endif()
24
25    # Get version description.
26    # Depending on whether you checked out a branch (dev) or a tag (release),
27    # "git describe" will return "5.0-gtk2-2-g12345678" or "5.0-gtk2", respectively.
28    execute_process(COMMAND ${GIT_CMD} describe --tags --always OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
29
30    # Get branch name.
31    # Will return empty if you checked out a commit or tag. Empty string handled later.
32    execute_process(COMMAND ${GIT_CMD} symbolic-ref --short -q HEAD OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
33
34    # Get commit hash.
35    execute_process(COMMAND ${GIT_CMD} rev-parse --short --verify HEAD OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
36
37    # Get commit date, YYYY-MM-DD.
38    execute_process(COMMAND ${GIT_CMD} show -s --format=%cd --date=format:%Y-%m-%d OUTPUT_VARIABLE GIT_COMMIT_DATE OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
39
40    # Get number of commits since tagging. This is what "GIT_DESCRIBE" uses.
41    # Works when checking out branch, tag or commit.
42    # Get a list of all tags in repo:
43    execute_process(COMMAND ${GIT_CMD} tag --merged HEAD OUTPUT_VARIABLE GIT_TAG WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
44    # Replace newlines with semicolons so that it can be split:
45    string(REPLACE "\n" ";" GIT_TAG_LIST "${GIT_TAG}")
46    execute_process(COMMAND ${GIT_CMD} rev-list --count HEAD --not ${GIT_TAG_LIST} OUTPUT_VARIABLE GIT_COMMITS_SINCE_TAG OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
47
48    # Get number of commits since branching.
49    # Works when checking out branch, tag or commit.
50    execute_process(COMMAND ${GIT_CMD} rev-list --count HEAD --not --tags OUTPUT_VARIABLE GIT_COMMITS_SINCE_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
51
52    # If user checked-out something which is not a branch, use the description as branch name.
53    if(GIT_BRANCH STREQUAL "")
54        set(GIT_BRANCH "${GIT_DESCRIBE}")
55    endif()
56
57    # Create numeric version.
58    # This version is nonsense, either don't use it at all or use it only where you have no other choice, e.g. Inno Setup's VersionInfoVersion.
59    # Strip everything after hyphen, e.g. "5.0-gtk2" -> "5.0", "5.1-rc1" -> "5.1" (ergo BS).
60    if(GIT_COMMITS_SINCE_TAG STREQUAL "")
61        set(GIT_NUMERIC_VERSION_BS "0.0.0")
62    else()
63        string(REGEX REPLACE "-.*" "" GIT_NUMERIC_VERSION_BS ${GIT_DESCRIBE})
64        set(GIT_NUMERIC_VERSION_BS "${GIT_NUMERIC_VERSION_BS}.${GIT_COMMITS_SINCE_TAG}")
65    endif()
66
67    message(STATUS "Git checkout information:")
68    message(STATUS "	Commit description:	${GIT_DESCRIBE}")
69    message(STATUS "	Branch:			${GIT_BRANCH}")
70    message(STATUS "	Commit:			${GIT_COMMIT}")
71    message(STATUS "	Commit date:		${GIT_COMMIT_DATE}")
72    message(STATUS "	Commits since tag:	${GIT_COMMITS_SINCE_TAG}")
73    message(STATUS "	Commits since branch:	${GIT_COMMITS_SINCE_BRANCH}")
74    message(STATUS "	Version (unreliable):	${GIT_NUMERIC_VERSION_BS}")
75
76    if(NOT DEFINED CACHE_NAME_SUFFIX)
77        set(CACHE_NAME_SUFFIX "${GIT_DESCRIBE}")
78        message(STATUS "CACHE_NAME_SUFFIX was not defined, it is now \"${CACHE_NAME_SUFFIX}\"")
79    else()
80        message(STATUS "CACHE_NAME_SUFFIX is \"${CACHE_NAME_SUFFIX}\"")
81    endif()
82
83else(REL_INFO_FILE STREQUAL REL_INFO_FILE-NOTFOUND)
84    include("${PROJECT_SOURCE_DIR}/ReleaseInfo.cmake")
85endif(REL_INFO_FILE STREQUAL REL_INFO_FILE-NOTFOUND)
86
87if(WIN32)
88    if(BIT_DEPTH EQUAL 4)
89        set(BUILD_BIT_DEPTH 32)
90        # 32 bits builds has to be installable on 64 bits system, to support WinXP/64.
91        set(ARCHITECTURE_ALLOWED "x86 x64 ia64")
92        # installing in 32 bits mode even on 64 bits OS and architecture
93        set(INSTALL_MODE "")
94    elseif(BIT_DEPTH EQUAL 8)
95        set(BUILD_BIT_DEPTH 64)
96        # Restricting the 64 bits builds to 64 bits systems only
97        set(ARCHITECTURE_ALLOWED "x64 ia64")
98        # installing in 64 bits mode for all 64 bits processors, even for itanium architecture
99        set(INSTALL_MODE "x64 ia64")
100    endif(BIT_DEPTH EQUAL 4)
101    # set part of the output archive name
102    set(SYSTEM_NAME "WinVista")
103
104    configure_file("${PROJECT_SOURCE_DIR}/tools/win/InnoSetup/WindowsInnoSetup.iss.in" "${CMAKE_BINARY_DIR}/rtdata/WindowsInnoSetup.iss")
105endif(WIN32)
106
107# build version.h from template
108configure_file("${PROJECT_SOURCE_DIR}/rtgui/version.h.in" "${CMAKE_BINARY_DIR}/rtgui/version.h")
109# build AboutThisBuild.txt from template
110configure_file("${PROJECT_SOURCE_DIR}/AboutThisBuild.txt.in" "${CMAKE_BINARY_DIR}/AboutThisBuild.txt")
111