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:
Create a CMakeLists file (
CMakeLists.txt) that contains the build instructions in the CMake language.Invoke the
cmakecommand that uses theCMakeLists.txtfile 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 to a writable location. The folder contains a CMakeLists file that contains the generators for a simple project. Here, polyspaceroot\polyspace\examples\doc_ps_setup\compilation_database is the Polyspace installation folder, for instance, polyspacerootC:\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:
In a terminal, navigate to the folder containing the CMakeLists file and create a new folder
generated_commandsto store the generated files. Change directory to this folder.mkdir generated_commands cd generated_commandsUsing the
cmakecommand, generate a compilation database corresponding to the CMake build:Thecmake -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ../cmakeoption-G "Unix Makefiles"generates a makefile and the option-DCMAKE_EXPORT_COMPILE_COMMANDS=1generates 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_commandscontains a filecompile_commands.jsonthat 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-configureon the compilation database that you generated in the previous step.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.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.