Starting with CMake 3.8 , CMake now fully supports C # as a language if you build with Visual Studio 2010 or later. Now you can relatively easily create assemblies or executable targets in C #. Here is a complete example for a simple WinForm C # application:
cmake_minimum_required(VERSION 3.8) project(TestApp LANGUAGES CSharp) # Include CMake utilities for CSharp, for WinForm and WPF application support. include(CSharpUtilities) # Define the executable, including any .cs files. The .resx and other Properties files are optional here, but including them makes them visible in the VS solution for easy editing. add_executable(${PROJECT_NAME} App.config Form1.cs Form1.Designer.cs Form1.resx Program.cs Properties/AssemblyInfo.cs Properties/Resources.Designer.cs Properties/Resources.resx Properties/Settings.Designer.cs Properties/Settings.settings ) # Set the .NET Framework version for the executable. set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1") # Set the executable to be 32-bit. set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE TRUE) # Set the C# language version (defaults to 3.0). set(CMAKE_CSharp_FLAGS "/langversion:latest") # Set the source file properties for Windows Forms use. csharp_set_windows_forms_properties( Form1.cs Form1.Designer.cs Form1.resx Program.cs Properties/AssemblyInfo.cs Properties/Resources.Designer.cs Properties/Resources.resx Properties/Settings.Designer.cs Properties/Settings.settings ) # Add in the .NET reference libraries. set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES "Microsoft.CSharp" "System" "System.Core" "System.Data" "System.Deployment" "System.Drawing" "System.Net.Http" "System.Windows.Forms" "System.Xml" "System.Xml.Linq" )
For assemblies or DLLs, simply use add_library instead of add_executable .
source share