Set up a local project
For each coherent, buildable component that you work on, create a local project -- a repository for your analysis results and settings. You need to set up a project only once for each component you work on.
Capture your build settings
Klocwork requires a build specification to perform an analysis. The build specification contains a list of the project's source files and their compiler options (such as includes and defines for C/C++). Klocwork creates the build specification by monitoring the IDE build process or by monitoring an external (command-line) build process. The former is recommended as it automatically updates the build specification when files are added or removed from the project.
Important: Do not rely on the Eclipse CDT indexer to generate the build specification, because this method has proven inaccurate.
Option 1: If you build outside Eclipse or Wind River Workbench
Run kwinject directly to create a build specification. See Creating a C/C++ build specification.
After you generate your build specification, you need to Specify your build settingsIn the Project Properties, select Klocwork Build Settings.Select Use build specification file, browse to the build specification you created, and click OK.The properties are saved for the selected project and used when you run your next analysis. You only have to specify build settings once for your project, as long as your updated build specification file remains in the same location..
Option 2: If you build inside Eclipse or Wind River Workbench
The steps vary depending on whether you are using Eclipse, QNX Momentics or Wind River Workbench.
If you are using QNX Momentics, see Capturing your build settings for QNX Momentics.
If you are using Wind River Workbench, see Integrating Klocwork with Wind River Workbench.
Eclipse
- Go to Project Properties > C/C++ Build > Tool Chain Editor.
- Change the Current Builder for your active configuration from CDT Internal Builder to Gnu Make Builder and click Apply .
- Go to Project Properties > C/C++ Build.
- In the Builder Settings tab, deselect Use default build command.
- For Eclipse 4.18 or older: In the Build command field, replace your build command with the following:
<klocwork_user_install>/bin/kwinject -u -o ${ProjDirPath}/kwinject.out <build_command>
where <build_command> is your build command, for example,
make
See kwinject for an explanation of the options.
For Eclipse 4.20 or newer: In the Build command field, replace your build command with the following:<klocwork_install>/bin/kwinject.exe
To specify build arguments, go to the Behavior tab, select Use custom build arguments, and enter your options in the Build arguments field. For example:
-u -o ${ProjDirPath}\kwinject.out make
- Click OK.
- To create the build specification, clean and build the project.
You need to run a "clean" build only once to create the initial build specification in the project directory. After that, when you build, kwinject will update the build specification when files are added or deleted.
Specify your build settings
- In the Project Properties, select Klocwork Build Settings.
- Select Use build specification file, browse to the build specification you created, and click OK.
The properties are saved for the selected project and used when you run your next analysis. You only have to specify build settings once for your project, as long as your updated build specification file remains in the same location.
Connect to a project or stream on the Klocwork Server
You get the most from static code analysis when you connect a small local project to a larger project or stream on the Klocwork Server. The small local project is analyzed quickly while incorporating Klocwork knowledge bases generated on the server where additional source files were analyzed (for example, shared libraries). Connecting to a server project or stream also allows you to share issue status information with the integration build analysis and among team members. You can run a standalone desktop analysis, but the analysis only derives knowledge from the local project's source files.
You perform this step only once for each project.
- In the project properties view navigator, expand Klocwork and select Enable project specific settings.
- Click the Synchronization tab.
- Ensure that the Klocwork Server host and port information is correct.
- In the Project name list, select the server project or stream you want to connect to.
- Enable the Use secure connection checkbox if a secure connection to the Klocwork Server has been set up.
- Click OK.
When you set up your connection, synchronization occurs between the integration project and your desktop project, pulling configuration information from the integration project.
You only have to do this step once for each project.
Import or export your local project synchronization settings
Rather than modify the settings for each project in your workspace, you can perform a batch import/export of all local project synchronization settings for an entire workspace. When exported, the settings are stored in a simple XML file which can be shared with other developers or re-imported to rebuild a workspace.
When imported into a new workspace, all project synchronization settings in the new workspace will be overridden. This is true for all projects, regardless of whether or not the Enable project specific settings checkbox is enabled. If project MyProj in Workspace A has Enable project specific settings disabled, and project MyProj in Workspace B has Enable project specific settings enabled, the configuration settings for project MyProj in Workspace B will be overwritten and local project settings will be disabled.
The configuration settings include:
- enabling project specific settings
- the host name and port number of the Klocwork Server
- secure connection settings
- the name of the associated project on the server
To export your project synchronization settings
- In the Klocwork and select Settings. dialog, expand
- Click Export Map..., then specify a file name and location for your export map file and click Save.
Click View Map to view the configuration mapping file in your default XML viewer. The following listing shows the format of a typical output file with two projects:
<SyncMapping> <ProjectSettings EclipseProjectName="myProj"/> <ProjectSettings EclipseProjectName="HelloWorld3"> <ProjectSyncInfo KwProjectName="HelloWorld3" KwServerHost="server11" KwServerPort="8080" KwSslEnabled="true"/> </ProjectSettings> </SyncMapping>
To import a configuration mapping file
- In the Klocwork and select Settings. dialog, expand
- Click Import Map..., then specify the file name and location for the exported map file and click Open.
- Click OK to import the configuration map file.