I have a library that is built as part of my CMake-based project. This library has many targets and I am not interested in seeing them appearing in my target list (either under Visual Studio or QtCreator). Is there a way for me to have this library built as part of my project build (kindda like a dependency build) but not seeing the available targets of this library?
There is currently little explicit support for hiding specific targets in these IDEs. CMake does not (yet) support a show/hide targets option. However, there is a way to avoid scrolling through long lists of targets in Visual Studio; you can group your targets with IDEs folders. CMake supports this, by setting the FOLDER
property on specific targets.
First, tell CMake to enable IDE folders by adding this line to your top-level CMakeLists.txt file:
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Then, organize your targets into folders, by setting the FOLDER
property.
# Put these targets in the 'HiddenTargets' folder in the IDE.
set_target_properties(SillyLib1 SillyLib2 DontCareLib1 PROPERTIES FOLDER HiddenTargets)
# Put these targets in the 'AppTools' folder in the IDE.
set_target_properties(WriterLib1 ReaderLib1 AwesomeLib42 PROPERTIES FOLDER AppTools)
Now, your CMake targets will be placed in the HiddenTargets
and AppTools
folders in the Visual Studio Solution Explorer. You can collapse the folders containing targets you don't want to see, or hide the folder altogether (by right-clicking the folder, and selecting Hide Folder). The targets will still be usable (and will be built if necessary), they just won't be visible in the Solution Explorer. You can un-hide hidden folders by right-clicking the solution, and selecting Unhide Folders.
Qt Creator does not support this, to my knowledge. However, in 2017, they addressed a similar request to hide CMake targets. In general, this bug fix (implemented in Qt Creator 4.4.0 and greater) cleaned up the polluted targets view (removed the Source Directory listing), and improved their Hide Generated Files and Hide Empty Folders capabilities, which gave users more control over what is shown/hidden in the project listing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With