'Show compiler command line of CMake with Visual Studio 2019

I am using open folder functionality of VS2019, and I would like to see flags being used to compile my code.

Compilation database does not seem to be generated with my generator(Visual Studio 16 2019 Win64) when I do CMAKE_EXPORT_COMPILE_COMMANDS , also set(VERBOSE ON) does not work.



Solution 1:[1]

I had a similar issue.

You must use $ENV{} syntax to check/access environment variables such as CMAKE_* within CMakeLists.txt. See my https://stackoverflow.com/a/68724763/717355

Solution 2:[2]

CMAKE_EXPORT_COMPILE_COMMANDS option is ignored in VS generator:

This option is implemented only by Makefile Generators and the Ninja. It is ignored on other generators.

See full doc: https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Philip Oakley
Solution 2 Ivan Sidorov