arynaq
arynaq

Reputation: 6870

Visual Studio, running cmakesettings.json from the command line

Visual Studio supports creating a CMakeSettings.json file to keep cmake configurations when opening a CMake project, as described here.

This works perfectly well within the IDE itself, but if I want to automate my builds I cannot re-use the same CMakeSettings.json file, I have to either parse it, then send the values to CMake with -DFOO=parsed_value or keep two seperate build configurations (risking the error of them not being in sync).

The IDE must internally do this parsing anyway before it calls CMake so does anyone know if this build step is accessible outside the IDE?

Upvotes: 7

Views: 5765

Answers (3)

markf78
markf78

Reputation: 627

Note that in VS2019, the correct way to do this is to use CMakePresets.json and then you can build in a CI using cmake from the cmd.exe. CMakeSettings.json is deprecated. To enabled support for them, there is an option that needs to be enabled. See this link https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-160 for more information.

Upvotes: 1

Richard Scott
Richard Scott

Reputation: 101

Have a look at the suggestion here to create a settings.cmake which you can use to pre-populate the cache from the command line.

cmake -C <initial-cache>

They suggest a script to export the settings from a build folder to get you started.

I am trying to figure out this too as I would like to have single settings file for commandline, VS2017 and VSCode.

Upvotes: 4

Tim L.
Tim L.

Reputation: 49

This might not be the answer you are looking for and I am not 100% sure, but CMakeSettings.json seems to be exclusive to Visual Studio 2017. I never came across CMakeSettings.json other than in context with VS2017. Even when you do an advanced google search with "CMakeSettings.json" -Visual -Studio -2017, you won't get search results other than finding the filename on repositories in github for example. Searching CMakeSettings.json or CMakeSettings on cmake.org won't fetch any results either.

If parsing works, that might be the way to go.

Upvotes: 1

Related Questions