How it works...

First, we install CMake to our build system. Once the installation is complete, we switch to the native environment to create CMakeLists.txt. This file contains high-level build instructions about the project's composition and properties.

We name our project hello, which creates an executable, called hello, from a source file named hello.cpp. Additionally, we specify the minimal version of CMake required to build our application.

After we have created the project definition, we can switch back to the build system shell and generate low-level build instructions by running make

It is common practice to create a dedicated build directory to keep all our build artifacts. By doing this, the object files generated by a compiler or files generated by CMake do not pollute the source code directories. 

In a single command line, we create a build directory, change to the newly-created directory, and run CMake.

We pass the parent directory as a parameter to let CMake know where to look for CMakeListst.txt:

By default, CMake generates the Makefile files for the traditional Unix make utility. We run make to actually build the application:

It works, but results in an executable binary built for the x86 platform, while our target system is ARM:

To solve this, we add several options to our CMakeLists.txt file to configure cross-compilation. Repeating the build steps again, we get a new hello binary, now for the ARM platform:

As we can see in the output of the file command, we have built the executable file for the ARM platform, not x86, which we used as a build platform. This means that this program will not run on the build machine, but can be successfully copied to our target platform and run there.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.30.162