CMake and running PC-Lint at file-level in Visual Studio - visual-studio

Is there way to run PC-Lint either for a specific file or for the whole project in CMake-generated Visual Studio projects?
Currently I'm able to run PC-Lint per-project by creating custom targets using Kitware's script, but in my environment linting the whole project may take up to 10 minutes. So, I would also like to have a possibility to lint a specific source file only (and to choose that file from Visual Studio).
I was thinking, if PC lint could be used as custom "compiler" and to create for my target another project_LINT target that uses the lint "compiler". Then I could maybe select individual files to be "compiled". Or is this idea doomed? :)

Related

Source file list from a Visual Studio project

Is there any way of passing the list of source files, that Visual Studio would build, to a makefile. Ideally Visual Studio would set an environment variable with a list of the files to compile. But unfortunately I have not discovered such a variable. I know I could write a script to parse the project file but I would really like to find a method which does not rely on a script. I would like to be able to set up the Visual Studio project so that different source files are built depending on the build configuration, using the Exclude from Build option. I would then like the makefile to only build the files that were not excluded. I am attempting to use Visual Studio as the development environment for a project which runs on different hardware and OS combinations.
P.S. Using Visual Studio is non-optional, and not my personal choice.
Create a MakeFile project within the VS solution.
This should be found under File -> New -> Project -> Visual C++ -> Other -> Makefile Project
Using Visual Studio 2017, there is a MakeFile template that can be used.
Additional instructions on how to do so can be found here

Use cmake to generate Visual Studio sln project without link to original CMakeFiles.txt

I need to use cmake to generate visual studio sln file, BUT I want to ensure, that this generated *.sln file will not be connected with original CMakeFiles.txt (I want to generate sln file once).
I know that this is not typical usage and the connection with source CMakeFiles.txt is in standard usage perfect, but in my case it is not wanted -- I want to distribute these sln files (solution with projects) to some colleagues, who do not have CMake.
Maybe there is another approach (except cmake), to create few visual studio project without annoying clicking in Visual Studio.
Thanks,
Radek
I need to use cmake to generate visual studio sln file, BUT I want to
ensure, that this generated *.sln file will not be connected with
original CMakeFiles.txt
By design CMake will generate solution files that depend on CMake so this part is not really possible with CMake alone.
Maybe there is another approach (except cmake), to create few visual
studio project without annoying clicking in Visual Studio.
There is a way to stop regeneration in the IDE. I use this in many of my projects most likely for the same reason you do. At least with older versions of Visual Studio the regeneration caused dozens of prompts. Although I believe Visual Studio 2013 only prompts 1 time now I still enable this. The following code (inserted near the top of my root CMakelists.txt) is what I use to enable the option to suppress IDE regeneration.
option (CMAKE_SUPPRESS_REGENERATION "Suppress the cmake macro that causes regeneration of build scripts during build" ON)

Visual Studio 2010 custom compile using batch file

I have recently converted a mid-sized Visual Studio 2005 solution to Visual Studio 2010.
One of the projects contains files which are not C/C++ files and are compiled using a batch file running a custom build tool. The output of the custom build step is some C++ files, which must be compiled after that.
The output of the custom build step in the properties for the relevant files is correctly set to the generated C++ files.
The problem is that sometimes VS2010 tries to compile the generated C++ files before the files with the custom build step, which means in a clean build it fails to find the C++ files and fails. If I try building several times eventually it would compile the custom files and then the build will succeed, but this is obviously not a good solution for automated build.
In VS2005 there is no problem building this project, but VS2010 fails to determine the correct compile order from the outputs of the custom build step. Is there another way to force correct compile order in VS2010?
Visual Studio supports parallel builds, it can build more than one project at the same time. This will not work properly if it cannot properly see the dependencies between projects. A custom build can certainly be a troublemaker here. The number of parallel builds is configurable, setting it to 1 would be a very crude but effective workaround. Tools + Options, Projects and Solutions, Build and Run, "maximum number of parallel project builds" setting.
But don't do that, parallel builds can be a huge time saver. You fix this kind of problem by setting project dependencies explicitly. Right-click the project that uses the generated C++ files in the Solution Explorer window and click Project Dependencies. Tick the check box for the project that produces the C++ files. In case it is relevant to other readers, check this answer for a way to create a project that only does the custom build step and nothing else.
Visual Studio 2008 by default executes custom build tools first. The order can be changed via right click menu on project with command "Tool Build Order". This facility is not available in Visual Studio 2010. I do not know of a work-around.
Consider using Visual Studio 2010's "Properties >> Configuration Properties >> Build Events >> Pre-Build Event" as the place where you should issue command(s) to build source files that must be compiled first. In the Command Line field, call upon the cl.exe compiler or use a small external makefile to compile those files. Visual Studio will then compile the rest of your project following this initial step.
I resolved my problem when I noticed that my custom build step runs for only one file at a time. It runs for the next file on the next build etc.
The reason apparently is that my custom build steps are calling a batch file and VS2010 creates one temporary batch file to execute all custom build files.
The solution was pointed in this discussion:
http://social.msdn.microsoft.com/Forums/en-HK/msbuild/thread/ca392036-ebdb-4812-930e-f90aa445cca5
It is simply to prefix all calls to batch files with a "call" statement, thus not terminating the execution of the master batch file prematurely.

Will VS2008 puke if I add extra "non standard" targets to a .csproj file?

Will Visual Studio choke on customized .csproj files?
For example, I wanted to add a Target to update the version number in all AssemblyInfo.cs files. I plan to invoke this from the command line with MSbuild.
As another example, I would like to include the build timestamp into the compile, like so. This would be a pre-compile step (I guess), and unlike the example above, this one would run from within a build inside Visual Studio.
Will VS be ok with this?
As long as the code is a valid MSBuild extension, Visual Studio should be able to handle it. Under the hood the project files are really just MSBuild files and MSBuild does the dirty work of the VS build system. So as long as the file remains a valid MSBuild file it should be just fine.
Yes it does allow customizations. We integrated FxCop with our release-mode builds this way.
It will complain when you first load the project file after it's been edited, saying "it's been tampered with, do you wish to continue loading?" Just hit yes and continue on your merry way. It also lets you check a box to ignore the rest of the projects in the solution for the same warning.

Is there a Visual Studio C# equivalent of the Visual Studio C++ Makefile project

In Visual C++ inside Visual Studio, one of the project subtypes is a "Makefile Project".
But there doesn't seem to be an equivalent for Visual C# inside Visual Studio?
BTW, a Makefile project is:
If you have a project that you build from the command line with a
makefile, then the Visual Studio development environment will not
recognize your project. To open and build your project using Visual
Studio, first create an empty project containing the appropriate build
settings using the Makefile Project Wizard. You can then use this
project to build your project from the Visual Studio development
environment.
The project displays no files in Solution Explorer. The project
specifies the build settings, which are reflected in the project's
property page.
The equivalent of make in Visual Studio world is msbuild. Visual Studio does not use make. .csproj, .vbproj etc. are input files for msbuild. You can do pretty much the same stuff in them as in conventional makefiles, including command line building, custom targets etc.
There's nothing C++-specific about the Makefile project type; it just runs a command line. It's just that it's listed along with the Visual C++ project types. You can add one to a solution that otherwise contains nothing but C# projects.
Alternatively, you could set up a pre-build step in your C# project that directly runs nmake, msbuild or even NAnt.
Msbuild is what is used to build your projects when you hit the Play button. Personally I like NAnt + NantContrib it was easier for me to pick up and start using right away. For all new projects I use tree surgeon this tool creates a default build script and proper build tree with testing project and code coverage report.

Resources