[CMake] Add header files to project when there are no cpp files

David Cole david.cole at kitware.com
Tue Aug 28 10:31:35 EDT 2012


On Tue, Aug 28, 2012 at 10:01 AM, David Doria <daviddoria at gmail.com> wrote:
> I have just started using QtCreator. When I open a CMake project in
> QtCreator, all of my cpp files mentioned in the CMakeLists.txt are added to
> the "project". However, my headers (.h) and template implementation (.hpp)
> are not added to the project (I believe this is the same behavior as Visual
> Studio). I have seen this thread:
> http://www.cmake.org/pipermail/cmake/2003-January/003274.html that says you
> can simply add the headers to the add_executable/add_library line:
>
> add_library(MyProject main.cpp MyClass.h MyClass.cpp)
>
> This works fine. However, I have several projects that are "template only"
> (there are no .cpp files), and I essentially only use them as git
> submodules, so there are actually no driver cpp files either (the drivers
> are in the project that includes the submodule). That is, the complete
> directory looks like this:
>
> MyProject/CMakeLists.txt
> MyProject/MyProject.h
>
> Because of this, I can't use add_executable or add_library at all. Is there
> another command that can get CMake to add these files to the project?
>
> Thanks,
>
> David
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


Not sure if it works with QtCreator or not, but you should be able to
add_custom_target and use the SOURCES argument to get "source" files
to show up in the generated project.


More information about the CMake mailing list