6db1ef2d0c038257d2baf18b01d45906dd56cf08
[apps/agl-service-data-persistence.git] / ll-database-binding / conf.d / app-templates / docs / dev_guide / 1_Quickstart.md
1 # Quickstart
2
3 ## Initialization
4
5 To use these templates files on your project just install the reference files using
6 **git submodule** then use `config.cmake` file to configure your project specificities :
7
8 ```bash
9 git submodule add https://gerrit.automotivelinux.org/gerrit/apps/app-templatesconf.d/app-templates conf.d/app-templates
10 mkdir conf.d/cmake
11 cp conf.d/app-templates/cmake/config.cmake.sample conf.d/cmake/config.cmake
12 ```
13
14 Edit the copied config.cmake file to fit your needs.
15
16 Now, create your top CMakeLists.txt file which include `config.cmake` file.
17
18 An example is available in **app-templates** submodule that you can copy and
19 use:
20
21 ```bash
22 cp conf.d/app-templates/cmake/CMakeLists.txt CMakeLists.txt
23 ```
24
25 ## Create your CMake targets
26
27 For each target part of your project, you need to use ***PROJECT_TARGET_ADD***
28 to include this target to your project.
29
30 Using it, make available the cmake variable ***TARGET_NAME*** until the next
31 ***PROJECT_TARGET_ADD*** is invoked with a new target name.
32
33 So, typical usage defining a target is:
34
35 ```cmake
36 PROJECT_TARGET_ADD(SuperExampleName) --> Adding target to your project
37
38 add_executable/add_library(${TARGET_NAME}.... --> defining your target sources
39
40 SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES.... --> fit target properties
41 for macros usage
42
43 INSTALL(TARGETS ${TARGET_NAME}....
44 ```
45
46 ## Targets PROPERTIES
47
48 You should set properties on your targets that will be used to package your
49 apps in a widget file that could be installed on an AGL system.
50
51 Specify what is the type of your targets that you want to be included in the
52 widget package with the property **LABELS**:
53
54 Choose between:
55
56 - **BINDING**: Shared library that be loaded by the AGL Application Framework
57 - **BINDINGV2**: Shared library that be loaded by the AGL Application Framework.
58  This has to be accompagnied with a JSON file named like the *${OUTPUT_NAME}-apidef* of
59  the target that describe the API with OpenAPI syntax (e.g: *mybinding-apidef*).
60  Or you can choose the name by setting the *CACHE* cmake variable *OPENAPI_DEF*
61  (***CAUTION***: setting a CACHE variable is needed, or set a normal variable
62  with the *PARENT_SCOPE* option to make it visible for the parent scope
63  where the target is defined) JSON file will be used to generate header file
64  using `afb-genskel` tool.
65 - **HTDOCS**: Root directory of a web app. This target has to build its
66  directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
67 - **DATA**: Resources used by your application. This target has to build its
68  directory and puts its files in the ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}
69 - **EXECUTABLE**: Entry point of your application executed by the AGL
70  Application Framework
71
72 > **TIP** you should use the prefix _afb-_ with your **BINDING* targets which
73 > stand for **Application Framework Binding**.
74
75 ```cmake
76 SET_TARGET_PROPERTIES(${TARGET_NAME}
77         PREFIX "afb-"
78         LABELS "BINDING"
79         OUTPUT_NAME "file_output_name")
80 ```
81
82 > **NOTE**: You doesn't need to specify an **INSTALL** command for these
83 > targets. This is already handle by template and will be installed in the
84 > following path : **${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}**