CMake and header files in Qt Creator

I’m using CMake as the build system in Qt Creator. One of the reasons is to simply transition of the project to and from CLion which is a nice alternative when it comes to C++ and Qt development.

Another reason to use CMake is the Qt ambition to start using it in Qt 6.

I discovered that when I was using CMake (I’m not very experienced in CMake), the header files in the IDE (Qt Creator) wasn’t showing up properly in the Project’s sidebar. The reasons for this is how you declare your files in the add_executables directive in your CMakeLists.txt file.

If your header files are listed here as in:

add_executable

Then they will appear nicely as part of the project in the sidebar:

headers showing

If you remove them from your CMakeLists.txt add_executable directive, they will be greyed out and moved out as external dependencies but not part of the project. Note that your project will still build just fine.

headers not showing

See the add_executable documentation.

A small bonus: If you’re using Qt Creator and want the CMake documentation as .qch file, get it here. Read more about adding external documentation to Qt Creator.

That’s all folks! :)