# Migrating CMakeSettings.json over to CMakePresets.json and integrating with Linux workflow

**URL:** https://discourse.cmake.org/t/migrating-cmakesettings-json-over-to-cmakepresets-json-and-integrating-with-linux-workflow/9092
**Category:** Usage
**Tags:** os:linux, os:windows, comp:msvc
**Created:** [September 26, 2023, 2:10am UTC](https://discourse.cmake.org/t/migrating-cmakesettings-json-over-to-cmakepresets-json-and-integrating-with-linux-workflow/9092 "2023-09-26T02:10:11Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![TryerGit](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tryergit/32/3777_2.png) [@TryerGit](https://discourse.cmake.org/u/TryerGit)
#### Post date: [September 26, 2023, 2:10am UTC](https://discourse.cmake.org/t/migrating-cmakesettings-json-over-to-cmakepresets-json-and-integrating-with-linux-workflow/9092/1 "2023-09-26T02:10:11Z")

</div>

Hello,

According to official Visual Studio docs (see [here](https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-170)), they recommend not using `CMakeSettings.json` but use `CMakePresets.json`.going forward. Visual Studio IDE (VSIDE) continues to support `CMakeSettings.json` as of now.

My `CMakeSettings.json` currently is:

```auto
{
  "configurations": [
    {
      "name": "x64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": ["msvc_x64_x64"],
      "buildRoot": "${projectDir}\\cmake\\windows\\build\\${name}",
      "installRoot": "${projectDir}\\cmake\\windows\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "",
      "ctestCommandArgs": ""
    },
    {
      "name": "x64-Release",
      "generator": "Ninja",
      "configurationType": "Release",
      "inheritEnvironments": ["msvc_x64_x64"],
      "buildRoot": "${projectDir}\\cmake\\windows\\build\\${name}",
      "installRoot": "${projectDir}\\cmake\\windows\\install\\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "",
      "ctestCommandArgs": ""
    }
  ]
}

```

So, automatically, on Windows, VSIDE reads this file and uses the information to build the artefacts and the executables to:

`${projectDir}\cmake\windows\build\x64-Debug"` and `${projectDir}\cmake\windows\build\x64-Release"` depending on whether the Debug or the Release configuration is chosen.

On Linux, for the same project, I use VSCode and within that I do not make use of any extensions nor do I use `CMakePresets.json`. Natively, I have a `tasks.json` file which builds CMake projects like so:

```auto
"tasks": [
        {
            "label": "cmakelindbgbuild",
            "type": "shell",
            "command": "cmake -S . -B ./cmake/linux/dbg -DCMAKE_BUILD_TYPE=Debug; cmake --build ./cmake/linux/dbg",
            "group": "build",
         ...
        },
        {
            "label": "cmakelinrelbuild",
            "type": "shell",
            "command": "cmake -S . -B ./cmake/linux/rel -DCMAKE_BUILD_TYPE=Release; cmake --build ./cmake/linux/rel",
            "group": "build",
         ...
        }
    ]

```

That is, I essentially use CMake command line arguments (via a command in `tasks.json`) to build on Linux. So, from within VSCode on Linux, when this task command is run – either `cmakelindbgbuild` or `cmakelinrelbuild` – the artefacts and the executables go into:

`${projectDir}\cmake\linux\dbg"` and `${projectDir}\cmake\linux\rel"` respectively. So, I have clear separation of the builds and executable residing in separate folders under `${projectDir}\cmake\` and the Linux builds do not overwrite/interfere with the Windows builds nor vice versa.

I would like to continue using the current Linux workflow (where there is no dependence of my build on `CMakePresets.json`) but would like my Windows VSIDE to use `CMakePresets.json` instead of `CMakeSettings.json`. My specific questions are:

(1) How can I specify in the new `CMakePresets.json` that the configurations stored in that file should only apply to Windows? I notice that there is no `if(WIN32)` or `if(UNIX)` in the example provided in official CMake documentation [here](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) So, how will VSIDE know which configurations are relevant to the Windows build?

(2) Would the following `CMakePresets.json` work in Windows? I notice that the format of `CMakePresets.json` is different from the format of `CMakeSettings.json` – so I have tried to come up with the closest equivalent I could gather from online searches.

```auto
{
  "configurePresets": [
    {
      "name": "x64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",//Is this valid? If not, how can I convey equivalent information to VSIDE?
      "inheritEnvironments": ["msvc_x64_x64"],//Is this valid? If not, how can I convey equivalent information to VSIDE?
      "binaryDir": "${sourceDir}/cmake/windows/build/${name}",
      "installDir": "${sourceDir}/cmake/windows/install${name}",
      "cmakeCommandArgs": "",//is this valid? If not, how can I convey equivalent information to VSIDE?
      "buildCommandArgs": "",//is this valid? If not, how can I convey equivalent information to VSIDE?
      "ctestCommandArgs": ""//is this valid? If not, how can I convey equivalent information to VSIDE?
    }
  ]
}

```

Is this a valid `CMakePresets.json` file that would work on Windows VSIDE?

(3) Given that I am not using `CMakePresets.json` to build on Linux (as specified before, I directly run an appropriate command in `tasks.json`), would the presence of the above `CMakePresets.json` in the root folder cause any trouble/undefined behavior with executing the command in `tasks.json`?

Thank you for your support.
