我可以在cmake时间获得CMake为特定vcproj生成的GUID吗? [英] Can I get the GUID generated by CMake for a specific vcproj at cmake time?

查看:226
本文介绍了我可以在cmake时间获得CMake为特定vcproj生成的GUID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前言:我试图将我的C#csproj与我们的其他C ++和C ++ / CLI基于代码的cmake build集成。我收到建议反对尝试这样做,因为CMake不能在Visual Studio中与.NET合作,但在实施一些自定义之后,我觉得我非常接近。



我的部分定制是使用configure_file命令在CMake时间编辑csproj文件,根据正在发生的构建类型(例如x86,x64)进行自定义。



问题是我使用一些ProjectReference标签来引用C ++ / CLI项目:

  ProjectReference Include =.. \..\WrapperProject\WrapperProject.vcproj> 
< Project> {7BD6E175-CDD1-4F8D-A3B2-0AC862E62C03}< / Project>
< Name> WrapperProject< / Name>
< / ProjectReference>

...并且GUID不能保持静态,因为当CMake缓存重建(如果我错误,请更正我)。



所以我想做的是找到我们在CMake时间为这些项目计划什么GUID, vcproj文件。



Google告诉我,人们可以使用'set_property'设置GUID,例如:

  set_property(CACHE $ {target_name} _GUID_CMAKE PROPERTY VALUE $ {MY_GUID})

...但我似乎找不到getter等效。我试过这样的事情:



get_property(WRAPPER_GUID CACHE INTERNAL PROPERTY WrapperTargetName_GUID_CMAKE)



运气。

解决方案

在玩完这些之后,我意识到了Fraser指出的 - 这个方法不会总是工作,因为我不能期望GUID在新的运行CMake可用。所以我去了我已经看到建议在CMake邮件列表,这是显式设置GUID值自己的路由。



所以在CMakeLists.txt每个C + / CLI wrapper项目,我有这样的:

 #为这个项目设置一个全局缓存变量GUID 
# TestAppNet csproj需要此GUID才能正确引用此项目
set_property(GLOBAL PROPERTY Wrapper_GUID1897F4D1-E929-444E-9343-00F094113772)
get_property(projectGUID GLOBAL PROPERTY Wrapper_GUID)
MESSAGE 将项目GUID设置为:$ {projectGUID})
set(Wrapper_GUID_CMAKE$ {projectGUID}CACHE INTERNALProject GUID)

在C#项目CMakeLists.txt中,我有:

  get_property CMAKE_WRAPPER_GUID GLOBAL PROPERTY Wrapper_GUID)
MESSAGE(状态将Wrapper GUID设置为:$ {CMAKE_WRAPPER_GUID})

...然后CMAKE_WRAPPER_GUID用作在configure_file命令期间填充的.csproj文件中的变量。



我不知道这个是高效的,但它似乎工作!


Preamble: I am trying to integrate my C# csproj with the rest of our C++ and C++/CLI code-base cmake build. I have received advise against trying to do this, because CMake doesn't co-operate well with .NET in Visual Studio, but after implementing some customizations, I feel that I am very close.

Part of my customization is using the configure_file command to edit the csproj file at CMake time, to customize it depending on the type of build (e.g. x86, x64) that is happening.

The problem is that I use some ProjectReference tags to reference the C++/CLI projects:

<ProjectReference Include="..\..\WrapperProject\WrapperProject.vcproj">
  <Project>{7BD6E175-CDD1-4F8D-A3B2-0AC862E62C03}</Project>
  <Name>WrapperProject</Name>
</ProjectReference>

... and the GUIDs cannot remain static, since they change for the project whenever the CMake cache is rebuilt (correct me if I'm mistaken).

So what I would like to do is find our at CMake time what GUIDs are planned for these projects and to edit the vcproj file accordingly.

Google tells me that people are able to use 'set_property' to set the GUID, like so:

set_property(CACHE ${target_name}_GUID_CMAKE PROPERTY VALUE ${MY_GUID} )

... but I can't seem to find the getter equivalent. I've tried things like this:

get_property(WRAPPER_GUID CACHE INTERNAL PROPERTY WrapperTargetName_GUID_CMAKE)

... without luck. Your help is appreciated!

解决方案

After playing around with this more, I realized what Fraser pointed out - that this method wouldn't always work because I can't expect the GUIDs to be available on a fresh run of CMake. So I went the route that I had seen suggested on the CMake mailing list, which is to explicitly set the GUID values myself.

So in the CMakeLists.txt for each C++/CLI wrapper project, I have something like this:

# Set a global cache variable for this project GUID
# The TestAppNet csproj needs this GUID to properly reference this project
set_property(GLOBAL PROPERTY Wrapper_GUID "1897F4D1-E929-444E-9343-00F094113772") 
get_property(projectGUID GLOBAL PROPERTY Wrapper_GUID)
MESSAGE( STATUS "Setting project GUID to: ${projectGUID}")
set(Wrapper_GUID_CMAKE "${projectGUID}" CACHE INTERNAL "Project GUID")

And in the C# project CMakeLists.txt, I have this:

get_property(CMAKE_WRAPPER_GUID GLOBAL PROPERTY Wrapper_GUID)
MESSAGE( STATUS "Setting Wrapper GUID to: ${CMAKE_WRAPPER_GUID}" )

... and then the CMAKE_WRAPPER_GUID is used as a variable in the .csproj file that is populated during the configure_file command.

I'm not sure if this is efficient, but it seems to work!

这篇关于我可以在cmake时间获得CMake为特定vcproj生成的GUID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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