How to hide targets in Visual Studio from CMake

2019-04-28 15:51发布

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?

1条回答
Lonely孤独者°
2楼-- · 2019-04-28 16:20

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)

查看更多
登录 后发表回答