Enhances OS detection with Yocto and SDK
[staging/xdg-launcher.git] / README.md
1 # AGL CMake template
2
3 Files used to build an application, or binding, project with the
4 AGL Application Framework.
5
6 To build your AGL project using these templates, you have to install
7 them within your project and adjust compilation option in `config.cmake`.
8 For technical reasons, you also have to specify **cmake** target in
9 sub CMakeLists.txt installed. Make a globbing search to find source files
10 isn't recommended now to handle project build especially in a multiuser
11 project because CMake will not be aware of new or removed source files.
12
13 You'll find usage samples here:
14
15 - [helloworld-service](https://github.com/iotbzh/helloworld-service)
16 - [low-level-can-service](https://gerrit.automotivelinux.org/gerrit/apps/low-level-can-service)
17 - [high-level-viwi-service](https://github.com/iotbzh/high-level-viwi-service)
18 - [audio-binding](https://github.com/iotbzh/audio-binding)
19 - [unicens2-binding](https://github.com/iotbzh/unicens2-binding)
20
21 ## Quickstart
22
23 ### Initialization
24
25 To use these templates files on your project just install the reference files using
26 **git submodule** then use `config.cmake` file to configure your project specificities :
27
28 ```bash
29 git submodule add https://gerrit.automotivelinux.org/gerrit/p/apps/app-templates.git conf.d/app-templates
30 mkdir conf.d/cmake
31 cp conf.d/app-templates/cmake/config.cmake.sample conf.d/cmake/config.cmake
32 ```
33
34 Edit the copied config.cmake file to fit your needs.
35
36 Now, create your top CMakeLists.txt file which include `config.cmake` file.
37
38 An example is available in **app-templates** submodule that you can copy and
39 use:
40
41 ```bash
42 cp conf.d/app-templates/cmake/CMakeLists.txt.sample CMakeLists.txt
43 ```
44
45 ### Create your CMake targets
46
47 For each target part of your project, you need to use ***PROJECT_TARGET_ADD***
48 to include this target to your project.
49
50 Using it, make available the cmake variable ***TARGET_NAME*** until the next
51 ***PROJECT_TARGET_ADD*** is invoked with a new target name.
52
53 So, typical usage defining a target is:
54
55 ```cmake
56 PROJECT_TARGET_ADD(SuperExampleName) --> Adding target to your project
57
58 add_executable/add_library(${TARGET_NAME}.... --> defining your target sources
59
60 SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES.... --> fit target properties
61 for macros usage
62
63 INSTALL(TARGETS ${TARGET_NAME}....
64 ```
65
66 ### Targets PROPERTIES
67
68 You should set properties on your targets that will be used to package your
69 apps in a widget file that could be installed on an AGL system.
70
71 Specify what is the type of your targets that you want to be included in the
72 widget package with the property **LABELS**:
73
74 Choose between:
75
76 - **BINDING**: Shared library that be loaded by the AGL Application Framework
77 - **BINDINGV2**: Shared library that be loaded by the AGL Application Framework.
78  This has to be accompagnied with a JSON file named like the *${OUTPUT_NAME}-apidef* of
79  the target that describe the API with OpenAPI syntax (e.g: *mybinding-apidef*).
80  Or you can choose the name by setting the *CACHE* cmake variable *OPENAPI_DEF*
81  (***CAUTION***: setting a CACHE variable is needed, or set a normal variable
82  with the *PARENT_SCOPE* option to make it visible for the parent scope
83  where the target is defined) JSON file will be used to generate header file
84  using `afb-genskel` tool.
85 - **HTDOCS**: Root directory of a web app. This target has to build its
86  directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
87 - **DATA**: Resources used by your application. This target has to build its
88  directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
89 - **EXECUTABLE**: Entry point of your application executed by the AGL
90  Application Framework
91
92 ```cmake
93 SET_TARGET_PROPERTIES(${TARGET_NAME}
94         PREFIX "afb-"
95         LABELS "BINDING"
96         OUTPUT_NAME "file_output_name")
97 ```
98
99 > **TIP** you should use the prefix _afb-_ with your **BINDING* targets which
100 > stand for **Application Framework Binding**.
101
102 ## More details: Typical project architecture
103
104 A typical project architecture would be :
105
106 ```tree
107 <project-root-path>
108
109 ├── conf.d/
110 │   ├── autobuild/
111 │   │   ├── agl
112 │   │   │   └── autobuild
113 │   │   ├── linux
114 │   │   │   └── autobuild
115 │   │   └── windows
116 │   │       └── autobuild
117 │   ├── app-templates/
118 │   │   ├── README.md
119 │   │   ├── autobuild/
120 │   │   │   ├── agl
121 │   │   │   │   └── autobuild.in
122 │   │   │   ├── linux
123 │   │   │   │   └── autobuild.in
124 │   │   │   └── windows
125 │   │   │       └── autobuild.in
126 │   │   ├── cmake/
127 │   │   │   ├── config.cmake.sample
128 │   │   │   ├── export.map
129 │   │   │   └── macros.cmake
130 │   │   ├── deb/
131 │   │   │   └── config.deb.in
132 │   │   ├── rpm/
133 │   │   │   └── config.spec.in
134 │   │   └── wgt/
135 │   │       ├── config.xml.in
136 │   │       ├── config.xml.in.sample
137 │   │       ├── icon-default.png
138 │   │       ├── icon-html5.png
139 │   │       ├── icon-native.png
140 │   │       ├── icon-qml.png
141 │   │       └── icon-service.png
142 │   ├── packaging/
143 │   │   ├── config.spec
144 │   │   └── config.deb
145 │   ├── cmake
146 │   │   └── config.cmake
147 │   └── wgt
148 │      └── config.xml.in
149 ├── <libs>
150 ├── <target>
151 │   └── <files>
152 ├── <target>
153 │   └── <file>
154 └── <target>
155     └── <files>
156 ```
157
158 | # | Parent | Description |
159 | - | -------| ----------- |
160 | \<root-path\> | - | Path to your project. Hold master CMakeLists.txt and general files of your projects. |
161 | conf.d | \<root-path\> | Holds needed files to build, install, debug, package an AGL app project |
162 | app-templates | conf.d | Git submodule to app-templates AGL repository which provides CMake helpers macros library, and build scripts. config.cmake is a copy of config.cmake.sample configured for the projects. SHOULD NOT BE MODIFIED MANUALLY !|
163 | autobuild | conf.d | Scripts generated from app-templates to build packages the same way for differents platforms.|
164 | cmake | conf.d | Contains at least config.cmake file modified from the sample provided in app-templates submodule. |
165 | wgt | conf.d | Contains at least config.xml.in template file modified from the sample provided in app-templates submodule for the needs of project (See config.xml.in.sample file for more details). |
166 | packaging | conf.d | Contains output files used to build packages. |
167 | \<libs\> | \<root-path\> | External dependencies libraries. This isn't to be used to include header file but build and link statically specifics libraries. | Library sources files. Can be a decompressed library archive file or project fork. |
168 | \<target\> | \<root-path\> | A target to build, typically library, executable, etc. |
169
170 ### Update app-templates submodule
171
172 You may have some news bug fixes or features available from app-templates
173 repository that you want. To update your submodule proceed like the following:
174
175 ```bash
176 git submodule update --remote
177 git commit -s conf.d/app-templates
178 ```
179
180 This will update the submodule to the HEAD of master branch repository.
181
182 You could just want to update at a specified repository tag or branch or commit
183 , here are the method to do so:
184
185 ```bash
186 cd conf.d/app-templates
187 # Choose one of the following depending what you want
188 git checkout <tag_name>
189 git checkout --detach <branch_name>
190 git checkout --detach <commit_id>
191 # Then commit
192 cd ../..
193 git commit -s conf.d/app-templates
194 ```
195
196 ### Build a widget
197
198 #### config.xml.in file
199
200 To build a widget you need a _config.xml_ file describing what is your apps and
201 how Application Framework would launch it. This repo provide a simple default
202 file _config.xml.in_ that should work for simple application without
203 interactions with others bindings.
204
205 It is recommanded that you use the sample one which is more complete. You can
206 find it at the same location under the name _config.xml.in.sample_ (stunning
207 isn't it). Just copy the sample file to your _conf.d/wgt_ directory and name it
208 _config.xml.in_, then edit it to fit your needs.
209
210 > ***CAUTION*** : The default file is only meant to be use for a
211 > simple widget app, more complicated ones which needed to export
212 > their api, or ship several app in one widget need to use the provided
213 > _config.xml.in.sample_ which had all new Application Framework
214 > features explained and examples.
215
216 #### Using cmake template macros
217
218 To leverage all cmake templates features, you have to specify ***properties***
219 on your targets. Some macros will not works without specifying which is the
220 target type.
221
222 As the type is not always specified for some custom targets, like an ***HTML5***
223 application, macros make the difference using ***LABELS*** property.
224
225 Choose between:
226
227 - **BINDING**: Shared library that be loaded by the AGL Application Framework
228 - **BINDINGV2**: Shared library that be loaded by the AGL Application Framework.
229  This has to be accompagnied with a JSON file named like the *${OUTPUT_NAME}-apidef* of
230  the target that describe the API with OpenAPI syntax (e.g: *mybinding-apidef*).
231  Or you can choose the name by setting the *CACHE* cmake variable *OPENAPI_DEF*
232  (***CAUTION***: setting a CACHE variable is needed, or set a normal variable
233  with the *PARENT_SCOPE* option to make it visible for the parent scope
234  where the target is defined) JSON file will be used to generate header file
235  using `afb-genskel` tool.
236 - **HTDOCS**: Root directory of a web app. This target has to build its
237  directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
238 - **DATA**: Resources used by your application. This target has to build its
239  directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
240 - **EXECUTABLE**: Entry point of your application executed by the AGL
241  Application Framework
242
243 Example:
244
245 ```cmake
246 SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
247                 LABELS "HTDOCS"
248                 OUTPUT_NAME dist.prod
249         )
250 ```
251
252 If your target output is not named as the ***TARGET_NAME***, you need to specify
253 ***OUTPUT_NAME*** property that will be used by the ***populate_widget*** macro.
254
255 Use the ***populate_widget*** macro as latest statement of your target
256 definition. Then at the end of your project definition you should use the macro
257 ***build_widget*** that make an archive from the populated widget tree using the
258 `wgtpkg-pack` Application Framework tools.
259
260 ## Macro reference
261
262 ### PROJECT_TARGET_ADD
263
264 Typical usage would be to add the target to your project using macro
265 `PROJECT_TARGET_ADD` with the name of your target as parameter.
266
267 Example:
268
269 ```cmake
270 PROJECT_TARGET_ADD(low-can-demo)
271 ```
272
273 > ***NOTE***: This will make available the variable `${TARGET_NAME}`
274 > set with the specificied name. This variable will change at the next call
275 > to this macros.
276
277 ### project_subdirs_add
278
279 This macro will search in all subfolder any `CMakeLists.txt` file. If found then
280 it will be added to your project. This could be use in an hybrid application by
281 example where the binding lay in a sub directory.
282
283 Usage :
284
285 ```cmake
286 project_subdirs_add()
287 ```
288
289 You also can specify a globbing pattern as argument to filter which folders
290 will be looked for.
291
292 To filter all directories that begin with a number followed by a dash the
293 anything:
294
295 ```cmake
296 project_subdirs_add("[0-9]-*")
297 ```
298
299 ## Advanced customization
300
301 ### Including additionnals cmake files
302
303 Advanced tuning is possible using addionnals cmake files that are included
304 automatically from some specifics locations. They are included in that order:
305
306 - Project CMake files normaly located in _<project-root-path>/conf.d/app-templates/cmake/cmake.d_
307 - Home CMake files located in _$HOME/.config/app-templates/cmake.d_
308 - System CMake files located in _/etc/app-templates/cmake.d_
309
310 CMake files has to be named using the following convention: `XX-common-*.cmake`
311 or `XX-${PROJECT_NAME}-*.cmake`, where `XX` are numbers, `*` file name
312 (ie. `99-common-my_customs.cmake`).
313
314 > **NOTE** You need to specify after numbers that indicate include order, to
315 which project that file applies, if it applies to all project then use keyword
316 `common`.
317
318 So, saying that you should be aware that every normal cmake variables used at
319 project level could be overwrited by home or system located cmake files if
320 variables got the same name. Exceptions are cached variables set using
321 **CACHE** keyword:
322
323 Example:
324
325 ```cmake
326 set(VARIABLE_NAME 'value string random' CACHE STRING 'docstring')
327 ```
328
329 ### Include customs templated scripts
330
331 As well as for additionnals cmake files you can include your own templated
332 scripts that will be passed to cmake command `configure_file`.
333
334 Just create your own script to the following directories:
335
336 - Home location in _$HOME/.config/app-templates/scripts_
337 - System location in _/etc/app-templates/scripts_
338
339 Scripts only needs to use the extension `.in` to be parsed and configured by
340 CMake command.
341
342 ## Autobuild script usage
343
344 ### Generation
345
346 To be integrated in the Yocto build workflow you have to generate `autobuild`
347 scripts using _autobuild_ target.
348
349 To generate those scripts proceeds:
350
351 ```bash
352 mkdir -p build
353 cd build
354 cmake .. && make autobuild
355 ```
356
357 You should see _conf.d/autobuild/agl/autobuild_ file now.
358
359 ### Available targets
360
361 Here are the available targets available from _autobuild_ scripts:
362
363 - **clean** : clean build directory from object file and targets results.
364 - **distclean** : delete build directory
365 - **configure** : generate project Makefile from CMakeLists.txt files.
366 - **build** : compile all project targets.
367 - **package** : build and output a wgt package.
368
369 You can specify variables that modify the behavior of compilation using
370 the following variables:
371
372 - **CONFIGURE_ARGS** : Variable used at **configure** time.
373 - **BUILD_ARGS** : Variable used at **build** time.
374 - **DEST** : Directory where to output ***wgt*** file.
375
376 Variable as to be in CMake format. (ie: BUILD_ARGS="-DC_FLAGS='-g -O2'")
377
378 Usage example:
379
380 ```bash
381 ./conf.d/autobuild/wgt/autobuild package DEST=/tmp
382 ```