PDA

View Full Version : Qt Creator Files with the same prefix as target cpp file automatically get added to project?



daviddoria
22nd December 2015, 19:36
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:


Project(TestProject)
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. I created another header file, MyClass.h, and re-ran CMake and this file was not added to the project (as I originally expected).

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?

Thanks,

David

anda_skoa
22nd December 2015, 19:48
What do you mean with "added to the projcet"?
Did QtCreator modify your CMakeLists.txt and put Test.h into some variable?

Cheers,
_

daviddoria
22nd December 2015, 19:50
I mean that Test.h shows up in the list of files under TestProject in the Projects panel on the left side of the QtCreator window.

David

anda_skoa
23rd December 2015, 09:12
Ah, I see.

My guess would be that cmake scans the source file for dependencies and provides that information in a way that allows QtCreator to use it.

Cheers,
_

daviddoria
23rd December 2015, 13:24
Nope, it's not that. 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.