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)
本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0 许可协议。转载请注明来自 张拓的博客!