Building C/C++ Project with Travis CI for Multiple OSs and CPUs

Three years ago, I created a CMake project, aiming to build a C/C++ project with Dynamsoft Barcode Reader on Windows, Linux, and macOS. Today, as the world’s top barcode SDK, Dynamsoft Barcode Reader has extended to more operating systems and CPU architectures:

  • ARM32 Linux: Raspberry Pi
  • ARM64 Linux: Jetson Nano

Now, I only have a Windows PC in hand. How can I build the project for all target environments without purchasing new hardware devices or spending time setting up virtual environments?

One of the economical ways is to use Travis CI. Travis CI is a hosted continuous integration service that supplies virtual machines to build, test, and deploy projects.

Barcode SDK for Linux(AMD64, ARM64, ARM32), Windows(x86, x64), and macOS

The SDKs are scattered in three places:

AMD64 and ARM32 Linux

x86 and x64 Windows

macOS

ARM64 Linux

Extract the SDK from one of the (*)manylinux2014_aarch64.whl files.

CMake Configuration for ARM32 and ARM64 Barcode SDK

If the operating system is the same, we can link a specific library file by evaluating CMAKE_SYSTEM_PROCESSOR:

Why is ARM32_BUILD required? According to the online documentation, there is no ARM32 virtual machine available.

Therefore, to build the project for ARM32 devices like Raspberry Pi, a workaround is to install a cross-compiler in the ARM64 Linux environment and add a CMake option:

Before taking the next step, do a quick test to assure the CMake project can be built successfully.

Configuring Travis.yml for Different OSs and CPUs

Create a travis.yml file in the project root directory.

The following jobs are used to create different virtual machines:

The last one is a little bit special, for I need to install some tools for compiling the ARM32 project on ARM64 Linux.

Add scripts to make the build work on all target platforms:

Finally, do not forget to add the status badge in README.md:

Source Code

https://github.com/Dynamsoft/cmake

Originally published at https://www.dynamsoft.com on February 22, 2021.

Manager of Dynamsoft Open Source Projects | Tech Lover