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:
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:
Wheremake -B <targetName><targetName>is the name of a target in a makefile and the option-Bensures that the target and all its prerequisite targets are considered out-of-date and rebuilt.Create a Polyspace Platform project or options file using the build command.
For example, if you ran
makeas shown in the previous step, to generate a Polyspace Platform project, you can run the following:For more information, seepolyspace-configure -output-platform-project myProject make -B <targetName>polyspace-configure. Instead of-output-platform-project, you can use-output-options-fileto 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:
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:
This command generates a JSON compilation database filecmake -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .compile_commands.jsonin the current directory.Create a Polyspace Platform project or options file using the compilation database.
For example, if you generated a file
compile_commands.jsonas shown in the previous step, to generate a Polyspace Platform project, you can run the following:For more information, seepolyspace-configure -output-platform-project myProject -compilation-database compile_commands.jsonpolyspace-configure. Instead of-output-platform-project, you can use-output-options-fileto 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.
For static analysis using Polyspace Bug Finder™ or Polyspace Code Prover™, you must set the option
Compilation toolchain (Static Analysis)For running tests using Polyspace Test™, you must set these options:
Compilation toolchain (Testing)(Polyspace Test)By default, this option is set to using the automatically detected toolchain.
Target board name (Testing)(Polyspace Test)By default, this option is set to running tests on your host computer.
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 Bug Finder Options in Polyspace Platform User Interface.