CMakePresets.json: Using (env-)variable in Visual Studio Remote Settings vendor map

754 Views Asked by At

A few weeks ago, we introduced the introduce the cmakepresets.json to our cpp cross platform project, which we code with Visual Studio. The setup was really straight forward and we are able to build and debug our project without any problems.

There is just one thing which is a little bit annoying. I would like to use a variable to secifiy the directory on the remote system. It's defined over the "sourceDir"-tag of the Visual Studio Remote Settings vendor map of the CMakePresets.json. There the HOME enviroment variable is used and the special visual studio variable $ms{projectDirName} which evaluates to the name of the open folder in Visual Studio.

{
  "name": "linux-default",
  "displayName": "Linux Debug",
  "description": "Sets Ninja generator, compilers, build and install directory, debug build type",
  "generator": "Ninja",
  "binaryDir": "${sourceDir}/out/build/${presetName}",
  "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug",
    "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
  },
  "vendor": {
    "microsoft.com/VisualStudioSettings/CMake/1.0": {
      "hostOS": [ "Linux" ]
    },
    "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
     "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
   }
  }
}

I tried to define a enviroment variable with the CMakeLists.txt but I think that the variable isn't in the scope of the CMakePresets.json. Are there any other possibilities to variable define the source directory?

0

There are 0 best solutions below