使用CMake生成C#项目 [英] Generate C# project using CMake

查看:1769
本文介绍了使用CMake生成C#项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows上现有的c ++ CMake代码库中生成c#项目。一些搜索后,我可以找到只有两个项目,为cmake构建自己的csharp编译器:
gdcm 以及 kde

I'm trying to generate c# project within an existing c++ CMake code base on Windows. After some search I could find just two projects that built their own csharp compilers for cmake: gdcm and kde.

我试过两个,不幸的是,第一个没有生成一个c#项目,而是创建了vs c ++项目与cs文件。并且因为为链接器设置了c ++标志,构建总是失败,出现错误。我试验了他们提供的示例项目。我想知道可能是Visual Studio 8 2005生成器的限制吗?

I tried both of them and unfortunately the first one failed to generate a c# project, instead it created vs c++ project with cs files in it. And because of c++ flags set for linker, build always failed with errors. I experimented with the sample project they provided. I'm wondering could be it be a limitation of "Visual Studio 8 2005" generator?

第二个也似乎有希望,但主要针对单声道,所以我也不成功。

The second one also seemed promising, but was primarily aimed for Mono, so I wasn't successful with it either.

有没有人在使用其中一个cmake模块构建c#项目时有正面的经验,或者可能是其他的?

Did anyone have a positive experience with building c# projects using one of those cmake modules or may be something else?

推荐答案

CMake 2.8.9及以上添加 TYPE code> include_external_msproject 如下:

CMake 2.8.9 and up add a TYPE parameter to include_external_msproject like so:

include_external_msproject(
    MyProject MyProject.csproj
    TYPE FAE04EC0-301F-11D3-BF4B-00C04F79EFBC)

这样可以指定项目是C#(上面的魔法GUID),否则事情挣扎( see docs < a>)。

This lets you specify that the project is C# (the magic GUID above), otherwise things struggle (see docs).

您可能仍然希望使用<$ c>其他地方提到的 configure_file $ c> .csproj 文件,以获得正确的路径,除非您直接构建到源代码树中。

You will probably still want to use the configure_file template approach mentioned elsewhere with your .csproj file to get the right paths into it, unless you're building straight into your source tree.

好消息是你可以在 .csproj.template 文件中通配C#文件,如下所示:

The good news is that you can wildcard your C# files in the .csproj.template file like so:

<ItemGroup>
  <Compile Include="${DOS_STYLE_SOURCE_DIR}\**\*.cs" />
</ItemGroup>

您需要在 CMakeLists.txt 将CMake的unix风格的正斜杠路径分隔符转换为Windows风格的反斜杠,否则将编译文件,但它们不会在Visual Studio中显示为项目中的链接:

And you'll need something like this in your CMakeLists.txt to convert CMake's unix-style forwardslash path separators into Windows-style backslashes, otherwise it will compile the files but they won't show up as links in the project in Visual Studio:

FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" DOS_STYLE_SOURCE_DIR)


b $ b

那么它只是:

Then it's just:

CONFIGURE_FILE(MyProject.csproj.template MyProject.csproj)

CMakeLists.txt 中将模板文件配置为真实带有通配符路径的项目文件。

In your CMakeLists.txt to configure the template file into a real project file with the right wildcard path.

HTH。

这篇关于使用CMake生成C#项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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