CSharp实用程序¶
在 3.8 版本加入.
使 CSharp/.NET 目标的配置更容易的功能。
一组 CMake 实用程序函数,可用于处理 2010 版及更高版本的 Visual Studio 生成器的 CSharp 目标。
该模块提供以下功能:
主要功能
辅助函数
模块提供的主要功能¶
- csharp_set_windows_forms_properties¶
设置源文件属性以使用 Windows 窗体。如果您的 CSharp 目标使用 Windows Forms:
csharp_set_windows_forms_properties([<file1> [<file2> [...]]])
<fileN>与设置
VS_CSHARP_<tagname>属性相关的所有源文件列表(包括.cs、.resx和.Designer.cs扩展名)。
在所有给定文件的列表中搜索以“.Designer.cs”和“.resx”结尾的所有文件。对于每个 designer 或 resource 文件,搜索具有相同基本名称但仅扩展名为“.cs”的文件。如果找到,则
VS_CSHARP_<tagname>属性设置如下:- 对于 .cs 文件:
VS_CSHARP_SubType“表单”
- 对于 .Designer.cs 文件(如果存在):
VS_CSHARP_DependentUpon <cs 文件名>
VS_CSHARP_DesignTime ""(如果之前定义过则删除标签)
VS_CSHARP_AutoGen ""(如果之前定义过则删除标签)
- 对于 .resx 文件(如果存在):
VS_RESOURCE_GENERATOR ""(如果之前定义过则删除标签)
VS_CSHARP_DependentUpon <cs 文件名>
VS_CSHARP_SubType“设计师”
- csharp_set_designer_cs_properties¶
根据兄弟文件名设置
.Designer.cs文件的源文件属性。如果您的 CSharp 目标不**不**使用 Windows 窗体(对于 Windows 窗体,请改用csharp_set_designer_cs_properties()),请使用它:csharp_set_designer_cs_properties([<file1> [<file2> [...]]])
<fileN>与设置
VS_CSHARP_<tagname>属性相关的所有源文件列表(包括.cs、.resx、.settings和 ``.Designer.cs `` 扩展)。
在所有给定文件的列表中搜索以“.Designer.cs”结尾的所有文件。对于每个 designer 文件,搜索具有相同基本名称但不同扩展名的所有文件。如果找到匹配项,则根据匹配文件的扩展名设置 designer 文件的源文件属性:
- 如果匹配是 .resx 文件:
VS_CSHARP_AutoGen“真”
VS_CSHARP_DesignTime“真”
VS_CSHARP_DependentUpon <resx 文件名>
- 如果匹配是 .cs 文件:
VS_CSHARP_DependentUpon <cs 文件名>
- 如果匹配是 .settings 文件:
VS_CSHARP_AutoGen“真”
VS_CSHARP_DesignTimeSharedInput "真"
VS_CSHARP_DependentUpon <设置文件名>
备注
因为 .Designer.cs 文件的源文件属性是根据找到的匹配项设置的,并且每个匹配项都设置 VS_CSHARP_DependentUpon 属性,所以每个 Designer.cs 应该只有一个匹配项文件。
- csharp_set_xaml_cs_properties¶
设置源文件属性以使用 Windows Presentation Foundation (WPF) 和 XAML。如果您的 CSharp 目标使用 WPF/XAML::,请使用它:
csharp_set_xaml_cs_properties([<file1> [<file2> [...]]])
<fileN>与设置
VS_CSHARP_<tagname>属性相关的所有源文件列表(包括.cs、.xaml和.xaml.cs扩展名)。
在所有给定文件的列表中搜索以“.xaml.cs”结尾的所有文件。对于每个 xaml-cs 文件,搜索具有相同基本名称但扩展名为“.xaml”的文件。如果找到匹配项,则设置 .xaml.cs 文件的源文件属性:
VS_CSHARP_DependentUpon <xaml 文件名>
上述函数使用的辅助函数¶
- csharp_get_filename_keys¶
计算键值列表的辅助函数,以独立于 cmake 中给出的相对/绝对路径来识别源文件,并消除区分大小写
csharp_get_filename_keys(OUT [<file1> [<file2> [...]]])
出去存储键列表的变量的名称
<fileN>使用
add_library()或add_executable()提供给 CSharp 目标的文件名
该函数以某种方式对源名称应用规范化。如果文件已添加到具有不同目录前缀的目标,则需要查找文件匹配项:
add_library(lib myfile.cs ${CMAKE_CURRENT_SOURCE_DIR}/myfile.Designer.cs) set_source_files_properties(myfile.Designer.cs PROPERTIES VS_CSHARP_DependentUpon myfile.cs) # this will fail, because in cmake # - ${CMAKE_CURRENT_SOURCE_DIR}/myfile.Designer.cs # - myfile.Designer.cs # are not the same source file. The source file property is not set.
- csharp_get_filename_key_base¶
返回完整的文件路径和名称**不带**密钥扩展名。 KEY 应该是来自 csharp_get_filename_keys 的密钥。在 BASE 中返回不带文件扩展名的 KEY 的值
csharp_get_filename_key_base(BASE KEY)
基础具有“KEY”的计算“基数”的变量名称。
关键将计算其基数的键。应为大写的完整文件名。
- csharp_get_dependentupon_name¶
计算一个字符串,该字符串可用作源文件属性的值
csharp_get_dependentupon_name(NAME FILE)
名字具有结果值的变量名称
文件要转换为
<DependentUpon>值的文件名
实际上这只是文件名,目前没有给出任何路径。