cmake配置csharp dll项目

  • Post author:
  • Post category:build
  • Post comments:0评论
cmake_minimum_required(VERSION 3.14)
# 名称 
set(MY_PROJECT_NAME CSharpLib)
# 项目类型
project(${MY_PROJECT_NAME} LANGUAGES CSharp)
# show
message ("cmake:${PROJECT_NAME}")

# debug版本加-d后缀
# set(CMAKE_DEBUG_POSTFIX -d)

# 库目录
set(MY_SOURCE_LIB_DIR "${PROJECT_SOURCE_DIR}/../lib/")

# default Release
if (NOT CMAKE_BUILD_TYPE)
   set (CMAKE_BUILD_TYPE "Release")
   message (
      STATUS "${PROJECT_NAME} no CMAKE_BUILD_TYPE selected, defaulting to ${CMAKE_BUILD_TYPE} "
   )
endif()

# AnyCPU
SET(CMAKE_CSharp_FLAGS "/platform:AnyCPU")

# .net版本
SET(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1")
# cs代码
add_library(${PROJECT_NAME} SHARED
  Properties/AssemblyInfo.cs
  LockscreenWin10.cs
)
# 系统引用
LIST(APPEND VS_DOTNET_REFERENCES "Microsoft.CSharp")
LIST(APPEND VS_DOTNET_REFERENCES "System")
LIST(APPEND VS_DOTNET_REFERENCES "System.Core")
LIST(APPEND VS_DOTNET_REFERENCES "System.Data")
LIST(APPEND VS_DOTNET_REFERENCES "System.Data.DataSetExtensions")
LIST(APPEND VS_DOTNET_REFERENCES "System.Net.Http")
LIST(APPEND VS_DOTNET_REFERENCES "System.Xml")
LIST(APPEND VS_DOTNET_REFERENCES "System.Xml.Linq")
LIST(APPEND VS_DOTNET_REFERENCES "System.Threading.Tasks")
LIST(APPEND VS_DOTNET_REFERENCES "System.IO")
# 
set_target_properties(${PROJECT_NAME} PROPERTIES
    VS_DOTNET_REFERENCES "${VS_DOTNET_REFERENCES}"
    VS_DOTNET_REFERENCE_WindowsRuntime "System.Runtime.WindowsRuntime.dll" # 引用dll
    VS_DOTNET_REFERENCE_Windows "Windows.winmd"
)
# 生成后事件
if (WIN32) 
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD         
    COMMAND ${CMAKE_COMMAND} -E copy_if_different  
    "$<$<CONFIG:Debug>:Debug/${PROJECT_NAME}.dll>"  
    "$<$<CONFIG:Release>:Release/${PROJECT_NAME}.dll>"  
    "../CSharpMiddle/")  
endif() # (WIN32) 
文章作者: 张拓
文章链接: http://www.xssl.online/cmake%e9%85%8d%e7%bd%aecsharp-dll%e9%a1%b9%e7%9b%ae/
版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0 许可协议。转载请注明来自 张拓的博客
浏览次数: 458

张拓

陕西西安蓝田张拓QQ1070410059。一生所求不过“心安”二字。 然,尘世多纷扰。

发表回复