簡體   English   中英

使用 CMake(針對 Visual Studio 的 CMake)在同一解決方案中創建 C# 和 C++/CLR 項目

[英]Creating C# and C++/CLR projects in the same solution using CMake (CMake targeting visual studio)

我想使用具有兩個項目的 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# 中創建另一個項目。

有什么辦法可以做到這一點嗎?

您當然可以在同一個 CMake 項目中同時擁有C++/CLI和 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 或更高版本以獲得對 C# 的完整CMake 支持。 此外,您的 C# 示例似乎缺少 CSharp 目標的一些基本 CMake 命令,如本響應所示。 您應該能夠根據需要將這些命令添加到同一CMakeLists.txt文件中,以修改 C# 源文件和 C# 目標文件的屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM