[CMake] Visual Studio source control binding

wedekind wedekind at caesar.de
Wed Feb 28 04:19:31 EST 2007


Hello all,

recently, I have added source control bindings to the Visual Studio
generator of my cvs-copy of cmake. Now I am able to bind my cmake-generated
VS project files to our source control system perforce. Which is quite
convenient, since I do not have to switch from VS to my perforce client and
search for the files I want to edit, check them out and go back to VS to
actually edit them. The source control integration automatically checks it
out when I'm editing the file.

Since I'm not so familiar with cmake development, I just want to propose my
solution to you. I would be glad about your comments, especially about how
to submit my changes, if you should approve them.

Here is how I have done it:

CMake already provided the VS_KEYWORD which can be set via
SET_TARGET_PROPERTIES. I have added three new target properties to configure
source control bindings: VS_SCCPROJECTNAME, VS_SCCLOCALPATH and
VS_SCCPROVIDER. They are read from a target in
cmLocalVisualStudio7Generator::WriteProjectStart(...) and added to the
generated project file like this:

cmLocalVisualStudio7Generator::WriteProjectStart(...)
{

...

  const char* keyword = target.GetProperty("VS_KEYWORD");
  if(!keyword)
    {
    keyword = "Win32Proj";
    }
  const char* vs_projectname = target.GetProperty("VS_SCCPROJECTNAME");
  if (!vs_projectname)
  {
   vs_projectname = "";
  }
  const char* vs_localpath = target.GetProperty("VS_SCCLOCALPATH");
  if (!vs_localpath)
  {
   vs_localpath = "";
  }
  const char* vs_provider = target.GetProperty("VS_SCCPROVIDER");
  std::string providerString;
  if (!vs_provider)
  {
   providerString = "";
  }
  else
  {
   providerString = "\tSccProvider=\"" + std::string(vs_provider) + "\"\n";
  }

...

  fout << "\tSccProjectName=\"" << vs_projectname << "\"\n"
       << "\tSccLocalPath=\"" << vs_localpath << "\"\n"
       << providerString
       << "\tKeyword=\"" << keyword << "\">\n"
       << "\t<Platforms>\n"
       << "\t\t<Platform\n\t\t\tName=\"" << this->PlatformName << "\"/>\n"
       << "\t</Platforms>\n";
}

To configure perforce source control bindings in your CMakeLists.txt, you
just add the target properties like this:

SET_TARGET_PROPERTIES(someTarget PROPERTIES
  VS_SCCPROJECTNAME "Perforce Project"
  VS_SCCLOCALPATH   "..\\.."
  VS_SCCPROVIDER    "MSSCCI:Perforce SCM"
)

Please note that you should use VS_SCCLOCALPATH to enter the relative path
to the first common root-directory of your project-file and the source code
files that are managed by the project file. This is important for
out-of-source builds like in this example:

<rootpath>/path/to/the/sources
<rootpath>/path/to/solution

==> VS_SCCLOCALPATH is "..\\..\\.."


Cheers

Marco




More information about the CMake mailing list