Does adding `.natvis` files via target_sources work on Ninja?

According to the docs as of CMake 3.7

Visual Studio Generators for VS 2010 and above learned to place .natvis source files into VS project files properly.

Which means the following will work correctly with Visual Studio generators.

target_sources(foobar PRIVATE foobar.natvis)

Will this also work for Ninja on MSVC?

Do I need to guard this with a check for MSVC?

Looking at the code, CMake literally only knows how to tell VS “this is a natvis file”. The IDE then takes that indication to do what is necessary; no other generator knows about it and will just ignore the file.

1 Like