Contenuto principale

Configure Sources and Build Options in Project for Polyspace Analysis and Testing

Before running static analysis or tests with Polyspace Platform projects, it is essential to configure the build options correctly in the project configuration. In straightforward scenarios, the default build options can meet your requirements. However, typically, you need to explicitly configure the build options to accurately represent your build environment. Rather than setting these options manually, you can create a project using your build command. Projects created using a build command have the source paths and build options automatically determined from the build command.

Create Project Using Build System

If you use a build command such as make or cmake for building your source code or you are able to generate a JSON compilation database using your build system, you can create a Polyspace® Platform project from the build command or compilation database. The source files and build options in the project are determined from the compiler invocations in the build command or compilation database.

This topic shows how to create a Polyspace Platform project using build systems at the command line. For the equivalent workflow in the Polyspace Platform user interface, see Create Polyspace Platform Project From Build Command in User Interface.

Create Project from Build Command

To create a Polyspace Platform project or Polyspace options file for static analysis from a build command:

  1. Run the build command to perform a complete build of your source code and make sure that there are no build errors.

    For instance, you might run the following build command in a terminal:

    make -B <targetName>
    Where <targetName> is the name of a target in a makefile and the option -B ensures that the target and all its prerequisite targets are considered out-of-date and rebuilt.

  2. Create a Polyspace Platform project or options file using the build command.

    For example, if you ran make as shown in the previous step, to generate a Polyspace Platform project, you can run the following:

    polyspace-configure -output-platform-project myProject make -B <targetName>
    For more information, see polyspace-configure. Instead of -output-platform-project, you can use -output-options-file to generate a Polyspace options file for static analysis.

Create Project from Compilation Database

Tracing your build command requires keeping track of the underlying processes when you run the build command and identifying the compiler invocations. This method requires that your build command runs to completion without errors and your operating system allows tracking of the underlying processes. If your build system supports generation of a JSON compilation database, you can opt for a simpler method that can run faster and does not have the same limitations. You can simply read the compiler invocations from the compilation database and create a Polyspace Platform project with pre-configured source paths and build options.

To create a Polyspace Platform project or Polyspace options file for static analysis from a JSON compilation database:

  1. Generate the compilation database using your build system.

    For instance, if you use CMake to build your source code, in a terminal, navigate to the build directory and enter:

    cmake -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
    This command generates a JSON compilation database file compile_commands.json in the current directory.

  2. Create a Polyspace Platform project or options file using the compilation database.

    For example, if you generated a file compile_commands.json as shown in the previous step, to generate a Polyspace Platform project, you can run the following:

    polyspace-configure -output-platform-project myProject -compilation-database compile_commands.json
    For more information, see polyspace-configure. Instead of -output-platform-project, you can use -output-options-file to generate a Polyspace options file for static analysis.

Create Project and Configure Build Options Manually

If you can map your compiler and compilation options to the build options in the project configuration, you can also set the build options manually.

All other build options are common to static analysis and testing. You can set them proactively by mapping options in your build environment to Polyspace build options or reactively by troubleshooting errors during project build or static analysis. For more information on the options, see Polyspace Code Prover Options in Polyspace Platform User Interface.

See Also