How to hide targets in Visual Studio from CMake
Asked Answered
L

2

8

I am generating a .sln with CMake. I want to use Google Test and use that kind of code for adding a new tests:

add_executable(my_test test/my_test.cpp)
target_link_libraries(my_test gtest gmock_main)
add_test(NAME my_test COMMAND my_test)

It works fine, but when I open my .sln, I have all the targets appearing in the solution explorer: the libraries, the unit tests, etc.

Is there a way to hide these target?

Lissotrichous answered 12/10, 2016 at 18:45 Comment(4)
I am not sure you can hide targets but you can do is group targets.Bonnie
As far as I can tell, there's no way to hide projects in Visual Studio itself, so it's unlikely CMake would help you there. Why is it a problem anyway? I suppose you can always split it up into several solutions, but it seems to me that would just be hassle for no benefit.Lengthwise
It's a problem because some projects include a lot of build targets. GLFW for example includes around 50 build targets, the list in visual studio is not really meant for this many entries as it has no search functionality and scrolling is awkward. It also makes it much more difficult for new users of your project to find the target they actually care about.Gaucherie
Oh, actually my concern is more the CMake > Build Only menu in VS2017 which is much more difficult to navigate. However, I suspect that list does draw from whatever is in the solution explorer, so if you could split that up it would probably clean up both.Gaucherie
A
9

You can't do it explicitly only in cmake (ATM), but here is one way on how can hide multiple targets more efficiently: Simply put them on in the same "folder" (in cmake) and then hide the folder (in visual studio).

Suppose you have cmake targets called Mm,Nn and Pp that you want to hide in Visual Studio. You need to say to cmake to allow "folders" and Simply set the property called FOLDER like so

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_target_properties(Mm Nn Pp PROPERTIES FOLDER nameOfTheFolder)

and then right click on the folder nameOfTheFolderin solution and on hide folder.

If you want to see the hidden folders again, right click on the solution and then Unhide folders (this is at least how it is in visual studio 2010)

Algophobia answered 28/8, 2017 at 11:43 Comment(0)
R
0

If you mean by using CMake, then as far as I know, the answer at the time of this writing is that you can't. At the time of this writing, in CMake itself, this only exists as a feature-request: Proposal: Target property to indicate IDEs shouldn't show it.

Ranie answered 19/3 at 4:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.