Manexa as dependencias de C ++ con Clickable

Se un aplicativo depende dunha biblioteca que non está preinstalada en Ubuntu Touch, o aplicativo deberá enviala dentro do paquete de clic. Esta guía mostra como se pode facer isto con Clickable.

Construción

Ás veces, as bibliotecas están dispoñibles previamente, o que lle permite saltar o paso de compilación. Recoméndase recompilar a súa dependencia, xa que lle proporciona máis control sobre todo o proceso e pode levar a mellores resultados (por exemplo, un mellor rendemento ou tamaños de paquetes máis pequenos).

Ubicación

Put the library’s source code at libs/LIBNAME (replacing LIBNAME by the library’s name), because this is where clickable will look for it by default. If the dependency source code is available as a git repository, it is a good idea to add it as a git submodule. Otherwise add a script to download the sources.

Add a libraries section to your clickable.yaml, like this:

 builder: "cmake"
 libraries:
   LIBNAME:
     builder: "cmake"

Se a biblioteca non contén unha configuración de CMake, deberá empregar o constructor qmake ou` personalizado`.

Optionally, configure the compilation by adding build_args, which may look like this:

 builder: "cmake"
 libraries:
   LIBNAME:
     builder: "cmake"
     build_args:
     - "-DBUILD_EXAMPLES=OFF"
     - "-DBUILD_DOCS=OFF"
     - "-DBUILD_TESTS=OFF"
     - "-DBUILD_SHARED_LIBS=OFF"

Most build arguments are project specific. Therefore, study the library’s build instructions and also look for option settings in its CMakeLists.txt .

To actually build the library for all architectures run clickable build --libs --arch armhf, clickable build --libs --arch arm64 and clickable build --libs --arch amd64. Don’t forget to mention this step in your README, so that others can reproduce the build process.

See how Teleports clickable.yaml uses the libraries feature to build its dependency tdlib.

Precompilación

Se compilou a súa biblioteca como se describiu anteriormente, omita este paso.

A pre-built library is usually only available as a shared object that needs to be linked dynamically. Furthermore, it may contain components that you don’t need, resulting in a bloated app. It may even miss something that you could achieve by compiling it yourself. Sometimes, a library is available in the Ubuntu Repositories, but is not installable for the architecture you need (likely armhf or arm64). In this case you have to compile the library as described above.

Se a biblioteca está dispoñible nos Repositorios de Ubuntu, pode engadila á lista de dependencias, así:

 builder: "cmake"
 dependencies_target:
 - "libsomething-dev"

Clickable will install the specified package automatically for the target architecture inside the build container. An example can be found in Guitar Tools” clickable.json.

If the library can be found in a PPA, you can add the PPA to the clickable.yaml, too. For example:

 builder: "cmake"
 dependencies_ppa:
 - "ppa:someone/libsomething"
 dependencies_target:
 - "libsomething-dev"

Se non, engada un script para descargar a biblioteca pre-construída.

Uso

En primeiro lugar, cómpre especificar o directorio de inclusión onde se poden atopar as cabeceiras que inclúe no código fonte do aplicativo. En segundo lugar, cómpre ligar o binario da biblioteca co binario do seu aplicativo.

In case the library contains a CMake configuration file, you can use the find_package command, which provides you with a target to link against or variables pointing to the library’s binary and include directories. The additional lines on your CMakeLists.txt then may look like:

find_package(SOMELIBRARY REQUIRED)

include_directories(${SOMELIBRARY_INCLUDE_DIRS})
target_link_libraries(mytarget ${SOMELIBRARY_LIBS})

The find_package command usually defines the path to the include directory as SOMELIBRARY_INCLUDE_DIRS and the library’s binaries as SOMELIBRARY_LIBS (check on the library’s documentation on what their CMake configuration provides exactly). Use them with the include_directories and target_link_libraries commands. See the Camera Scanner ImageProcessing CMakeLists.txt for a real world example.

At this point you should already be able to test with Clickable’s desktop mode running clickable desktop.

Despregamento

Se ligaches a biblioteca de xeito estático, podes omitir este paso, xa que o binario da biblioteca xa está dentro do binario do teu aplicativo.

Find out which shared object files (*.so) you need to ship. You can do so by starting the app on your device via clickable && clickable logs. You should see an error message telling you which shared object file was missing.

Find the path to the shared object files. For libraries built via clickable, they are located somewhere in the library’s install dir, which is located inside the library’s build dir by default (e.g. build/arm-linux-gnueabihf/opencv/install). For pre-built libraries run clickable run "find / -name 'libSomething.so'" (replacing libSomething.so by the file your are looking for). This should print the path to the file (along with some error messages you can ignore). In general, /usr/lib is a good bet when looking for the shared object files.

To get the files into the click package, add the install_lib key to your clickable.yaml:

 builder: "cmake"
 libraries:
   LIBNAME:
     builder: "cmake"
     install_lib:
     - "$LIBNAME_LIB_INSTALL_DIR/usr/lib/$ARCH_TRIPLET/libqmapboxgl.so*"
     - "/usr/lib/$ARCH_TRIPLET/libSoundTouch.so.*"

The lines above contain two examples. The first one installing a library built with Clickable. The asterisk in .so* helps to catch symbolic links along with the actual library which are used to point to the current version.

Dependendo da biblioteca, é posible que deba enviar algúns datos adicionais. Nese caso consulte o readme da biblioteca ou as instrucións de instalación.

You should be set up to build and install your click package on a device connected to your computer now by running clickable.