Adds commit hash to the version.
[apps/app-templates.git] / cmake / cmake.d / 02-variables.cmake
1 ###########################################################################
2 # Copyright 2015, 2016, 2017 IoT.bzh
3 #
4 # author: Fulup Ar Foll <fulup@iot.bzh>
5 # contrib: Romain Forlot <romain.forlot@iot.bzh>
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 ###########################################################################
19
20
21 #--------------------------------------------------------------------------
22 #  WARNING:
23 #     Do not change this cmake template
24 #     Customise your preferences in "./etc/config.cmake"
25 #--------------------------------------------------------------------------
26
27 # Get colorized message output non Windows OS. You know bash ? :)
28 if(NOT WIN32)
29         string(ASCII 27 Esc)
30         set(ColourReset "${Esc}[m")
31         set(ColourBold  "${Esc}[1m")
32         set(Red         "${Esc}[31m")
33         set(Green       "${Esc}[32m")
34         set(Yellow      "${Esc}[33m")
35         set(Blue        "${Esc}[34m")
36         set(Magenta     "${Esc}[35m")
37         set(Cyan        "${Esc}[36m")
38         set(White       "${Esc}[37m")
39         set(BoldRed     "${Esc}[1;31m")
40         set(BoldGreen   "${Esc}[1;32m")
41         set(BoldYellow  "${Esc}[1;33m")
42         set(BoldBlue    "${Esc}[1;34m")
43         set(BoldMagenta "${Esc}[1;35m")
44         set(BoldCyan    "${Esc}[1;36m")
45         set(BoldWhite   "${Esc}[1;37m")
46 endif()
47
48 # Native packaging name
49 set(NPKG_PROJECT_NAME agl-${PROJECT_NAME})
50
51 string(REGEX MATCH "[0-9]+" LINUX_VERSION_CODE ${LINUX_VERSION_CODE_LINE})
52 math(EXPR a "${LINUX_VERSION_CODE} >> 16")
53 math(EXPR b "(${LINUX_VERSION_CODE} >> 8) & 255")
54 math(EXPR c "(${LINUX_VERSION_CODE} & 255)")
55
56 set(KERNEL_VERSION "${a}.${b}.${c}")
57
58 # Setup project and app-templates version variables
59 execute_process(COMMAND git describe --abbrev=0
60         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
61         OUTPUT_VARIABLE GIT_PROJECT_VERSION
62         OUTPUT_STRIP_TRAILING_WHITESPACE
63 )
64 execute_process(COMMAND git describe --abbrev=0
65         WORKING_DIRECTORY ${BARE_PKG_TEMPLATE_PREFIX}
66         OUTPUT_VARIABLE APP_TEMPLATES_VERSION
67         OUTPUT_STRIP_TRAILING_WHITESPACE
68 )
69
70 # Get the git commit hash to append to the version
71 execute_process(COMMAND git rev-parse --short HEAD
72         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
73         OUTPUT_VARIABLE COMMIT_HASH
74         OUTPUT_STRIP_TRAILING_WHITESPACE
75 )
76
77 # Detect unstaged or untracked changes
78 execute_process(COMMAND git status --short
79         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
80         OUTPUT_VARIABLE DIRTY_FLAG
81         OUTPUT_STRIP_TRAILING_WHITESPACE
82 )
83
84 # Include project configuration
85 # ------------------------------
86 if(NOT DEFINED PROJECT_VERSION)
87         set(PROJECT_VERSION ${GIT_PROJECT_VERSION})
88 endif()
89
90 # Release additionnals informations isn't supported so setting project
91 # attributes then add the dirty flag if git repo not sync'ed
92 project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES ${PROJECT_LANGUAGES})
93 if(NOT ${DIRTY_FLAG})
94         set(PROJECT_VERSION "${PROJECT_VERSION}-${COMMIT_HASH}-dirty")
95 else()
96         set(PROJECT_VERSION "${PROJECT_VERSION}-${COMMIT_HASH}")
97 endif()
98
99 set(AFB_TOKEN   ""      CACHE PATH "Default AFB_TOKEN")
100 set(AFB_REMPORT "1234" CACHE PATH "Default AFB_TOKEN")
101
102 # Check GCC minimal version
103 if (gcc_minimal_version)
104 message (STATUS "${Cyan}-- Check gcc_minimal_version (found gcc version ${CMAKE_C_COMPILER_VERSION}) \
105 (found g++ version ${CMAKE_CXX_COMPILER_VERSION})${ColourReset}")
106 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version} OR CMAKE_C_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version})
107 message(FATAL_ERROR "${Red}**** FATAL: Require at least gcc-${gcc_minimal_version} please set CMAKE_C[XX]_COMPILER")
108 endif()
109 endif(gcc_minimal_version)
110
111 # Check Kernel mandatory version, will fail the configuration if required version not matched.
112 if (kernel_mandatory_version)
113 message (STATUS "${Cyan}-- Check kernel_mandatory_version (found kernel version ${KERNEL_VERSION})${ColourReset}")
114 if (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version})
115 message(FATAL_ERROR "${Red}**** FATAL: Require at least ${kernel_mandatory_version} please use a recent kernel or source your SDK environment then clean and reconfigure your CMake project.")
116 endif (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version})
117 endif(kernel_mandatory_version)
118
119 # Check Kernel minimal version just print a Warning about missing features
120 # and set a definition to be used as preprocessor condition in code to disable
121 # incompatibles features.
122 if (kernel_minimal_version)
123 message (STATUS "${Cyan}-- Check kernel_minimal_version (found kernel version ${KERNEL_VERSION})${ColourReset}")
124 if (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
125 message(WARNING "${Yellow}**** Warning: Some feature(s) require at least ${kernel_minimal_version}. Please use a recent kernel or source your SDK environment then clean and reconfigure your CMake project.${ColourReset}")
126 else (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
127 add_definitions(-DKERNEL_MINIMAL_VERSION_OK)
128 endif (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
129 endif(kernel_minimal_version)
130
131 # Project path variables
132 # ----------------------
133 set(PKGOUT_DIR package CACHE PATH "Output directory for packages")
134
135 # Define a default package directory
136 if(PKG_PREFIX)
137         set(PROJECT_PKG_BUILD_DIR ${PKG_PREFIX}/${PKGOUT_DIR} CACHE PATH "Application contents to be packaged")
138 else()
139         set(PROJECT_PKG_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/${PKGOUT_DIR} CACHE PATH "Application contents to be packaged")
140 endif()
141
142 # Paths to templates files
143 set(TEMPLATE_DIR "${BARE_PKG_TEMPLATE_PREFIX}/template.d" CACHE PATH "Subpath to a directory where are stored needed files to launch on remote target to debuging purposes")
144
145 string(REGEX REPLACE "^(.*)/.*$" "\\1" ENTRY_POINT "${BARE_PKG_TEMPLATE_PREFIX}")
146 set(PROJECT_PKG_ENTRY_POINT ${ENTRY_POINT}/packaging CACHE PATH "Where package build files, like rpm.spec file or config.xml, are write.")
147
148 set(WIDGET_ICON "${ENTRY_POINT}/wgt/${PROJECT_ICON}" CACHE PATH "Path to the widget icon")
149 if(NOT WIDGET_CONFIG_TEMPLATE)
150         set(WIDGET_CONFIG_TEMPLATE ${TEMPLATE_DIR}/config.xml.in CACHE PATH "Path to widget config file template (config.xml.in)")
151 endif()
152
153 # Path to autobuild template
154 set(PROJECT_TEMPLATE_AGL_AUTOBUILD_DIR ${CMAKE_SOURCE_DIR}/conf.d/autobuild/agl CACHE PATH "Subpath to a directory where are stored autobuild script")
155 set(PROJECT_TEMPLATE_LINUX_AUTOBUILD_DIR ${CMAKE_SOURCE_DIR}/conf.d/autobuild/linux CACHE PATH "Subpath to a directory where are stored autobuild script")
156
157 # Archive target variables
158 set(ARCHIVE_OUTPUT_ARCHIVE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}_${PROJECT_VERSION}.orig.tar)
159 set(ARCHIVE_OUTPUT ${ARCHIVE_OUTPUT_ARCHIVE}.gz)
160 set(TMP_ARCHIVE_SUBMODULE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}-sub)
161 set(CMD_ARCHIVE_SUBMODULE \'git archive --verbose --prefix=${NPKG_PROJECT_NAME}-${PROJECT_VERSION}/$$path/ --format tar HEAD --output ${TMP_ARCHIVE_SUBMODULE}-$$sha1.tar\' )
162
163 if(OSRELEASE MATCHES "debian" AND NOT DEFINED ENV{SDKTARGETSYSROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
164         # build deb spec file from template
165         set(PACKAGING_DEB_OUTPUT_DSC       ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.dsc)
166         set(PACKAGING_DEB_OUTPUT_INSTALL   ${PROJECT_PKG_ENTRY_POINT}/debian.${NPKG_PROJECT_NAME}.install)
167         set(PACKAGING_DEB_OUTPUT_CHANGELOG ${PROJECT_PKG_ENTRY_POINT}/debian.changelog)
168         set(PACKAGING_DEB_OUTPUT_COMPAT    ${PROJECT_PKG_ENTRY_POINT}/debian.compat)
169         set(PACKAGING_DEB_OUTPUT_CONTROL   ${PROJECT_PKG_ENTRY_POINT}/debian.control)
170         set(PACKAGING_DEB_OUTPUT_RULES     ${PROJECT_PKG_ENTRY_POINT}/debian.rules)
171 endif()
172
173 # Break After Binding are loaded but before they get initialised
174 set(GDB_INITIAL_BREAK "personality" CACHE STRING "Initial Break Point for GDB remote")
175
176 # Define some checker binaries to verify input DATA files
177 # to be included in package. Schema aren't checked for now.
178 # Dummy checker about JSON.
179 set(LUA_CHECKER "luac" "-p" CACHE STRING "LUA compiler")
180 set(XML_CHECKER "xmllint" CACHE STRING "XML linter")
181 set(JSON_CHECKER "" CACHE STRING "JSON linter")
182
183 # Default GNU directories path variables
184 set(BINDIR bin CACHE PATH "User executables")
185 set(ETCDIR etc CACHE PATH "Read only system configuration data")
186 set(LIBDIR lib CACHE PATH "System library directory")
187 set(HTTPDIR htdocs CACHE PATH "HTML5 data directory")
188 set(DATADIR var CACHE PATH "External data resources files")
189
190 # Normally CMake uses the build tree for the RPATH when building executables
191 # etc on systems that use RPATH. When the software is installed the executables
192 # etc are relinked by CMake to have the install RPATH. If this variable is set
193 # to true then the software is always built with the install path for the RPATH
194 # and does not need to be relinked when installed.
195 # Rpath could be set and controlled by target property INSTALL_RPATH
196 set(CMAKE_BUILD_WITH_INSTALL_RPATH true)