Throughout my code base I have this re-ocurring pattern to provide friendly Visual Studio Support.
# Add CMakeLists.txt so it shows up in Visual Studio generated projects
I even do this for my custom modules:
# Add modules so they shows up in Visual Studio generated projects
Is there an easy, good, fast way to do this? Adding them manually as shown above does work but is tedious and error prone.
I tried globbing but our project is pretty big and that adds 10 seconds to the configuration time.
I think how you’ve described it is how I’d do it. If you wrapped
add_library, you could probably do this in such a wrapper.
FWIW, you don’t have to add them extra via
target_sources. You can just list them directly in the
add_executable command. All our projects at work do it this way, and it works just fine.
Interesting, we do not add them but they are automagically added to the targets in the generated Visual Studio solution. But I guess it only works when you define a target in a CMakeLists.txt.
CMakeLists.txt for a target should be added automatically, but this is only the one for the directory owning the
add_executable call. If you gather sources in subdirectories or have helper files, they’d need manually listed.