如何从CMake隐藏Visual Studio中的目标 [英] How to hide targets in Visual Studio from CMake

查看:128
本文介绍了如何从CMake隐藏Visual Studio中的目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用CMake生成.sln. 我想使用Google Test并使用这种代码添加新的测试:

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)

它工作正常,但是当我打开.sln时,所有目标都出现在解决方案资源管理器中:库,单元测试等.

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?

推荐答案

在cmake(ATM)中,您不能显式地仅执行此操作,但这是一种如何隐藏更多目标的方法高效:只需将它们放在同一文件夹"中(在cmake中),然后隐藏该文件夹(在Visual Studio中).

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).

假定您有要隐藏在Visual Studio中的名为Mm,Nn和Pp的cmake目标.您需要说出要允许文件夹"的位置,然后只需设置属性称为文件夹

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)

,然后右键单击解决方案中的文件夹nameOfTheFolder隐藏文件夹.

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

如果要再次查看隐藏的文件夹,请右键单击解决方案,然后单击取消隐藏文件夹(至少在Visual Studio 2010中是这样)

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)

这篇关于如何从CMake隐藏Visual Studio中的目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆