Important: Please read the Qt Code of Conduct -

Files with the same prefix as target cpp file automatically get added to project?

  • I was trying to test some different ways to add headers to a project (add_custom_target, source_group, etc.). To start to test this, I created a folder with my CMakeLists.txt:

    add_executable(Test Test.cpp)

    and two other files, Test.cpp and Test.h. When I opened the CMakeLists.txt file with QtCreator and generated the project, I was suprised to find Test.h was added to the project (shows up in the list of files under TestProject in the Projects panel on the left side of the QtCreator window). I created another header file, MyClass.h, and re-ran CMake and this file was not added to the project (as I originally expected). There was no reference to Test.h in Test.cpp and it does appear in the project, and even when I add a reference (#include "MyClass.h") to MyClass.h, it does not appear in the project.

    Is it the desired behavior for files with the same prefix to be added to the project? Or is there some other explanation of why Test.h would be added to the project without being mentioned in the CMakeLists.txt?



Log in to reply