Hvigor integrates CMake and Ninja as the build tools for C++ code. The initial configuration should suffice in most cases. Yet, you can add your custom configuration whenever necessary.
The following shows the configuration items contained in the module-level build-profile.json5 file.
{
...
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
},
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt", // Path of the custom CMakeLists.txt file. It is a relative path starting from the root directory of the module.
"arguments": ["-DCMAKE_BUILD_TYPE=Debug"], // Custom arguments to pass to CMake. For details about the build parameters, see the official documentation of CMake. The arguments will overwrite the default ones with the same names.
"cppFlags": "-g", // Custom C++ flag.
"abiFilters": ["arm64-v8a"] // Target architecture. Default: arm64-v8a.
},
"nativeLib": {
"debugSymbol": { // Configuration for stripping the symbols and debugging information from .so files of C++ build products.
"strip": true, // Perform stripping.
"exclude": [] // Regular expression to use for exclusions from the strip scope.
},
"filter": { // Configuration for packing .so files into the app package.
"excludes": [ // .so files to exclude from the app package. You can use this option to reduce the package size.
"**/3.so", // Exclude all .so files whose names are 3.
"**/x86_64/*.so" // Exclude all .so files of the x86_64 architecture.
],
"pickFirsts": [], // Pack the .so file with the highest priority based on the priority of the .so files.
"pickLasts": [], // Pack the .so file with the lowest priority based on the priority of the .so files.
"enableOverride": true, // Allow the .so file with a higher priority to override the .so file with a lower priority when these files have the same name.
"select": [ // Options for precise selection of native products, allowing you to choose or exclude based on package name, version, product name, and more. The priority of select is higher than configuration items such as excludes and pickFirsts.
{
"package": "@ohos/curl", // Package name
"version": "1.3.5", // Package version
"include": ["libcurl.so"], // Native products to include
"exclude": ["libc++_shared.so"] // Native products to exclude
}
],
},
"headerPath": "./src/main/cpp/include" // File that declares the C/C++ interfaces shared by the module.
"librariesInfo":[
{
"name": "libentry.so",
"linkLibraries": ["curl::curl"]
}
]
},
},
],
...
} You can customize the externalNativeOptions parameters to modify the CPP build behavior. Under nativeLib/headerPath, you can declare the C and C++ interface file of the module and expose the file to the dependent modules through packaging. Through debugSymbol and filter, you can modify the size and packaging rules of .so products.
The priority of .so library files can be set through the pickFirsts and pickLasts options. The pickFirsts option is used to choose higher priority library files, while pickLasts is for selecting lower priority ones.
The priority is determined by the collection sequence of the dependencies (modules or third-party packages) of the current module. The dependencies of the current module are declared in the dependencies configuration item of the oh-package.json5 file. The collection order follows a breadth-first traversal mode.
In the following figure, the priority order is current > library0 > library1 > library5 > library2 > library3 > library4.

The select option allows for precise selection of native products based on package name, version, and product name, enabling the inclusion or exclusion of native products in HAP, HSP, and HAR files.
For example, if a module depends on libcurl.so from the @ohos/curl HAR file and there are multiple versions of libcurl.so available, you can use the select option to include the .so file of a specific version (1.3.5 in this example) into the product.
{
buildOption: {
nativeLib: {
filter: {
select: [ // The priority of select is higher than excludes, pickFirsts, and other configuration items.
{
package: "@ohos/curl", // Package name
version: "1.3.5", // Package version
include: ["libcurl.so"], // Native product to include
exclude: ["libc++_shared.so"] // Native products to exclude
}
]
}
}
}
}