I suggest you ...

CMake - Automatically Add Sources and Headers to a VAR in a .cmake file

Request:
Auto-generate and maintain a .cmake file for CMake projects which holds nothing but a list of sources and headers as auto-generated variables. This will eliminate the extremely tedious need for developers to add/remove/move files in visual studio, and then manually add/remove/move them in a CMake file.

For example:

SET(my_project_name_SOURCES
<source1.cpp>
<etc...>
)
SET(my_project_name_HEADERS
<source1.h>
<etc...>
)

In Visual Studio projects, when you add a source or header file, it's automatically added to your project files because that's an obvious thing to do. It currently doesn't do this for CMake projects. It's understandable, as doing this automatically and intelligently in Visual Studio seems non-trivial, as the users can layout their CMake targets any number of ways.

However, with this simple approach, developers can include() these predictably named files from their CMakeLists.txt, and then use the variables in their targets via add_library and add_executable.

With CLion, when you add a new source or header file in your project, it asks you if you want to add to CMakeLists.txt. Their implementation is much more robust than the suggestion here, so it may be worth looking at how they implemented it as a reference. However, this simple feature would be a big user-experience win for projects that are adding/removing files frequently.

18 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Gerald Wiltse shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Gerald Wiltse commented  ·   ·  Flag as inappropriate

    I guess there's some new features here, it seems likely VS team and CMake team are working together: https://cmake.org/cmake/help/latest/command/source_group.html

    I think it's still worth voting for this suggestion until source groups are actually implemented in visual studio cmake integration.

    I imagine/hope CMake team is working closely with VS team and Jetbrains Clion teams to make it more amenable and friendly for IDE's.

Feedback and Knowledge Base