8.4.2. Eclipse Project Setup

Eclipse for C/C++ can be used in many different ways, and consequently there are different ways to build your project for analysis with Axivion Suite. We try to enumerate some of the most common setups. The descriptions are written for a setup on Windows, but the same type of setup also works on other operating systems.

The major distinction of Eclipe CDT projects is between

  • projects built by an external build tool (Makefile Projects)

  • projects managed by Eclipse CDT (Managed Make)

8.4.2.1. Makefile Project

Eclipse can be used for projects with external makefiles. In this case, Eclipse only triggers the build by calling an external make tool. Please setup the project using this external make tool and do not use Eclipse as build driver.

8.4.2.2. Managed Make

In Managed Make projects, Eclipse is responsible for maintenance of the build rules. You have to setup a cross-compile build which builds the project not with the original compiler and linker, but with the Axivion tool chain using cafeCC.

Basic Configuration in Eclipse

For the project setup, you can either use an existing configuration or create a new one.

Create a new Build Configuration for the build with Axivion Suite

You can add a new Build Configuration to your project and configure the C/C++ Tool chain to run cafeCC and build IR directly. This setup is possible, if you mainly use configurations for different types of build (e.g. “Debug” and “Release”) which can easily be cloned, and which do not change often.

To configure this, from the project Properties: choose C/C++ Build and click on Manage Configurations. Add the new configuration. Go to C/C++ Build, Settings and configure all build tools to execute cafeCC.

Now, if you select this build configuration, Eclipse will build an IR File which can be picked up for analysis.

Use an existing Build Configuration

If you prefer not to maintain an extra build configuration for the build with Axivion Suite, you can use an existing one. This is preferable if you use different build configurations for different variants of your software and want to analyze several of them using Axivion Suite. In a typical setup, you can configure the build tool chain of a configuration to make the compiler exchangeable easily. Please configure in the project properties:

  1. C/C++ Build, Environment: Add Environment variables (assuming you are using gcc and g++ as compilers for C and C++):

    1. CC=gcc

    2. CXX=g++

  2. C/C++ Build, Settings, Tool Settings: Set the C-Compiler to $(CC), C++-Compiler to $(CXX) and C++-Linker to $(CXX).

Setup Server Build

To setup the server build (i.e. when axivion_ci runs in ci_mode), Eclipse can be started in a headless mode to build the project. How to do this depends on the specific flavor of the Eclipse installation. In the following, we describe one default way. Please note that this build mode can only be executed while the Eclipse workspace is not locked. This means that the headless build cannot run, if an open Eclipse instance uses the same workspace. We assume that the server build has its own workspace, which is not opened otherwise during the server build.

  1. in start_analysis.bat: set the name of the Eclipse build configuration in an environment variable. This variable can be referenced from the project configuration and from the build process. In the following, we assume that the configuration “Release” is used:

    set "CONFIG_NAME=Release"
    axivion_ci
    
  2. Create a file build_ir.bat to call Eclipse in a headless mode

    set "CONFIG_NAME=%1"
    eclipsec ^
      --launcher.suppressErrors ^
      -nosplash ^
      -application org.eclipse.cdt.managedbuilder.core.headlessbuild ^
      -importAll "%IDE_PROJECT_PATH%" ^
      -data "%IDE_WORKSPACE_PATH%" ^
      -cleanBuild "%CONFIG_NAME%"
    
  3. If you used the variant with environment variable to configure the compiler (see Use an existing Build Configuration), add the following options to the build command:

    -E CC=cafeCC ^
    -E CXX=cafeCC ^
    
  4. In your project configuration, choose Command as BuildSystemIntegration and set build_command to $(builtin:AXIVION_CONFDIR)/build_ir.bat $(env:CONFIG_NAME).

  5. Configure a suitable clean_command, if cleaning of the workspace is not done via your external CI.

Setup Local Build

  1. If you configured a separate build configuration in Eclipse (as in step Create a new Build Configuration for the build with Axivion Suite), you can execute the Local Build in two steps:

    1. Build the respective configuration in Eclipse via the normal build command

    2. Configure /Project/ir in your project configuration to pick up the IR file generated by this build configuration

  2. If you decided to reuse an existing build configuration, we cannot use the built-in build feature of Eclipse. The following issues need to be considered:

    • in the original build, the compiler shall be replaced with cafeCC

    • the original build should not be overwritten by the Axivion build and vice-versa

    • the Axivion build should run incrementally

    • we cannot use the Eclipse headless build, because the workspace will be locked while Eclipse is running

    Therefore, we setup the Local Build to directly call GNU Make and avoid the workspace lock:

    1. In the project properties, C/C++ Build select an “External Builder”. This option will make Eclipse write makefiles to the original build tree.

    2. Uncheck the option “Expand Env. Variable Refs in Makefile”. Unchecking this option will make Eclipse write the $(CC) and $(CXX) Variables into the Makefiles instead of replacing them with the compiler name.

    3. In your build_ir.bat file, create an alternative section for the Local Build. This alternative is activated when axivion_ci is run in local_mode and thus implicitly sets the environment variable AXIVION_LOCAL_BUILD. This variable can be used as condition to select this alternative case:

      1. Clone the Makefiles generated for the original build into a separate build tree directory using the script clone_build_structure.py. This step is optional, you could also re-use the original build tree and use CC="cafeCC -with_ir_suffix" CXX="cafeCC -with_ir_suffix" instead.

      2. Build the project by calling GNU make from your start_analysis.bat:

      if defined AXIVION_LOCAL_BUILD (
         rfgscript "%~dp0clone_build_structure.py" "%CONFIG_NAME%"
         make -C "%LOCAL_BUILD_DIR%" CC=cafeCC CXX=cafeCC  all
      ) else (
         rem server build, code see above
      )
      
    4. Make sure to pass the Eclipse build configuration as the 1st parameter to build_ir.bat and to execute build_ir.bat in a working directory so that the 1st parameter is a relative path to the existing original build tree.