我想使用 CMake 在 MSVC 中创建一个解决方案,该解决方案具有两个项目(在 CMake 词汇中,一个 C# 执行程序和一个 C++/CLR 库)。
我怎样才能做到这一点?我发现的所有示例都是关于 CMake 中的一种类型的项目(全部为 C++ 或 C#)。
澄清:
如果我想使用 CMake 创建一个 C++/CLR 项目,我可以编写如下代码:
cmake_minimum_required (VERSION 3.5)
project (TestCppClr)
if (NOT MSVC)
message(FATAL_ERROR "This CMake files only wirks with MSVC.")
endif(NOT MSVC)
ADD_EXECUTABLE(testCppClr "${CMAKE_SOURCE_DIR}/main.cpp")
set_target_properties(testCppClr PROPERTIES COMMON_LANGUAGE_RUNTIME "")
如果我想创建一个针对 C# 的项目,我可以编写如下内容:
cmake_minimum_required (VERSION 3.5)
project(Example VERSION 0.1.0 LANGUAGES CSharp)
if (NOT MSVC)
message(FATAL_ERROR "This CMake files only wirks with MSVC.")
endif(NOT MSVC)
add_executable(Example
App.config
App.xaml
App.xaml.cs
MainWindow.xaml
MainWindow.xaml.cs
Properties/AssemblyInfo.cs
Properties/Resources.Designer.cs
Properties/Resources.resx
Properties/Settings.Designer.cs
Properties/Settings.settings)
我找不到任何方法来组合这两个 CMake 文件,因此我可以在 C++/CLR 中创建一个可执行文件,并在 C# 中创建另一个项目。
有什么办法可以做到这一点吗?
你当然可以两者兼得C++/CLI和 C# 在同一个 CMake 项目中 - 只需在调用时启用两种语言(C++ 和 C#)project()
.
cmake_minimum_required (VERSION 3.5)
# Enable both C++ and C# languages.
project (TestCSharpAndCppClr VERSION 0.1.0 LANGUAGES CXX CSharp)
if(NOT MSVC)
message(FATAL_ERROR "This CMake files only works with MSVC.")
endif(NOT MSVC)
# Create your C++/CLI executable, and modify its properties.
add_executable(testCppClr "${CMAKE_SOURCE_DIR}/main.cpp")
set_target_properties(testCppClr PROPERTIES COMMON_LANGUAGE_RUNTIME "")
# Create your C# executable.
add_executable(Example
App.config
App.xaml
App.xaml.cs
MainWindow.xaml
MainWindow.xaml.cs
Properties/AssemblyInfo.cs
Properties/Resources.Designer.cs
Properties/Resources.resx
Properties/Settings.Designer.cs
Properties/Settings.settings)
请注意,您应该使用 CMake 3.8 或更高版本才能获得fullCMake 对 C# 的支持。此外,您的 C# 示例似乎缺少 CSharp 目标的一些基本 CMake 命令,如此所示response。您应该能够根据需要将这些命令添加到相同的CMakeLists.txt
文件来修改 C# 源文件和 C# 目标的属性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)