Creating a C/C++ build specification
Creating a C/C++ build specificationKlocwork integrates with your build, capturing all of the information it needs to provide a centralized view of the entire code stream. It stores this information in a structured build log -- a text file we call a build specification. The build specification is the basis of the Klocwork analysis. It's important that the build specification is an accurate and up-to-date representation of your build. If the build specification is inaccurate, the Klocwork analysis will be inaccurate too. A build specification is required at both the integration and local build levels.
This article shows you how to use kwinject to capture your build settings. kwinject is recommended for capturing build settings for all C/C++ projects, except if you are running distributed builds (where the compiler is executed across several machines):
Prerequisites Before you can create a build specification, you need to install the Server package. See Installing Klocwork. Capture your build settingsTroubleshooting: Not sure if your compiler is supported out-of-the-box? Go to Making sure kwinject recognizes your compiler. In your build environment, issue your regular build command, but prefix it with the kwinject command, plus whatever kwinject options you need. For a full list of kwinject options, see kwinject. kwinject [kwinject_options] <build_command> [args] For example: if your build command is "make", run: kwinject make A build specification (called kwinject.out by default) will be created when your build is complete. Example This example uses zlib. Just substitute your information for the zlib-specific information:
Troubleshooting: If you see the error message "Compiler can't be configured", see kwinject error - Compiler can't be configured.
Visual Studio projectsYou can use kwinject to create a build specification if you build your Visual Studio projects from the command line (with devenv, msdev, vcbuild or msbuild). Note: We recommend that you run kwinject from a Visual Studio command prompt in order to more accurately capture the Visual Studio build environment settings.
Examples: kwinject --output test.out devenv mysolution.sln /Rebuild kwinject --output test2.out msbuild mysolution.sln /t:Rebuild /p:Configuration=Debug Tip: You don't need to specify the configuration with devenv, because it uses the default.
If you are using VS2010 or VS2012: In order to produce the correct build specification, you must do the following:
Making sure kwinject recognizes your compilerFor kwinject to recognize your compiler name, you may need to identify what compiler type is associated with your compiler (for example, gcc is a variant of GNU). Go to C/C++ compilers supported for build integration and look up your compiler type to see if it's supported.
Notes for specific compilersTo automatically deploy a custom binding to build machines and developer desktops, you need to deploy a custom kwfilter.conf file, as follows:
Here are some sample compilers: Green Hills GHS: Add the following lines: filter ghs gcc, gcx, ccarm, cxarm, ccmips, cxmips #filter ghscom ecomarm
#filter gnu gcc, g++, cc, c++ Intel XL C/C++: Add the following line: filter xlc cc
#filter gnu gcc, g++, cc, c++ GNU: Add the following line if ld is invoked directly (not through gcc): filter gnu_ld ld Metaware High C/C++: Add the following line if ldarc is invoked directly (not through hcarc): filter ldarc ldarc, ldac CodeWarrior Freescale S12: Add the following lines if you use the CodeWarrior S12 linker and libmaker: filter link_hc12 linker filter lib_hc12 libmaker Wind River Diab: Add the following line if you are using the "coverage" tool: filter coverage coverage VSI-Cafe: For VSI-Cafe, add these lines: filter cafe_compile cl filter cafe_link link Review your build specification for accuracyOnce you've got a build specification, confirm the existence of compile , link and config lines. Carefully review the build specification to ensure that your compiler options have been processed properly. For more information on making sure kwinject has accurately captured your build settings, see: If your build specification contains only a version line or is missing the config line, go to Troubleshooting an incomplete kwinject build specification. When to update your build specificationYou need to update or create a new build specification in the following situations:
If you reuse an existing build specification or try to modify it manually in these situations, the analysis results will not be accurate. Note: If you have done a clean build (full rebuild of your source files), we recommend that you create a new build specification and perform a full build analysis. See Running a full build analysis.
Incremental updates to your build specificationAfter you have created a build specification with kwinject, you can update it, rather than creating an entirely new build specification, whenever you perform an incremental analysis of your desktop or integration project. Use the --update option of kwinject to update an existing build specification. For more information, see Running incremental analysis. What's next?Now it's time to use your build specification to run an analysis.
|