6effb00e6723f41afa514a36314a14d1b1b6e482
[AGL/documentation.git] / docs / ATTIC / 3_Developer_Guides / 4_X(cross)_Development_System:_User's_Guide / 2_Create_your_first_AGL_application / 3.4.2.5_Build_using_an_IDE.md
1 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/devguides/master/xds-docs-guides-devguides-book.yml -->
2
3 # Build using an IDE
4
5 One option for building your application using XDS is to use
6 an Integrated Development Environment
7 ([IDE](https://en.wikipedia.org/wiki/Integrated_development_environment)).
8 Many IDEs exist (e.g. [NetBeans](https://netbeans.org/),
9 [Visual Studio Code](https://code.visualstudio.com/),
10 [Qt Creator](https://www.qt.io/),
11 [Eclipse](https://www.eclipse.org/), and so forth).
12
13 This section first develops an XDS configuration file
14 (i.e. `xds-project.conf`) and then provides two
15 examples, NetBeans and Visual Studio, that do the following.
16
17 - NetBeans: Creates two separate build configurations
18   for a project, which makes it easy to switch back and forth
19   between types of builds.
20
21 - Visual Studio: Creates tasks that allow you to build an example
22   based on CMake templates.
23
24 ## XDS Configuration File
25
26 This section shows how to create an XDS configuration file
27 (i.e. `xds-project.conf`) or how to re-use an existing file.
28 For example, the following commands set up the configuration
29 file for an `aarch64` SDK to cross-build the
30 application for a Renesas Gen3 board.
31
32 ```bash
33 # create file at root directory of your project
34 # for example:
35 # MY_PROJECT_DIR=/home/seb/xds-workspace/helloworld-native-application
36 cat > $MY_PROJECT_DIR/xds-project.conf << EOF
37  export XDS_AGENT_URL=localhost:8800
38  export XDS_PROJECT_ID=4021617e-ced0-11e7-acd2-3c970e49ad9b
39  export XDS_SDK_ID=c226821b-b5c0-386d-94fe-19f807946d03
40 EOF
41 ```
42
43 ## NetBeans
44
45 This section creates two configurations: one to compile the
46 project natively using native GNU gcc, and one to cross-compile
47 the project using XDS.
48
49 Having two configurations allows you to easily switch between them
50 using NetBean's **Run -> Set Project Configuration** menu.
51
52 ### Native Configuration
53
54 Follow these steps to create the native configuration:
55
56 1. Open the **Tools** -> **Options** menu.
57
58 2. Open the **C/C++** tab.
59
60 3. Click on the **Add** button in the **Build Tools** sub-tab:
61
62    ![Add new tool panel](./pictures/nb_newtool.png){:: style="width:90%; max-width:700px; margin:auto; display:flex"}
63
64 4. Fill the **Make Command** and **Debugger Command** fields to point to the XDS tools:
65
66    ![Add new tool panel](./pictures/nb_xds_options.png){:: style="width:90%; max-width:700px; margin:auto; display:flex"}
67
68 5. Click **OK**.
69
70 6. Select the **File** -> **New Project** menu item to declare the
71    project and create a native configuration.
72
73 7. Select **C/C++ Project with Existing Sources** and click on **Next**.
74
75 8. Specify your project directory and set **Select Configuration Mode** to
76    "Custom".
77    Be sure to keep **Tool Collection** set to "Default GNU" in order to create a
78    *native configuration*, which is based on the native GNU GCC.
79
80 9. Click **Next**.
81
82    ![Select Model panel](./pictures/nb_new-project-1.png){:: style="width:90%; max-width:700px; margin:auto; display:flex"}
83
84 10. Update the **Run in Folder** field to add the `build_native` suffix.
85     Doing so results in the build files being located in the
86     `build_native` sub-directory.
87     Be sure to keep the defaults for all other settings and then click **Next**.
88
89     ![Select Model panel](./pictures/nb_new-project-2.png){:: style="width:90%; max-width:700px; margin:auto; display:flex"}
90
91 11. Click through **Next** several times while always keeping the
92     default settings until the **Finish** button appears.
93
94 12. Click **Finish** to complete the creation of the native configuration.
95
96 ### Cross-Compilation Configuration
97
98 Follow these steps to create the configuration for cross-compilation
99 based on the XDS tools:
100
101 1. Edit project properties (using menu **File** -> **Project Properties**)
102    to add a new configuration that will use XDS to cross-compile
103    your application for example for a Renesas Gen3 board.
104
105 2. in the **Build** category, click on **Manage Configurations** button
106    and then **New** button to add a new configuration named for example
107    "Gen3 board".
108
109    ![Select Build category](./pictures/nb_new-project-3.png){:: style="width:90%; max-width:700px; margin:auto; display:flex"}
110
111 3. Click the **Set Active** button.
112
113 4. Select the **Pre-Build** sub-category, and set the following:
114
115    - Working Directory: `build_gen3`
116    - Command Line: `xds-cli exec -c ../xds-project.conf -- cmake -DRSYNC_TARGET=root@renesas-gen3 -DRSYNC_PREFIX=/opt ..`
117    - Pre-build First: `ticked`<br/><br/>
118
119 5. Select the **Make** sub-category, and set the following:
120
121    - Working Directory: `build_gen3`
122    - Build Command: `xds-cli exec -c ../xds-project.conf -- make remote-target-populate`
123    - Clean Command: `xds-cli exec -c ../xds-project.conf -- make clean`<br/><br/>
124
125    ![Select Make sub-category](./pictures/nb_new-project-4.png){:: style="width:90%; max-width:700px; margin:auto; display:flex"}
126
127 6. Select the **Run** sub-category, and set the following:
128
129    - Run Command: `target/start-on-root@renesas-gen3.sh`
130    - Run Directory: `build-gen3`<br/><br/>
131
132    ![Select Run  sub-category](./pictures/nb_new-project-5.png){:: style="width:90%; max-width:700px; margin:auto; display:flex"}
133
134 7. Click **OK** to save settings.
135
136 By changing the configuration from **Default** to **Gen3 board**, you can
137 compile your helloworld application natively, which is the default configuration.
138 Or, you can cross-compile your application using XDS for the Renesas Gen3 board,
139 which is the Gen3 board configuration.
140
141 ## Visual Studio Code
142
143 This section presents a Visual Studio example that creates tasks
144 that allow you to build an example that is based on CMake templates.
145
146 Follow these steps:
147
148 1. Start Visual Studio Code and open your project using the
149    following commands:
150
151    ```bash
152    cd $MY_PROJECT_DIR
153    code . &
154    ```
155
156 2. Add new tasks by entering the `Ctrl+Shift+P` key combination and selecting
157    the `Tasks: Configure Task` command.
158    A list of task runner templates appears.
159
160 3. Define your own tasks.
161    Following is an example that builds the
162    [helloworld-native-application](https://github.com/iotbzh/helloworld-native-application)
163    that is based on CMake templates.
164
165    ```json
166    {
167        "version": "2.0.0",
168        "type": "shell",
169        "presentation": {
170            "reveal": "always"
171        },
172        "tasks": [
173            {
174                "label": "clean",
175                "type": "shell",
176                "command": "/bin/rm -rf ${workspaceFolder}/build/* && mkdir -p build && echo Cleanup done.",
177                "problemMatcher": []
178            },
179            {
180                "label": "pre-build",
181                "type": "shell",
182                "group": "build",
183                "command": "/opt/AGL/bin/xds-cli exec --rpath build --config xds-project.conf -- cmake -DRSYNC_TARGET=root@renesas-gen3 -DRSYNC_PREFIX=/opt ../",
184                "problemMatcher": [
185                    "$gcc"
186                ]
187            },
188            {
189                "label": "build",
190                "type": "shell",
191                "group": "build",
192                "command": "/opt/AGL/bin/xds-cli exec --rpath build --config xds-project.conf -- make widget",
193                "problemMatcher": [
194                    "$gcc"
195                ]
196            },
197            {
198                "label": "populate",
199                "type": "shell",
200                "command": "/opt/AGL/bin/xds-cli exec --rpath build --config xds-project.conf -- make widget-target-install",
201                "problemMatcher": []
202            }
203        ]
204    }
205    ```
206
207 4. Run a task by entering the `Ctrl+Shift+P` key combination and
208    selecting `Tasks: Run task` and then selecting the specific task.
209    For example, select `pre-build` to trigger pre-build task.
210
211 5. Optionally add keybindings that trigger tasks.
212    Following is an example:
213
214    ```json
215    // Build
216    {
217      "key": "alt+f9",
218      "command": "workbench.action.tasks.runTask",
219      "args": "clean"
220    },
221    {
222      "key": "alt+f10",
223      "command": "workbench.action.tasks.runTask",
224      "args": "pre-build"
225    },
226    {
227      "key": "alt+f11",
228      "command": "workbench.action.tasks.runTask",
229      "args": "build"
230    },
231    {
232      "key": "alt+f12",
233      "command": "workbench.action.tasks.runTask",
234      "args": "populate"
235    },
236    ```
237
238    <!-- section-note -->
239    **NOTES:**
240
241    - You can find more details about Visual Source Code keybindings
242      [here](https://code.visualstudio.com/docs/editor/tasks#_binding-keyboard-shortcuts-to-tasks).
243
244    - You can find more details about Visual Source Code tasks
245      [here](https://code.visualstudio.com/docs/editor/tasks).
246    <!-- end-section-note -->