# AGL CMake template Files used to build an application, or binding, project with the AGL Application Framework. To build your AGL project using these templates, you have to install them within your project and adjust compilation option in `config.cmake`. For technical reasons, you also have to specify **cmake** target in sub CMakeLists.txt installed. Make a globbing search to find source files isn't recommended now to handle project build especially in a multiuser project because CMake will not be aware of new or removed source files. You'll find usage samples here: - [helloworld-service](https://github.com/iotbzh/helloworld-service) - [low-level-can-service](https://gerrit.automotivelinux.org/gerrit/apps/low-level-can-service) - [high-level-viwi-service](https://github.com/iotbzh/high-level-viwi-service) - [audio-binding](https://github.com/iotbzh/audio-binding) - [unicens2-binding](https://github.com/iotbzh/unicens2-binding) ## Quickstart ### Initialization To use these templates files on your project just install the reference files using **git submodule** then use `config.cmake` file to configure your project specificities : ```bash git submodule add https://gerrit.automotivelinux.org/gerrit/p/apps/app-templates.git conf.d/app-templates mkdir conf.d/cmake cp conf.d/app-templates/samples.d/config.cmake.sample conf.d/cmake/config.cmake ``` Edit the copied config.cmake file to fit your needs. Now, create your top CMakeLists.txt file which include `config.cmake` file. An example is available in **app-templates** submodule that you can copy and use: ```bash cp conf.d/app-templates/samples.d/CMakeLists.txt.sample CMakeLists.txt ``` ### Create your CMake targets For each target part of your project, you need to use ***PROJECT_TARGET_ADD*** to include this target to your project. Using it, make available the cmake variable ***TARGET_NAME*** until the next ***PROJECT_TARGET_ADD*** is invoked with a new target name. So, typical usage defining a target is: ```cmake PROJECT_TARGET_ADD(SuperExampleName) --> Adding target to your project add_executable/add_library(${TARGET_NAME}.... --> defining your target sources SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES.... --> fit target properties for macros usage ``` ### Targets PROPERTIES You should set properties on your targets that will be used to package your apps in a widget file that could be installed on an AGL system. Specify what is the type of your targets that you want to be included in the widget package with the property **LABELS**: Choose between: - **BINDING**: Shared library that be loaded by the AGL Application Framework - **BINDINGV2**: Shared library that be loaded by the AGL Application Framework This has to be accompagnied with a JSON file named like the *${OUTPUT_NAME}-apidef* of the target that describe the API with OpenAPI syntax (e.g: *mybinding-apidef*). Or you can choose the name, without the extension, by setting the *CACHE* cmake variable *OPENAPI_DEF* (***CAUTION***: setting a CACHE variable is needed, or set a normal variable with the *PARENT_SCOPE* option to make it visible for the parent scope where the target is defined) JSON file will be used to generate header file using `afb-genskel` tool. - **PLUGIN**: Shared library meant to be used as a binding plugin. Binding would load it as a plugin to extend its functionnalities. It should be named with a special extension that you choose with SUFFIX cmake target property or it'd be **.ctlso** by default. - **HTDOCS**: Root directory of a web app. This target has to build its directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - **DATA**: Resources used by your application. This target has to build its directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - **EXECUTABLE**: Entry point of your application executed by the AGL Application Framework - **LIBRARY**: An external 3rd party library bundled with the binding for its own purpose because platform doesn't provide it. > **TIP** you should use the prefix _afb-_ with your **BINDING* targets which > stand for **Application Framework Binding**. ```cmake SET_TARGET_PROPERTIES(${TARGET_NAME} PREFIX "afb-" LABELS "BINDING" OUTPUT_NAME "file_output_name" ) ``` > **NOTE**: You doesn't need to specify an **INSTALL** command for these > targets. This is already handle by template and will be installed in the > following path : **${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}** ## More details: Typical project architecture A typical project architecture would be : ```tree │ ├── conf.d/ │ ├── autobuild/ │ │ ├── agl │ │ │ └── autobuild │ │ ├── linux │ │ │ └── autobuild │ │ └── windows │ │ └── autobuild │ ├── app-templates/ │ │ ├── README.md │ │ ├── cmake/ │ │ │ ├── export.map │ │ │ └── macros.cmake │ │ ├── samples.d/ │ │ │ ├── CMakeLists.txt.sample │ │ │ ├── config.cmake.sample │ │ │ ├── config.xml.in.sample │ │
###########################################################################
# Copyright 2015, 2016, 2017 IoT.bzh
#
# author: Romain Forlot <romain.forlot@iot.bzh>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake)
g.cmake, common.cmake will include lot of cmake file to customize project build depending on your plateform. It will detect your OS deducing it from file _/etc/os-release_ now as default in almost all Linux distribution. So you can use the value of field **ID_LIKE** or **ID** if the first one doesn't exists and add a cmake file for that distribution in your _conf.d/cmake/_ directory or relatively to your _app-templates_ submodule path _app-templates/../cmake/_ Those files has to be named use the following scheme _XX-${OSRELEASE}*.cmake_ where _XX_ are numbers, ${OSRELEASE} the **ID_LIKE** or **ID** field from _/etc/os-release_ file. You can also define default OS configuration file to use as fallback is none specific OS configuration is available using the scheme _XX-default*.cmake_. Then is you need by example a module that isn't named the same in one distro only, you only has to define a specific file to handle that case then for all the other case put the configuration in the default file. ### Include customs templated scripts As well as for additionnals cmake files you can include your own templated scripts that will be passed to cmake command `configure_file`. Just create your own script to the following directories: - Home location in _$HOME/.config/app-templates/scripts_ - System location in _/etc/app-templates/scripts_ Scripts only needs to use the extension `.in` to be parsed and configured by CMake command. ## Autobuild script usage ### Generation To be integrated in the Yocto build workflow you have to generate `autobuild` scripts using _autobuild_ target. To generate those scripts proceeds: ```bash mkdir -p build cd build cmake .. && make autobuild ``` You should see _conf.d/autobuild/agl/autobuild_ file now. ### Available targets Here are the available targets available from _autobuild_ scripts: - **clean** : clean build directory from object file and targets results. - **distclean** : delete build directory - **configure** : generate project Makefile from CMakeLists.txt files. - **build** : compile all project targets. - **package** : build and output a wgt package. You can specify variables that modify the behavior of compilation using the following variables: - **CONFIGURE_ARGS** : Variable used at **configure** time. - **BUILD_ARGS** : Variable used at **build** time. - **DEST** : Directory where to output ***wgt*** file. Variable as to be in CMake format. (ie: BUILD_ARGS="-DC_FLAGS='-g -O2'") Usage example: ```bash ./conf.d/autobuild/wgt/autobuild package DEST=/tmp ```