Skip to content

Instantly share code, notes, and snippets.

@h4tr3d
Last active January 21, 2020 14:49
Show Gist options
  • Save h4tr3d/0b610a507ed42faeb3c32e2700fabb13 to your computer and use it in GitHub Desktop.
Save h4tr3d/0b610a507ed42faeb3c32e2700fabb13 to your computer and use it in GitHub Desktop.
Qt Creator: show all project files in stocked CMake plugin in Hackers way

Not a question, just a life-hack :-)

Changes, that allows showing all project files in project view is discarded. Clarification that Project View is not a Project View but Build System View is added to the documentation. So, now there is no way to propagate CMakeProjectManager2 changes to the upstream at all.

But we can still display all files using stock plugin and existing functionality. Just hack it using fake CMAKE_TOOLCHAIN_FILE...

Idea:

  • using file(GLOB_RECURSE ...) scan project tree for files
  • create fake target ALL_PROJECT_FILES with this files
  • put it to the fake toolchain file to avoid modification of the original CMakeLists.txt
  • pass fake toolchain file to the cmake executable via Kit CMake properties...

Solution:

Solution allows to configure globbing expression for scanner per build configuration. Via Kit CMake configuration it can be configured per-kit. Look into Gist for complete instruction.

Screen shot: qtc-all-files-wa.png

It can be extended to allow passing exclude globbing expression. It can be extended in any way :-)

#
# Open QtC :: Tools -> Options, Go to Build & Run page, Switch to the Kits page.
# Select needed Kit and press Change... for CMake Configuration item
# Add Parameter:
# CMAKE_TOOLCHAIN_FILE=/path/to/qtc-scan-all.cmake
#
# If you need real toolchain file, just pass it as:
# CMAKE_TOOLCHAIN_FILE_FORWARD=...
#
# Rescan tree: Build -> Clear CMake Configuration.
#
# There is next configuration parameters (can be pass via -DPARAM=value)
# SCAN_GLOB_EXPR - globbing expression for included files, default: *
# SCAN_DUMMY_PROG - dummy executable for dummy target, default: true (aka /bin/true)
#
if (NOT TARGET ALL_PROJECT_FILES)
set(SCAN_GLOB_EXPR * CACHE STRING "Setup file system scanning pattern to display all needed files, default: *")
set(SCAN_DUMMY_PROG "true" CACHE STRING "Dummy prog for dummy target, default: true")
file(GLOB_RECURSE ALL_RPOJECT_FILES_LIST LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} ${SCAN_GLOB_EXPR})
add_custom_target(ALL_PROJECT_FILES ${SCAN_DUMMY_PROG} SOURCES ${ALL_RPOJECT_FILES_LIST})
endif()
# Forward real toolchain file
if (CMAKE_TOOLCHAIN_FILE_FORWARD)
include(${CMAKE_TOOLCHAIN_FILE_FORWARD})
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment