Fix: wrong link libraries dependencies var name
[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*  of
79  the target that describe the API with OpenAPI syntax. JSON file will be used
80  to generate header file using `afb-genskel` tool.
81 - **HTDOCS**: Root directory of a web app
82 - **DATA**: Resources used by your application
83 - **EXECUTABLE**: Entry point of your application executed by the AGL
84  Application Framework
85
86 ```cmake
87 SET_TARGET_PROPERTIES(${TARGET_NAME}
88         PREFIX "afb-"
89         LABELS "BINDING"
90         OUTPUT_NAME "file_output_name")
91 ```
92
93 > **TIP** you should use the prefix _afb-_ with your **BINDING* targets which
94 > stand for **Application Framework Binding**.
95
96 ## More details: Typical project architecture
97
98 A typical project architecture would be :
99
100 ```tree
101 <project-root-path>
102
103 ├── conf.d/
104 │   ├── autobuild/
105 │   │   ├── agl
106 │   │   │   └── autobuild
107 │   │   ├── linux
108 │   │   │   └── autobuild
109 │   │   └── windows
110 │   │       └── autobuild
111 │   ├── app-templates/
112 │   │   ├── README.md
113 │   │   ├── autobuild/
114 │   │   │   ├── agl
115 │   │   │   │   └── autobuild.in
116 │   │   │   ├── linux
117 │   │   │   │   └── autobuild.in
118 │   │   │   └── windows
119 │   │   │       └── autobuild.in
120 │   │   ├── cmake/
121 │   │   │   ├── config.cmake.sample
122 │   │   │   ├── export.map
123 │   │   │   └── macros.cmake
124 │   │   ├── deb/
125 │   │   │   └── config.deb.in
126 │   │   ├── rpm/
127 │   │   │   └── config.spec.in
128 │   │   └── wgt/
129 │   │       ├── config.xml.in
130 │   │       ├── config.xml.in.sample
131 │   │       ├── icon-default.png
132 │   │       ├── icon-html5.png
133 │   │       ├── icon-native.png
134 │   │       ├── icon-qml.png
135 │   │       └── icon-service.png
136 │   ├── packaging/
137 │   │   ├── config.spec
138 │   │   └── config.deb
139 │   ├── cmake
140 │   │   └── config.cmake
141 │   └── wgt
142 │      └── config.xml.in
143 ├── <libs>
144 ├── <target>
145 │   └── <files>
146 ├── <target>
147 │   └── <file>
148 └── <target>
149     └── <files>
150 ```
151
152 | # | Parent | Description |
153 | - | -------| ----------- |
154 | \<root-path\> | - | Path to your project. Hold master CMakeLists.txt and general files of your projects. |
155 | conf.d | \<root-path\> | Holds needed files to build, install, debug, package an AGL app project |
156 | 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 !|
157 | autobuild | conf.d | Scripts generated from app-templates to build packages the same way for differents platforms.|
158 | cmake | conf.d | Contains at least config.cmake file modified from the sample provided in app-templates submodule. |
159 | 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). |
160 | packaging | conf.d | Contains output files used to build packages. |
161 | \<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. |
162 | \<target\> | \<root-path\> | A target to build, typically library, executable, etc. |
163
164 ### Update app-templates submodule
165
166 You may have some news bug fixes or features available from app-templates
167 repository that you want. To update your submodule proceed like the following:
168
169 ```bash
170 git submodule update --remote
171 git commit -s conf.d/app-templates
172 ```
173
174 This will update the submodule to the HEAD of master branch repository.
175
176 You could just want to update at a specified repository tag or branch or commit
177 , here are the method to do so:
178
179 ```bash
180 cd conf.d/app-templates
181 # Choose one of the following depending what you want
182 git checkout <tag_name>
183 git checkout --detach <branch_name>
184 git checkout --detach <commit_id>
185 # Then commit
186 cd ../..
187 git commit -s conf.d/app-templates
188 ```
189
190 ### Build a widget
191
192 #### config.xml.in file
193
194 To build a widget you need a _config.xml_ file describing what is your apps and
195 how Application Framework would launch it. This repo provide a simple default
196 file _config.xml.in_ that should work for simple application without
197 interactions with others bindings.
198
199 It is recommanded that you use the sample one which is more complete. You can
200 find it at the same location under the name _config.xml.in.sample_ (stunning
201 isn't it). Just copy the sample file to your _conf.d/wgt_ directory and name it
202 _config.xml.in_, then edit it to fit your needs.
203
204 > ***CAUTION*** : The default file is only meant to be use for a
205 > simple widget app, more complicated ones which needed to export
206 > their api, or ship several app in one widget need to use the provided
207 > _config.xml.in.sample_ which had all new Application Framework
208 > features explained and examples.
209
210 #### Using cmake template macros
211
212 To leverage all cmake templates features, you have to specify ***properties***
213 on your targets. Some macros will not works without specifying which is the
214 target type.
215
216 As the type is not always specified for some custom targets, like an ***HTML5***
217 application, macros make the difference using ***LABELS*** property.
218
219 Choose between:
220
221 - **BINDING**: Shared library that be loaded by the AGL Application Framework
222 - **HTDOCS**: Root directory of a web app
223 - **DATA**: Resources used by your application
224 - **EXECUTABLE**: Entry point of your application executed by the AGL
225  Application Framework
226
227 Example:
228
229 ```cmake
230 SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
231                 LABELS "HTDOCS"
232                 OUTPUT_NAME dist.prod
233         )
234 ```
235
236 If your target output is not named as the ***TARGET_NAME***, you need to specify
237 ***OUTPUT_NAME*** property that will be used by the ***populate_widget*** macro.
238
239 Use the ***populate_widget*** macro as latest statement of your target
240 definition. Then at the end of your project definition you should use the macro
241 ***build_widget*** that make an archive from the populated widget tree using the
242 `wgtpkg-pack` Application Framework tools.
243
244 ## Macro reference
245
246 ### PROJECT_TARGET_ADD
247
248 Typical usage would be to add the target to your project using macro
249 `PROJECT_TARGET_ADD` with the name of your target as parameter.
250
251 Example:
252
253 ```cmake
254 PROJECT_TARGET_ADD(low-can-demo)
255 ```
256
257 > ***NOTE***: This will make available the variable `${TARGET_NAME}`
258 > set with the specificied name. This variable will change at the next call
259 > to this macros.
260
261 ### project_subdirs_add
262
263 This macro will search in all subfolder any `CMakeLists.txt` file. If found then
264 it will be added to your project. This could be use in an hybrid application by
265 example where the binding lay in a sub directory.
266
267 Usage :
268
269 ```cmake
270 project_subdirs_add()
271 ```
272
273 You also can specify a globbing pattern as argument to filter which folders
274 will be looked for.
275
276 To filter all directories that begin with a number followed by a dash the
277 anything:
278
279 ```cmake
280 project_subdirs_add("[0-9]-*")
281 ```
282
283 ## Advanced customization
284
285 ### Including additionnals cmake files
286
287 Advanced tuning is possible using addionnals cmake files that are included
288 automatically from some specifics locations. They are included in that order:
289
290 - Project CMake files normaly located in _<project-root-path>/conf.d/app-templates/cmake/cmake.d_
291 - Home CMake files located in _$HOME/.config/app-templates/cmake.d_
292 - System CMake files located in _/etc/app-templates/cmake.d_
293
294 CMake files has to be named using the following convention: `XX-***.cmake`,
295 where `XX` are numbers, `***` file name (ie. `99-my_customs.cmake`).
296
297 So, saying that you should be aware that every normal cmake variables used at
298 project level could be overwrited by home or system located cmake files if
299 variables got the same name. Exceptions are cached variables set using
300 **CACHE** keyword:
301
302 Example:
303
304 ```cmake
305 set(VARIABLE_NAME 'value string random' CACHE STRING 'docstring')
306 ```
307
308 ### Include customs templated scripts
309
310 As well as for additionnals cmake files you can include your own templated
311 scripts that will be passed to cmake command `configure_file`.
312
313 Just create your own script to the following directories:
314
315 - Home location in _$HOME/.config/app-templates/scripts_
316 - System location in _/etc/app-templates/scripts_
317
318 Scripts only needs to use the extension `.in` to be parsed and configured by
319 CMake command.
320
321 ## Autobuild script usage
322
323 ### Generation
324
325 To be integrated in the Yocto build workflow you have to generate `autobuild`
326 scripts using _autobuild_ target.
327
328 To generate those scripts proceeds:
329
330 ```bash
331 mkdir -p build
332 cd build
333 cmake .. && make autobuild
334 ```
335
336 You should see _conf.d/autobuild/agl/autobuild_ file now.
337
338 ### Available targets
339
340 Here are the available targets available from _autobuild_ scripts:
341
342 - **clean** : clean build directory from object file and targets results.
343 - **distclean** : delete build directory
344 - **configure** : generate project Makefile from CMakeLists.txt files.
345 - **build** : compile all project targets.
346 - **package** : build and output a wgt package.
347
348 You can specify variables that modify the behavior of compilation using
349 the following variables:
350
351 - **CONFIGURE_ARGS** : Variable used at **configure** time.
352 - **BUILD_ARGS** : Variable used at **build** time.
353 - **DEST** : Directory where to output ***wgt*** file.
354
355 Variable as to be in CMake format. (ie: BUILD_ARGS="-DC_FLAGS='-g -O2'")
356
357 Usage example:
358
359 ```bash
360 ./conf.d/autobuild/wgt/autobuild package DEST=/tmp
361 ```