QtCreator+cmake: list all files in project tree



  • I'm working on a cmake based project (non-Qt) and I want to open and edit the project with the QtCreator. I was able to oben, configure and build the project with QtCreator but now I noticed that not all files are listed in the project tree:
    The CmakeLists.txt files reference only the .cpp files so the QtCreator lists only the named .cpp files and their corresponding .hpp file. There are also several header only implementations which are included in some cpp files but which are not listed in the cmake files so the QtCreator does not show them in the project tree.
    (I did not create this cmake structure so I do not want to discuss if this is a wrong usage of cmake or not).

    My question is: Does anyone know a trick how to list all files in the project tree, regardless whether the files are listed in CMakeLists.txt or not.
    I'm looking for a way without editing / fixing / adjusting all the CMakeLists.txt (e.g. Eclipse/CDT lists all files found in the filesystem and that might be the reason why these cmake files contain no header files).



  • Hi! You can change the view from "Projects" to "File System". Above the treeview, there is a combobox where you can switch between the settings.



  • @Wieland
    I had the same idea but the "file system" view is just a flat view of one directory, not a hierarchical tree view so it's not a useful alternative (in my case)...



  • I found a solution that works for me: Instead of editing all the CMakeLists.txt I can add a dummy target in the top most CMakeLists.txt that collects all header files:

    file(GLOB_RECURSE ALL_SRC_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.hpp")
    file(GLOB_RECURSE ALL_TEST_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Tests/*.hpp")
    add_library(dummy_target_with_all_headers EXCLUDE_FROM_ALL ${ALL_SRC_HEADER_FILES} ${ALL_TEST_HEADER_FILES})
    target_link_libraries(dummy_target_with_all_headers)
    set_target_properties(dummy_target_with_all_headers PROPERTIES LINKER_LANGUAGE CXX)
    

    But I'm still looking for a way to move this target declaration to a separate file and pass this file as an additional command line argument to cmake so I don't have to modify the existing CMakeLists.txt file...



  • Update: QtCreator 4.3 (beta1) lists all header files - regardless whether they are listed in the CMakeLists.txt or not (as long as "hide generated files" is not checked). The previously mentioned dummy target is not required anymore.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.