1 ###########################################################################
2 # Copyright 2015, 2016, 2017 IoT.bzh
4 # author: Fulup Ar Foll <fulup@iot.bzh>
5 # contrib: Romain Forlot <romain.forlot@iot.bzh>
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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 ###########################################################################
21 #--------------------------------------------------------------------------
23 # Do not change this cmake template
24 # Customise your preferences in "./etc/config.cmake"
25 #--------------------------------------------------------------------------
27 # Get colorized message output non Windows OS. You know bash ? :)
30 set(ColourReset "${Esc}[m")
31 set(ColourBold "${Esc}[1m")
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")
48 # Native packaging name
49 set(NPKG_PROJECT_NAME agl-${PROJECT_NAME})
52 # Used to package .deb
53 if(EXISTS "/etc/os-release")
54 execute_process(COMMAND grep -E "^ID(=|_LIKE=)" /etc/os-release
55 OUTPUT_VARIABLE TMP_OSRELEASE
57 if (NOT TMP_OSRELEASE STREQUAL "")
58 string(REGEX REPLACE ".*=" "" OSRELEASE ${TMP_OSRELEASE})
60 set(OSRELEASE "NOT DEBIAN OS")
62 message(STATUS "OSRELEASE = ${OSRELEASE}")
64 set(OSRELEASE "NOT DEBIAN OS")
67 if(DEFINED ENV{SDKTARGETSYSROOT})
68 file(STRINGS $ENV{SDKTARGETSYSROOT}/usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE")
69 elseif(DEFINED ENV{PKG_CONFIG_SYSROOT_DIR})
70 file(STRINGS $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE")
72 file(STRINGS /usr/include/linux/version.h LINUX_VERSION_CODE_LINE REGEX "LINUX_VERSION_CODE")
75 string(REGEX MATCH "[0-9]+" LINUX_VERSION_CODE ${LINUX_VERSION_CODE_LINE})
76 math(EXPR a "${LINUX_VERSION_CODE} >> 16")
77 math(EXPR b "(${LINUX_VERSION_CODE} >> 8) & 255")
78 math(EXPR c "(${LINUX_VERSION_CODE} & 255)")
80 set(KERNEL_VERSION "${a}.${b}.${c}")
82 # Include project configuration
83 # ------------------------------
84 project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES ${PROJECT_LANGUAGES})
85 set(PROJECT_LIBDIR "${CMAKE_SOURCE_DIR}/libs" CACHE PATH "Subpath to libraries")
86 set(PROJECT_RESOURCES "${CMAKE_SOURCE_DIR}/data" CACHE PATH "Subpath to data")
88 set(AFB_TOKEN "" CACHE PATH "Default AFB_TOKEN")
89 set(AFB_REMPORT "1234" CACHE PATH "Default AFB_TOKEN")
91 # Check GCC minimal version
92 if (gcc_minimal_version)
93 message (STATUS "${Cyan}-- Check gcc_minimal_version (found gcc version ${CMAKE_C_COMPILER_VERSION}) \
94 (found g++ version ${CMAKE_CXX_COMPILER_VERSION})${ColourReset}")
95 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version} OR CMAKE_C_COMPILER_VERSION VERSION_LESS ${gcc_minimal_version})
96 message(FATAL_ERROR "${Red}**** FATAL: Require at least gcc-${gcc_minimal_version} please set CMAKE_C[XX]_COMPILER")
98 endif(gcc_minimal_version)
100 # Check Kernel mandatory version, will fail the configuration if required version not matched.
101 if (kernel_mandatory_version)
102 message (STATUS "${Cyan}-- Check kernel_mandatory_version (found kernel version ${KERNEL_VERSION})${ColourReset}")
103 if (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version})
104 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.")
105 endif (KERNEL_VERSION VERSION_LESS ${kernel_mandatory_version})
106 endif(kernel_mandatory_version)
108 # Check Kernel minimal version just print a Warning about missing features
109 # and set a definition to be used as preprocessor condition in code to disable
110 # incompatibles features.
111 if (kernel_minimal_version)
112 message (STATUS "${Cyan}-- Check kernel_minimal_version (found kernel version ${KERNEL_VERSION})${ColourReset}")
113 if (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
114 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}")
115 else (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
116 add_definitions(-DKERNEL_MINIMAL_VERSION_OK)
117 endif (KERNEL_VERSION VERSION_LESS ${kernel_minimal_version})
118 endif(kernel_minimal_version)
120 # Project path variables
121 # ----------------------
122 set(PKGOUT_DIR package CACHE PATH "Output directory for packages")
124 # Define a default package directory
126 set(PROJECT_PKG_BUILD_DIR ${PKG_PREFIX}/${PKGOUT_DIR} CACHE PATH "Application contents to be packaged")
128 set(PROJECT_PKG_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/${PKGOUT_DIR} CACHE PATH "Application contents to be packaged")
131 # Paths to templates files
132 set(TEMPLATE_DIR "${PKG_TEMPLATE_PREFIX}/template.d" CACHE PATH "Subpath to a directory where are stored needed files to launch on remote target to debuging purposes")
134 if(NOT WIDGET_CONFIG_TEMPLATE)
135 set(WIDGET_CONFIG_TEMPLATE ${TEMPLATE_DIR}/config.xml.in CACHE PATH "Path to widget config file template (config.xml.in)")
138 string(REGEX REPLACE "^(.*)/.*$" "\\1" ENTRY_POINT "${PKG_TEMPLATE_PREFIX}")
139 set(PROJECT_PKG_ENTRY_POINT ${ENTRY_POINT}/packaging CACHE PATH "Where package build files, like rpm.spec file or config.xml, are write.")
141 # Path to autobuild template
142 set(PROJECT_TEMPLATE_AGL_AUTOBUILD_DIR ${CMAKE_SOURCE_DIR}/conf.d/autobuild/agl CACHE PATH "Subpath to a directory where are stored autobuild script")
143 set(PROJECT_TEMPLATE_LINUX_AUTOBUILD_DIR ${CMAKE_SOURCE_DIR}/conf.d/autobuild/linux CACHE PATH "Subpath to a directory where are stored autobuild script")
145 # Archive target variables
146 set(ARCHIVE_OUTPUT_ARCHIVE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}_${PROJECT_VERSION}.orig.tar)
147 set(ARCHIVE_OUTPUT ${ARCHIVE_OUTPUT_ARCHIVE}.gz)
148 set(TMP_ARCHIVE_SUBMODULE ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}-sub)
149 set(CMD_ARCHIVE_SUBMODULE \'git archive --verbose --prefix=${NPKG_PROJECT_NAME}-${PROJECT_VERSION}/$$path/ --format tar HEAD --output ${TMP_ARCHIVE_SUBMODULE}-$$sha1.tar\' )
151 if(OSRELEASE MATCHES "debian" AND NOT DEFINED ENV{SDKTARGETSYSROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
152 # build deb spec file from template
153 set(PACKAGING_DEB_OUTPUT_DSC ${PROJECT_PKG_ENTRY_POINT}/${NPKG_PROJECT_NAME}.dsc)
154 set(PACKAGING_DEB_OUTPUT_INSTALL ${PROJECT_PKG_ENTRY_POINT}/debian.${NPKG_PROJECT_NAME}.install)
155 set(PACKAGING_DEB_OUTPUT_CHANGELOG ${PROJECT_PKG_ENTRY_POINT}/debian.changelog)
156 set(PACKAGING_DEB_OUTPUT_COMPAT ${PROJECT_PKG_ENTRY_POINT}/debian.compat)
157 set(PACKAGING_DEB_OUTPUT_CONTROL ${PROJECT_PKG_ENTRY_POINT}/debian.control)
158 set(PACKAGING_DEB_OUTPUT_RULES ${PROJECT_PKG_ENTRY_POINT}/debian.rules)
161 # Break After Binding are loaded but before they get initialised
162 set(GDB_INITIAL_BREAK "personality" CACHE STRING "Initial Break Point for GDB remote")
164 # Define some checker binaries to verify input DATA files
165 # to be included in package. Schema aren't checked for now.
166 # Dummy checker about JSON.
167 set(LUA_CHECKER "luac" CACHE STRING "LUA compiler")
168 set(XML_CHECKER "xmllint" CACHE STRING "XML linter")
169 set(JSON_CHECKER "echo" CACHE STRING "JSON linter")