Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Visual C++ property sheets using CMake

I'm currently porting a gcc project to Visual C++. It's defined in a CMake file, and I have created a Visual C++ property sheet to aid in compatibility (GccCompat.props). Everytime the Visual C++ project files are regenerated by CMake, the property sheet has to be added manually, since I don't know how to add it automatically. So, the question is:

How can I tell CMake to add a property sheet to the generated Visual C++ solution?

like image 810
OregonGhost Avatar asked Jun 04 '10 10:06

OregonGhost


People also ask

Can you use CMake with C#?

CMake learned to support CSharp (C#) as a first-class language that can be enabled via the project() and enable_language() commands. It is currently supported by the Visual Studio Generators for VS 2010 and above.

How do I add a .props file to Visual Studio?

right click on the project that you want to add a . props file for and choose "Add Existing Property Sheet". You can also choose to add a new property sheet.


2 Answers

This functionality has made it into the nightly build of CMake (https://gitlab.kitware.com/cmake/cmake/commit/e390991846825799e619e072a28f1da58b7c89ba), although not into a stable release yet. Theoretically, it will be in the next release, and CMake releases are made relatively frequently.

To use, you would set the VS_USER_PROPS property on a target. Eg. set_target_properties(foo PROPERTIES VS_USER_PROPS "${props_file}").

However, it doesn't appear that you can use multiple property sheets with this option, and, it replaces the default user property file ($(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props). To workaround this, property sheets can include other property sheets, so, you could make a 'master' property sheet which includes any other property sheets that you would like to use (including the default user property sheet).

like image 179
MuertoExcobito Avatar answered Oct 03 '22 04:10

MuertoExcobito


This question is a little bit old but I have recently stumbled upon the same problem while integrating GStreamer into my project. GStreamer comes with a set of extremely well prepared and high quality Property Sheets and I wanted to use them instead of hacking things around in CMake.

Fortunately, this issue is only limited to Windows and Visual Studio. So here's my solution:

The idea is to use Visual Studio's .user file feature. CMake does not generate this file so it's pretty safe to generate it at configure-time. At configure time you may generate a file that has the EXACT name as your project file but ends with a .user extension.

Partial Solution:

If your project file is named my_project.vcxproj, you need to create another file next to it called my_project.vcxproj.user. According to MSDN:

A user file (.vcxproj.user) stores user-specific properties, for example, debugging and deployment settings. The vcxproj.user file applies to all projects for a particular user.

The contents of this file for importing property sheets is something like this:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="/path/to/sheet1.props" />
  <Import Project="/path/to/sheet2.props" />
</Project>

Not flawless, but works until CMake starts supporting property sheets. The file can be created by using CMake's file command at configure-time.

Potential Caveat:

I have noticed when I add property sheets this way, sometimes they do not show in the Property Manager window (might be a bug in Visual Studio Community 2013) but they always are imported properly and dependencies are resolved correctly.

like image 38
Sepehr Avatar answered Oct 03 '22 04:10

Sepehr