0

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?

Lachi1812
  • 1
  • 1
  • This paths is evaluated before cmake even runs. Why would you need something other than `$env{HOME}` or `/some/absolute/path`? – Osyotr Feb 06 '23 at 23:00
  • Sometimes I copy my complete project because I'm working on another issue. Because of our setup, the remote path is identically in both copies. You now have the opportinity to manually change the path or can't open both copies at the same time. – Lachi1812 Feb 07 '23 at 04:45

0 Answers0