• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Porting a Library Built Using CMake<a name="EN-US_TOPIC_0000001200172241"></a>
2
3-   [Source Code Acquisition](#section1771132116245)
4-   [Porting Guidelines](#section9737174410328)
5-   [Cross-Compilation](#section38205577332)
6    -   [Compilation Reference](#section1088111263418)
7    -   [Cross-Compilation Settings](#section8168182883515)
8
9-   [Library Test](#section6686144293611)
10-   [Adding the Compiled double-conversion Library to the OpenHarmony Project](#section1651053153715)
11
12The following shows how to port the double-conversion library.
13
14## Source Code Acquisition<a name="section1771132116245"></a>
15
16Acquire the source code of double-conversion from  [https://github.com/google/double-conversion](https://github.com/google/double-conversion). The following table lists the directory structure.
17
18**Table  1**  Directory structure of the source code
19
20<a name="table824211132418"></a>
21<table><thead align="left"><tr id="row524220131043"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p22421213442"><a name="p22421213442"></a><a name="p22421213442"></a>Directory</p>
22</th>
23<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p132427131241"><a name="p132427131241"></a><a name="p132427131241"></a>Description</p>
24</th>
25</tr>
26</thead>
27<tbody><tr id="row1335114463010"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p3354144414307"><a name="p3354144414307"></a><a name="p3354144414307"></a>double-conversion/cmake/</p>
28</td>
29<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1235564417307"><a name="p1235564417307"></a><a name="p1235564417307"></a>Template used for building with CMake</p>
30</td>
31</tr>
32<tr id="row1024211133411"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12423137414"><a name="p12423137414"></a><a name="p12423137414"></a>double-conversion/double-conversion/</p>
33</td>
34<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p824221314420"><a name="p824221314420"></a><a name="p824221314420"></a>Directory of source files</p>
35</td>
36</tr>
37<tr id="row1242813545"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p424213131343"><a name="p424213131343"></a><a name="p424213131343"></a>double-conversion/msvc/</p>
38</td>
39<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p172429139418"><a name="p172429139418"></a><a name="p172429139418"></a>-</p>
40</td>
41</tr>
42<tr id="row20242513641"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p2024210139412"><a name="p2024210139412"></a><a name="p2024210139412"></a>double-conversion/test/</p>
43</td>
44<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p7242713241"><a name="p7242713241"></a><a name="p7242713241"></a>Source files of the test cases</p>
45</td>
46</tr>
47<tr id="row12242191314413"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p172420131646"><a name="p172420131646"></a><a name="p172420131646"></a>double-conversion/.gitignore</p>
48</td>
49<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p112426131843"><a name="p112426131843"></a><a name="p112426131843"></a>-</p>
50</td>
51</tr>
52<tr id="row1484211616360"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1384206143617"><a name="p1384206143617"></a><a name="p1384206143617"></a>double-conversion/AUTHORS</p>
53</td>
54<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p384310614366"><a name="p384310614366"></a><a name="p384310614366"></a>-</p>
55</td>
56</tr>
57<tr id="row1290331063610"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p18903410183613"><a name="p18903410183613"></a><a name="p18903410183613"></a>double-conversion/BUILD</p>
58</td>
59<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1990491033617"><a name="p1990491033617"></a><a name="p1990491033617"></a>-</p>
60</td>
61</tr>
62<tr id="row5967101420368"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p696710141361"><a name="p696710141361"></a><a name="p696710141361"></a>double-conversion/CMakeLists.txt</p>
63</td>
64<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1196714147366"><a name="p1196714147366"></a><a name="p1196714147366"></a>Top-level file used for building with CMake</p>
65</td>
66</tr>
67<tr id="row19372034133612"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1596214484473"><a name="p1596214484473"></a><a name="p1596214484473"></a>double-conversion/COPYING</p>
68</td>
69<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p163811348364"><a name="p163811348364"></a><a name="p163811348364"></a>-</p>
70</td>
71</tr>
72<tr id="row0184133717364"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1166255034715"><a name="p1166255034715"></a><a name="p1166255034715"></a>double-conversion/Changelog</p>
73</td>
74<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p151851337193617"><a name="p151851337193617"></a><a name="p151851337193617"></a>-</p>
75</td>
76</tr>
77<tr id="row173871412369"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p411055217475"><a name="p411055217475"></a><a name="p411055217475"></a>double-conversion/LICENSE</p>
78</td>
79<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p9387641173617"><a name="p9387641173617"></a><a name="p9387641173617"></a>-</p>
80</td>
81</tr>
82<tr id="row534170185015"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p035703507"><a name="p035703507"></a><a name="p035703507"></a>double-conversion/Makefile</p>
83</td>
84<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p6367075019"><a name="p6367075019"></a><a name="p6367075019"></a>-</p>
85</td>
86</tr>
87<tr id="row1367804175011"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1246133725014"><a name="p1246133725014"></a><a name="p1246133725014"></a>double-conversion/README.md</p>
88</td>
89<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p136796410508"><a name="p136796410508"></a><a name="p136796410508"></a>-</p>
90</td>
91</tr>
92<tr id="row2070619141508"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1963193815509"><a name="p1963193815509"></a><a name="p1963193815509"></a>double-conversion/SConstruct</p>
93</td>
94<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p570691485015"><a name="p570691485015"></a><a name="p570691485015"></a>-</p>
95</td>
96</tr>
97<tr id="row186521925020"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p152191040155012"><a name="p152191040155012"></a><a name="p152191040155012"></a>double-conversion/WORKSPACE</p>
98</td>
99<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p4661119175014"><a name="p4661119175014"></a><a name="p4661119175014"></a>-</p>
100</td>
101</tr>
102</tbody>
103</table>
104
105## Porting Guidelines<a name="section9737174410328"></a>
106
107Cross-compile the double-conversion library by modifying the toolchain to generate executable files for the OpenHarmony platform and then add these files to the OpenHarmony project by invoking CMake via GN.
108
109## Cross-Compilation<a name="section38205577332"></a>
110
111### Compilation Reference<a name="section1088111263418"></a>
112
113The  [README.md](https://github.com/google/double-conversion/blob/master/README.md)  file in the code repository details the procedures for compiling the double-conversion library using CMake as well as the testing methods. This document focuses on the building, compilation, and testing of the library. If you have any questions during library porting, refer to the  **README.md**  file. For porting of other third-party libraries that can be independently built with CMake, you can refer to the compilation guides provided by the libraries.
114
115### Cross-Compilation Settings<a name="section8168182883515"></a>
116
117The following steps show how to configure and modify the toolchains for cross-compiling the libraries built using CMake to compile executable files for the OpenHarmony platform.
118
1191.  Configure the toolchains.
120
121    Add configuration of the clang toolchains to the top-level file  **CMakeLists.txt**  listed in  [Table 1](#table824211132418).
122
123    ```
124    set(CMAKE_CROSSCOMPILING TRUE)
125    set(CMAKE_SYSTEM_NAME Generic)
126    set(CMAKE_CXX_COMPILER_ID Clang)
127    set(CMAKE_TOOLCHAIN_PREFIX llvm-)
128    # Specify the C compiler (ensure that the path of the toolchain has been added to the PATH environment variable) and its flags. To perform cross-compilation using clang, the --target flag must be specified.
129    set(CMAKE_C_COMPILER clang)
130    set(CMAKE_C_FLAGS "--target=arm-liteos -D__clang__ -march=armv7-a -w")
131    # Specify the C++ compiler (ensure that the path of the toolchain has been added to the PATH environment variable) and its flags. To perform cross-compilation, the --target flag must be specified.
132    set(CMAKE_CXX_COMPILER clang++)
133    set(CMAKE_CXX_FLAGS "--target=arm-liteos -D__clang__ -march=armv7-a -w")
134    # Specify the linker and its flags. --target and --sysroot must be specified. You can specify OHOS_ROOT_PATH via the suffix parameter of the cmake command.
135    set(MY_LINK_FLAGS "--target=arm-liteos --sysroot=${OHOS_SYSROOT_PATH}")
136    set(CMAKE_LINKER clang)
137    set(CMAKE_CXX_LINKER clang++)
138    set(CMAKE_C_LINKER clang)
139    set(CMAKE_C_LINK_EXECUTABLE
140        "${CMAKE_C_LINKER} ${MY_LINK_FLAGS} <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
141    set(CMAKE_CXX_LINK_EXECUTABLE
142        "${CMAKE_CXX_LINKER} ${MY_LINK_FLAGS} <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
143    # Specify the path for searching chained libraries.
144    set(CMAKE_SYSROOT ${OHOS_SYSROOT_PATH})
145    ```
146
1472.  Perform the compilation.
148
149    Run a Linux command to enter the directory \(listed in  [Table 1](#table824211132418)\) for storing double-conversion source files and then run the following commands:
150
151    ```
152    mkdir build && cd build
153    cmake .. -DBUILD_TESTING=ON -DOHOS_SYSROOT_PATH="..."
154    make -j
155    ```
156
157    **OHOS\_SYSROOT\_PATH**  specifies the absolute path where  **sysroot**  is located. For OpenHarmony, set  **OHOS\_SYSROOT\_PATH**  to the absolute path of the  **out/hispark\__xxx_/ipcamera\_hispark\__xxx_/sysroot**  directory. This directory is generated after full compilation is complete. Therefore, complete full compilation before porting.
158
1593.  <a name="li15717101715249"></a>View the result.
160
161    After step 2 is complete, a static library file and test cases are generated in the  **build**  directory.
162
163    **Table  2**  Directory structure of compiled files
164
165    <a name="table1452412391911"></a>
166    <table><thead align="left"><tr id="row15259397114"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p084365219116"><a name="p084365219116"></a><a name="p084365219116"></a>Directory</p>
167    </th>
168    <th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p118435524118"><a name="p118435524118"></a><a name="p118435524118"></a>Description</p>
169    </th>
170    </tr>
171    </thead>
172    <tbody><tr id="row17861750780"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p208014918411"><a name="p208014918411"></a><a name="p208014918411"></a>double-conversion/build/libdouble-conversion.a</p>
173    </td>
174    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p155272391619"><a name="p155272391619"></a><a name="p155272391619"></a>Static library file</p>
175    </td>
176    </tr>
177    <tr id="row141820612910"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1941811618918"><a name="p1941811618918"></a><a name="p1941811618918"></a>double-conversion/build/test/</p>
178    </td>
179    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p64181761995"><a name="p64181761995"></a><a name="p64181761995"></a>Test cases and CMake cache files</p>
180    </td>
181    </tr>
182    <tr id="row19525239815"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p452512394117"><a name="p452512394117"></a><a name="p452512394117"></a>double-conversion/build/CMakeCache.txt</p>
183    </td>
184    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p652615391617"><a name="p652615391617"></a><a name="p652615391617"></a>Cache files during CMake building</p>
185    </td>
186    </tr>
187    <tr id="row1526839312"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p28017499413"><a name="p28017499413"></a><a name="p28017499413"></a>double-conversion/build/CMakeFiles/</p>
188    </td>
189    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p25261439314"><a name="p25261439314"></a><a name="p25261439314"></a>-</p>
190    </td>
191    </tr>
192    <tr id="row15269396111"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p138014494415"><a name="p138014494415"></a><a name="p138014494415"></a>double-conversion/build/cmake_install.cmake</p>
193    </td>
194    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p75268391519"><a name="p75268391519"></a><a name="p75268391519"></a>-</p>
195    </td>
196    </tr>
197    <tr id="row185265399113"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p78054914419"><a name="p78054914419"></a><a name="p78054914419"></a>double-conversion/build/CTestTestfile.cmake</p>
198    </td>
199    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p65261039218"><a name="p65261039218"></a><a name="p65261039218"></a>-</p>
200    </td>
201    </tr>
202    <tr id="row125261139115"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p158064916419"><a name="p158064916419"></a><a name="p158064916419"></a>double-conversion/build/DartConfiguration.tcl</p>
203    </td>
204    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p20526939118"><a name="p20526939118"></a><a name="p20526939118"></a>-</p>
205    </td>
206    </tr>
207    <tr id="row2526839712"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p6803491043"><a name="p6803491043"></a><a name="p6803491043"></a>double-conversion/build/generated/</p>
208    </td>
209    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p115269395113"><a name="p115269395113"></a><a name="p115269395113"></a>-</p>
210    </td>
211    </tr>
212    <tr id="row173131653454"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p7803493412"><a name="p7803493412"></a><a name="p7803493412"></a>double-conversion/build/Makefile</p>
213    </td>
214    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p19316135318512"><a name="p19316135318512"></a><a name="p19316135318512"></a>-</p>
215    </td>
216    </tr>
217    <tr id="row4380879618"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p10381478619"><a name="p10381478619"></a><a name="p10381478619"></a>double-conversion/build/Testing/</p>
218    </td>
219    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p17381679610"><a name="p17381679610"></a><a name="p17381679610"></a>-</p>
220    </td>
221    </tr>
222    </tbody>
223    </table>
224
225
226## Library Test<a name="section6686144293611"></a>
227
2281.  Set up the OpenHarmony environment.
229
230    Using Hi3518EV300 as an example, compile the OpenHarmony image and burn it to the development board. For details, see  [Developing the First Example Program Running on Hi3518](../quick-start/quickstart-lite-steps-hi3518-running.md).
231
232    The following screen is displayed after a successful login to the OS.
233
234    **Figure  1**  Successful startup of OpenHarmony<a name="fig13279524162418"></a>
235    ![](figure/successful-startup-of-openharmony.png "successful-startup-of-openharmony")
236
2372.  Mount the  **nfs**  directory and put the executable file  **cctest**  into the  **test**  directory \(listed in  [Table 2](#table1452412391911)\) to the  **nfs**  directory.
2383.  Perform the test cases.
239
240    If the double-conversion library is not cross-compiled, you can execute the test cases by running the  **make test**  command and obtain the result via CMake. However, this command is not applicable to the library after cross-compilation. This way, you can perform the test cases by executing the generated test case files.
241
242    -   After the  **nfs**  directory is successfully mounted, run the following command to list all items in the test cases:
243
244    ```
245    cd nfs
246    ./cctest --list
247    ```
248
249    Some items are as follows:
250
251    ```
252    test-bignum/Assign<
253    test-bignum/ShiftLeft<
254    test-bignum/AddUInt64<
255    test-bignum/AddBignum<
256    test-bignum/SubtractBignum<
257    test-bignum/MultiplyUInt32<
258    test-bignum/MultiplyUInt64<
259    test-bignum/MultiplyPowerOfTen<
260    test-bignum/DivideModuloIntBignum<
261    test-bignum/Compare<
262    test-bignum/PlusCompare<
263    test-bignum/Square<
264    test-bignum/AssignPowerUInt16<
265    test-bignum-dtoa/BignumDtoaVariousDoubles<
266    test-bignum-dtoa/BignumDtoaShortestVariousFloats<
267    test-bignum-dtoa/BignumDtoaGayShortest<
268    test-bignum-dtoa/BignumDtoaGayShortestSingle<
269    test-bignum-dtoa/BignumDtoaGayFixed<
270    test-bignum-dtoa/BignumDtoaGayPrecision<
271    test-conversions/DoubleToShortest<
272    test-conversions/DoubleToShortestSingle<
273    ...
274    ```
275
276    -   Run the following command to test  **test-bignum**:
277
278    ```
279    ./cctest test-bignum
280    ```
281
282    The test is passed if the following information is displayed:
283
284    ```
285    Ran 13 tests.
286    ```
287
288
289## Adding the Compiled double-conversion Library to the OpenHarmony Project<a name="section1651053153715"></a>
290
2911.  Copy the double-conversion library to the OpenHarmony project.
292
293    Copy this library that can be cross-compiled to the  **third\_party**  directory of OpenHarmony. To avoid modifying the  **BUILD.gn**  file in the directory of the third-party library to be ported, add a directory to store adaptation files, including  **BUILD.gn**,  **build\_thirdparty.py**, and  **config.gni**, for converting GN to CMake building.
294
295    **Table  3**  Directory structure of the ported library
296
297    <a name="table13265185817173"></a>
298    <table><thead align="left"><tr id="row92666583171"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p2266105816178"><a name="p2266105816178"></a><a name="p2266105816178"></a>Directory</p>
299    </th>
300    <th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p32661158161718"><a name="p32661158161718"></a><a name="p32661158161718"></a>Description</p>
301    </th>
302    </tr>
303    </thead>
304    <tbody><tr id="row1526655816175"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p226605811710"><a name="p226605811710"></a><a name="p226605811710"></a>openHarmony/third_party/double-conversion/BUILD.gn</p>
305    </td>
306    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1626675812177"><a name="p1626675812177"></a><a name="p1626675812177"></a>GN file for adding the third-party library to the <span id="text2025921715555"><a name="text2025921715555"></a><a name="text2025921715555"></a>OpenHarmony</span> project</p>
307    </td>
308    </tr>
309    <tr id="row1726610589179"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12266115815170"><a name="p12266115815170"></a><a name="p12266115815170"></a>openHarmony/third_party/double-conversion/build_thirdparty.py</p>
310    </td>
311    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p122661958201719"><a name="p122661958201719"></a><a name="p122661958201719"></a>Script file for GN to call the <strong id="b45891919155715"><a name="b45891919155715"></a><a name="b45891919155715"></a>shell</strong> command to convert compilation from GN to CMake.</p>
312    </td>
313    </tr>
314    <tr id="row7266195891714"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p162665581170"><a name="p162665581170"></a><a name="p162665581170"></a>openHarmony/third_party/double-conversion/config.gni</p>
315    </td>
316    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p626712588175"><a name="p626712588175"></a><a name="p626712588175"></a>Third-party library compilation configuration file, which can be modified to determine whether the test cases will be used during the building</p>
317    </td>
318    </tr>
319    <tr id="row1272420109203"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p17725101052012"><a name="p17725101052012"></a><a name="p17725101052012"></a>openHarmony/third_party/double-conversion/double-conversion/</p>
320    </td>
321    <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p87252109205"><a name="p87252109205"></a><a name="p87252109205"></a>Directory of the third-party library to be ported</p>
322    </td>
323    </tr>
324    </tbody>
325    </table>
326
3272.  Add the GN file to the CMake adaptation file.
328
329    -   The following shows the implementation for building using the newly added  **BUILD.gn**  file. For other third-party libraries that can be independently compiled using CMake, you only need to change the target paths when porting them to OpenHarmony.
330
331    ```
332    import("config.gni")
333    group("double-conversion") {
334        if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
335            deps = [":make"]
336        }
337    }
338    if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
339        action("make") {
340            script = "//third_party/double-conversion/build_thirdparty.py"
341            outputs = ["$root_out_dir/log_dc.txt"]
342            exec_path = rebase_path(rebase_path("./build", ohos_third_party_dir))
343            command = "rm * .* -rf && $CMAKE_TOOLS_PATH/cmake .. $CMAKE_FLAG $CMAKE_TOOLCHAIN_FLAG && make -j"
344            args = [
345                "--path=$exec_path",
346                "--command=${command}"
347            ]
348        }
349    }
350    ```
351
352    -   The newly added  **config.gni**  file is used to configure the library in the following example implementation. For other third-party libraries that can be independently compiled using CMake, you only need to change the configuration of  **CMAKE\_FLAG**  when porting them to OpenHarmony.
353
354    ```
355    #CMAKE_FLAG: config compile feature
356    CMAKE_FLAG = "-DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=11"
357
358    #toolchain: follow up-layer, depend on $ohos_build_compiler
359    if (ohos_build_compiler == "clang") {
360        CMAKE_TOOLCHAIN_FLAG = "-DOHOS_SYSROOT_PATH=${ohos_root_path}prebuilts/lite/sysroot/"
361    } else {
362        CMAKE_TOOLCHAIN_FLAG = ""
363    }
364
365    #CMake tools path,no need setting if this path already joined to $PATH.
366    CMAKE_TOOLS_PATH = "setting CMake tools path..."
367    ```
368
369    -   The following shows the implementation of the newly added  **build\_thirdparty.py**  file. For other third-party libraries that can be independently compiled using CMake, you can port them to OpenHarmony without modifications.
370
371    ```
372    import os
373    import sys
374    from subprocess import Popen
375    import argparse
376    import shlex
377
378    def cmd_exec(command):
379        cmd = shlex.split(command)
380        proc = Popen(cmd)
381        proc.wait()
382        ret_code = proc.returncode
383        if ret_code != 0:
384            raise Exception("{} failed, return code is {}".format(cmd, ret_code))
385
386    def main():
387        parser = argparse.ArgumentParser()
388        parser.add_argument('--path', help='Build path.')
389        parser.add_argument('--command', help='Build command.')
390        parser.add_argument('--enable', help='enable python.', nargs='*')
391        args = parser.parse_args()
392
393        if args.enable:
394            if args.enable[0] == 'false':
395                return
396
397        if args.path:
398            curr_dir = os.getcwd()
399            os.chdir(args.path)
400            if args.command:
401                if '&&' in args.command:
402                    command = args.command.split('&&')
403                    for data in command:
404                        cmd_exec(data)
405                else:
406                    cmd_exec(args.command)
407            os.chdir(curr_dir)
408
409    if __name__ == '__main__':
410        sys.exit(main())
411    ```
412
413    -   Add a configuration item in the configuration file to control compiling of the library. By default, library compilation is disabled.
414
415    For example, add the following configuration to the  **//build/lite/ohos\_var.gni**  file:
416
417    ```
418    declare_args() {
419        ohos_build_thirdparty_migrated_from_fuchisa = true
420    }
421    ```
422
4233.  Build the library.
424
425    -   Manual building
426
427    Execute the following command:
428
429    ```
430    hb build -T //third_party/double-conversion:double-conversion
431    ```
432
433    If the compilation is successful, a static library file and test cases will be generated in the  [build](#li15717101715249)  directory.
434
435
436