87310b3f5f0d476fb862116814e4144ca419ce03
[staging/xdg-launcher.git] / docs / dev_guide / 3_advanced_usage.md
1 # Build a widget
2
3 ## config.xml.in file
4
5 To build a widget you need a _config.xml_ file describing what is your apps and
6 how Application Framework would launch it. This repo provide a simple default
7 file _config.xml.in_ that should work for simple application without
8 interactions with others bindings.
9
10 It is recommanded that you use the sample one which is more complete. You can
11 find it at the same location under the name _config.xml.in.sample_ (stunning
12 isn't it). Just copy the sample file to your _conf.d/wgt_ directory and name it
13 _config.xml.in_, then edit it to fit your needs.
14
15 > ***CAUTION*** : The default file is only meant to be use for a
16 > simple widget app, more complicated ones which needed to export
17 > their api, or ship several app in one widget need to use the provided
18 > _config.xml.in.sample_ which had all new Application Framework
19 > features explained and examples.
20
21 ## Using cmake template macros
22
23 To leverage all cmake templates features, you have to specify ***properties***
24 on your targets. Some macros will not works without specifying which is the
25 target type.
26
27 As the type is not always specified for some custom targets, like an ***HTML5***
28 application, macros make the difference using ***LABELS*** property.
29
30 Choose between:
31
32 - **BINDING**: Shared library that be loaded by the AGL Application Framework
33 - **BINDINGV2**: Shared library that be loaded by the AGL Application Framework.
34  This has to be accompagnied with a JSON file named like the *OUTPUT_NAME*  of
35  the target that describe the API with OpenAPI syntax. JSON file will be used
36  to generate header file using `afb-genskel` tool.
37 - **HTDOCS**: Root directory of a web app
38 - **DATA**: Resources used by your application
39 - **EXECUTABLE**: Entry point of your application executed by the AGL
40  Application Framework
41
42 Example:
43
44 ```cmake
45 SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
46                 LABELS "HTDOCS"
47                 OUTPUT_NAME dist.prod
48         )
49 ```
50
51 If your target output is not named as the ***TARGET_NAME***, you need to specify
52 ***OUTPUT_NAME*** property that will be used by the ***populate_widget*** macro.
53
54 Use the ***populate_widget*** macro as latest statement of your target
55 definition. Then at the end of your project definition you should use the macro
56 ***build_widget*** that make an archive from the populated widget tree using the
57 `wgtpkg-pack` Application Framework tools.
58
59 ## Macro reference
60
61 ### PROJECT_TARGET_ADD
62
63 Typical usage would be to add the target to your project using macro
64 `PROJECT_TARGET_ADD` with the name of your target as parameter.
65
66 Example:
67
68 ```cmake
69 PROJECT_TARGET_ADD(low-can-demo)
70 ```
71
72 > ***NOTE***: This will make available the variable `${TARGET_NAME}`
73 > set with the specificied name. This variable will change at the next call
74 > to this macros.
75
76 ### project_subdirs_add
77
78 This macro will search in all subfolder any `CMakeLists.txt` file. If found then
79 it will be added to your project. This could be use in an hybrid application by
80 example where the binding lay in a sub directory.
81
82 Usage :
83
84 ```cmake
85 project_subdirs_add()
86 ```
87
88 You also can specify a globbing pattern as argument to filter which folders
89 will be looked for.
90
91 To filter all directories that begin with a number followed by a dash the
92 anything:
93
94 ```cmake
95 project_subdirs_add("[0-9]-*")
96 ```