Hello @Marcel Pi !
Yes, it is possible to generate Visual Studio 2022 project files from a custom build system that produces a compile_commands.json
file. You can use the CMakeSettings.json
file to configure the Visual Studio project to use the compile_commands.json
file and other settings required by your custom build system.
Here is an example CMakeSettings.json
file that you can use as a starting point:
{
"configurations": [
{
"name": "My Build",
"generator": "Visual Studio 17 2022",
"configurationType": "Debug",
"buildRoot": "${projectDir}/build/${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"variables": [
{
"name": "CMAKE_EXPORT_COMPILE_COMMANDS",
"value": "ON"
},
{
"name": "MY_CUSTOM_BUILD_SYSTEM_FLAG",
"value": "ON"
}
],
"cmakeSettings": {
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.30.30704/bin/Hostx64/x64/cl.exe",
"configurationType": "Debug",
"compilerArgs": ["/Zi", "/MTd", "/Od", "/std:c++17"],
"linkerArgs": ["/debug:fastlink"],
"includePath": ["${workspaceRoot}/include"],
"defines": ["MY_CUSTOM_DEFINE"],
"browse": {
"path": ["${workspaceRoot}/include"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "${workspaceRoot}/build/${name}/compile_commands.json"
}
}
}
]
}
Here, the name
field is the name of the configuration, the generator
field specifies the version of Visual Studio to use, and the configurationType
field specifies whether the configuration is for Debug or Release mode.
The variables
field can be used to specify any additional variables required by your build system, such as flags or paths.
The cmakeSettings
field contains the settings that will be passed to CMake to generate the Visual Studio project files. Here, we are setting the path to the Visual C++ compiler (compilerPath
), the compiler and linker arguments (compilerArgs
and linkerArgs
), the include path (includePath
), and the preprocessor definitions (defines
).
Finally, the browse
field specifies the path to the compile_commands.json
file and the additional paths to search for header files.
Once you have created the CMakeSettings.json
file, you can open the folder in Visual Studio 2022 and select the configuration you created in the dropdown menu at the top of the IDE. You should then be able to build and debug your project as usual.
ALSO here is a relevant link :
https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-170
In case this helped kindly mark the answer as Accepted!
BR