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

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

问题描述

我试图生成一个现有的C ++在Windows上CMa​​ke的code群中C#项目。一些搜索后,我能找到的只有两个是建有自己的csharp的编译器cmake的项目:
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 2005年8发生器?

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和高达添加键入参数 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以上),否则奋斗的东西(的看到文档)。

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

您可能仍然想使用你的 .csproj的其他文件中提到的 configure_file 模板方法来获得正确的路径进入,除非你正在构建直接进入你的源代码树。

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.

好消息是,你可以在通配符的C#文件中的 .csproj.template 文件,像这样:

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风格的forwardslash路径分隔符转换为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)

然后,它只是:

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.

心连心。

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

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