Contenuto principale

Create Polyspace Platform Projects from CMake Builds

This topic shows how to create a Polyspace® project or options file using existing CMakeLists files. For information on the CMake plugin that allows you to introduce Polyspace Test™ workflows into CMakeLists files, see Use CMake to Execute Tests Authored Using Polyspace Test xUnit API (Polyspace Test).

CMake is a third-party, open source tool for build process management that allows you to specify the build instructions for your code base in a platform and toolchain independent CMake language. When using CMake, you:

  1. Create a CMakeLists file (CMakeLists.txt) that contains the build instructions in the CMake language.

  2. Invoke the cmake command that uses the CMakeLists.txt file to generate standard build files. These include makefile and Ninja, as well as Microsoft® Visual Studio® and Xcode project builds.

To learn more about CMake, see the CMake Tutorial.

If you use CMake to generate your build files, you can leverage the information in the CMakeLists file to create a Polyspace project or options file.

Prerequisites

This topic assumes that you are able to run cmake commands in a terminal.

You can follow the steps here with any CMake project. If you want to start with a sample project, copy the files in polyspaceroot\polyspace\examples\doc_ps_setup\compilation_database to a writable location. The folder contains a CMakeLists file that contains the generators for a simple project. Here, polyspaceroot is the Polyspace installation folder, for instance, C:\Program Files\Polyspace\R2026a.

Export JSON Compilation Database

Generate a compilation database file corresponding to the CMake build.

For instance, if you use CMake to generate makefiles to build your source code, you can generate a compilation database in addition to the makefile using these steps:

  1. In a terminal, navigate to the folder containing the CMakeLists file and create a new folder generated_commands to store the generated files. Change directory to this folder.

    mkdir generated_commands
    cd generated_commands
  2. Using the cmake command, generate a compilation database corresponding to the CMake build:

    cmake -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ../
    The cmake option -G "Unix Makefiles" generates a makefile and the option -DCMAKE_EXPORT_COMPILE_COMMANDS=1 generates a compilation database containing commands that are equivalent to the build instructions in the makefile.

    If the command completes execution without errors, the folder generated_commands contains a file compile_commands.json that you can use to create a Polyspace project or options file.

Create Polyspace Project or Options File

Create a Polyspace Platform project or options file using the compilation database compile_commands.json created in the previous step. You can create a project either at the command line or in the Polyspace Platform user interface:

  • On a terminal, run polyspace-configure on the compilation database that you generated in the previous step.

    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.

  • In the Polyspace Platform user interface, select File > Project From Build Command and enter the details of your compilation database. For more information, see Add Sources from Build Command.

See Also

Topics