0fc55a3e3c2b8839008de27bc2c1ac139eda23ab
[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 # Detect unstaged or untracked changes
71 execute_process(COMMAND git status --short
72         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
73         OUTPUT_VARIABLE DIRTY_FLAG
74         OUTPUT_STRIP_TRAILING_WHITESPACE
75 )
76
77 # Include project configuration
78 # ------------------------------
79 if(NOT DEFINED PROJECT_VERSION)
80         set(PROJECT_VERSION ${GIT_PROJECT_VERSION})
81 endif()
82
83 # Release additionnals informations isn't supported so setting project
84 # attributes then add the dirty flag if git repo not sync'ed
85 project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES ${PROJECT_LANGUAGES})
86 if(NOT ${DIRTY_FLAG})
87 set(PROJECT_VERSION "${PROJECT_VERSION}-dirty")
88 endif()
89
90 set(AFB_TOKEN   ""      CACHE PATH "Default AFB_TOKEN")
91 set(AFB_REMPORT "1234" CACHE PATH "Default AFB_TOKEN")
92
93 # Check GCC minimal version
94 if (gcc_minimal_version)
95 message (STATUS "${Cyan}-- Check gcc_minimal_version (found gcc version ${CMAKE_C_COMPILER_VERSION}) \
96 (found g++ version ${CMAKE_CXX_COMPILER_VERSION})${ColourReset}")
97 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version} OR CMAKE_C_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version})
98 message(FATAL_ERROR "${Red}**** FATAL: Require at least gcc-${gcc_minimal_version} please set CMAKE_C[XX]_COMPILER")
99 endif()
100 endif(gcc_minimal_version)
101
102 # Check Kernel mandatory version, will fail the configuration if required version not matched.
103 if (kernel_mandatory_version)
104 message (STATUS "${Cyan}-- Check kernel_mandatory_version (found kernel version ${KERNEL_VERSION})${ColourReset}")
105 if (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version})
106 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.")
107 endif (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version})
108 endif(kernel_mandatory_version)
109
110 # Check Kernel minimal version just print a Warning about missing features
111 # and set a definition to be used as preprocessor condition in code to disable
112 # incompatibles features.
113 if (kernel_minimal_version)
114 message (STATUS "${Cyan}-- Check kernel_minimal_version (found kernel version ${KERNEL_VERSION})${ColourReset}")
115 if (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
116 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}")
117 else (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
118 add_definitions(-DKERNEL_MINIMAL_VERSION_OK)
119 endif (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
120 endif(kernel_minimal_version)
121
122 # Project path variables
123 # ----------------------
124 set(PKGOUT_DIR package CACHE PATH "Output directory for packages")
125
126 # Define a default package directory
127 if(PKG_PREFIX)
128         set(PROJECT_PKG_BUILD_DIR ${PKG_PREFIX}/${PKGOUT_DIR} CACHE PATH "Application contents to be packaged")
129 else()
130         set(PROJECT_PKG_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/${PKGOUT_DIR} CACHE PATH "Application contents to be packaged")
131 endif()
132
133 # Paths to templates files
134 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")
135
136 string(REGEX REPLACE "^(.*)/.*$" "\\1" ENTRY_POINT "${BARE_PKG_TEMPLATE_PREFIX}")
137 set(PROJECT_PKG_ENTRY_POINT ${ENTRY_POINT}/packaging CACHE PATH "Where package build files, like rpm.spec file or config.xml, are write.")
138
139 set(WIDGET_ICON "${ENTRY_POINT}/wgt/${PROJECT_ICON}" CACHE PATH "Path to the widget icon")
140 if(NOT WIDGET_CONFIG_TEMPLATE)
141         set(WIDGET_CONFIG_TEMPLATE ${TEMPLATE_DIR}/config.xml.in CACHE PATH "Path to widget config file template (config.xml.in)")
142 endif()
143
144 # Path to autobuild template
145 set(PROJECT_TEMPLATE_AGL_AUTOBUILD_DIR ${CMAKE_SOURCE_DIR}/conf.d/autobuild/agl CACHE PATH "Subpath to a directory where are stored autobuild script")
146 set(PROJECT_TEMPLATE_LINUX_AUTOBUILD_DIR ${CMAKE_SOURCE_DIR}/conf.d/autobuild/linux CACHE PATH "Subpath to a directory where are stored autobuild script")
147
148 # Archive target variables
149 set(ARCHIVE_OUTPUT_ARCHIVE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}_${PROJECT_VERSION}.orig.tar)
150 set(ARCHIVE_OUTPUT ${ARCHIVE_OUTPUT_ARCHIVE}.gz)
151 set(TMP_ARCHIVE_SUBMODULE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}-sub)
152 set(CMD_ARCHIVE_SUBMODULE \'git archive --verbose --prefix=${NPKG_PROJECT_NAME}-${PROJECT_VERSION}/$$path/ --format tar HEAD --output ${TMP_ARCHIVE_SUBMODULE}-$$sha1.tar\' )
153
154 if(OSRELEASE MATCHES "debian" AND NOT DEFINED ENV{SDKTARGETSYSROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
155         # build deb spec file from template
156         set(PACKAGING_DEB_OUTPUT_DSC       ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.dsc)
157         set(PACKAGING_DEB_OUTPUT_INSTALL   ${PROJECT_PKG_ENTRY_POINT}/debian.${NPKG_PROJECT_NAME}.install)
158         set(PACKAGING_DEB_OUTPUT_CHANGELOG ${PROJECT_PKG_ENTRY_POINT}/debian.changelog)
159         set(PACKAGING_DEB_OUTPUT_COMPAT    ${PROJECT_PKG_ENTRY_POINT}/debian.compat)
160         set(PACKAGING_DEB_OUTPUT_CONTROL   ${PROJECT_PKG_ENTRY_POINT}/debian.control)
161         set(PACKAGING_DEB_OUTPUT_RULES     ${PROJECT_PKG_ENTRY_POINT}/debian.rules)
162 endif()
163
164 # Break After Binding are loaded but before they get initialised
165 set(GDB_INITIAL_BREAK "personality" CACHE STRING "Initial Break Point for GDB remote")
166
167 # Define some checker binaries to verify input DATA files
168 # to be included in package. Schema aren't checked for now.
169 # Dummy checker about JSON.
170 set(LUA_CHECKER "luac" "-p" CACHE STRING "LUA compiler")
171 set(XML_CHECKER "xmllint" CACHE STRING "XML linter")
172 set(JSON_CHECKER "" CACHE STRING "JSON linter")
173
174 # Default GNU directories path variables
175 set(BINDIR bin CACHE PATH "User executables")
176 set(ETCDIR etc CACHE PATH "Read only system configuration data")
177 set(LIBDIR lib CACHE PATH "System library directory")
178 set(HTTPDIR htdocs CACHE PATH "HTML5 data directory")
179 set(DATADIR data CACHE PATH "External data resources files")
180
181 # Normally CMake uses the build tree for the RPATH when building executables
182 # etc on systems that use RPATH. When the software is installed the executables
183 # etc are relinked by CMake to have the install RPATH. If this variable is set
184 # to true then the software is always built with the install path for the RPATH
185 # and does not need to be relinked when installed.
186 # Rpath could be set and controlled by target property INSTALL_RPATH
187 set(CMAKE_BUILD_WITH_INSTALL_RPATH true)