This is a guide to setup a github residing cmake project in Eclipse. The target is a BBB and Eclipse should be set to the arm cross tool chain so that development and debugging on the BBB is possible.
Install the compiler tools for your target platform:
debian@pc:~/$ sudo apt-get install gcc-arm-linux-gnueabihf
The preferred way of installing Eclipse on a Debian system is NOT to use Debian package management tool because it provides a hopelessly outdated eclipse version.
Eclipse is a standalone Java application and needs an up to date version of the Java runtime environment, which can be provided by the OpenJDK available as Debian packages:
debian@pc:~/$ sudo apt-get install openjdk-11-jdk openjdk-11-jre
Be sure to set the correct java runtime environment in Debian's alternative configuration:
debian@pc:~/$ sudo update-alternatives --config java
Select the openjdk if necessary.
Download and install the latest version of Eclipse IDE for C/C++ Developers into the users home directory by unzipping the tar.gz file. Optionally add a new entry in the gnome menu.Start Eclipse and install some useful plugins via Marketplace:
cmake4eclipse
Remote System Explorer
Target Communication Framework
TM Terminal
DevStyle
As an example the EtherCat SOEM project is used here to compile and debug on a raspberry pi.
Go to Eclipse workspace and pull the cmake project (example SOEM) to be compiled for the ARM linux architecture and create a build directory.
debian@pc:~/$ cd workspace
debian@pc:~/workspace$ git clone https://github.com/OpenEtherCATsociety/SOEM.git
The code resides in the SOEM directory.
We need a cross build to generate a arm-linux-gnueabihf executable to be deployed to the BBB. Change into the cloned project and define a toolchain.cmake file for cmake. The file contains the definition of the used toolchain (arm-linux-gnueabihf).
debian@pc:~/workspace$ cd SOEM
debian@pc:~/workspace/SOEM$ nano toolchain.cmake
Add the following code to the file:
set(ARM_TOOLCHAIN_PREFIX arm-linux-gnueabihf-)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER ${ARM_TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${ARM_TOOLCHAIN_PREFIX}g++)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
Check in changes into local repo:
debian@pc:~/workspace/SOEM$ git add toolchain.cmake
debian@pc:~/workspace/SOEM$ git commit -a
There are two ways to build the project. The first way is just on the command line without the need for an IDE. The second way is use the Eclipse IDE.
debian@pc:~/workspace/SOEM$ mkdir build && cd build
debian@pc:~/workspace/SOEM/build$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake
debian@pc:~/workspace/SOEM/build$ make all
Results are stored in build directory.
When using Eclipse, the plugin cmake4eclipse must be installed to support cmake projects. The cloned project doesn't contain any Eclipse project files yet, so a new Eclipse project must be created in the cloned directory. In Eclipse go to File → New → Project… and select the C/C++ → C++ Project-wizard.
Press Next and choose a project name, browse to the cloned location in filesystem, select a project type Cmake driven → Empty Project with toolchain Cmake driven and set a project name.
In the project properties select C/C++ Build → Cmake4eclipse and select the tab Symbols. Add a cache entry with name CMAKE_TOOLCHAIN_FILE and set the value to toolchain.cmake for each configuration. This ensures the toolchain file containing cross build setting to be recognized.
The project should be added to the Project Explorer and is ready to be build in Debug and Release configurations.
To deploy, debug and monitor the build artifacts on the target via Eclipse, the following plugins are useful: