This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
cqcppsdk.cmake
87 lines (79 loc) · 3.41 KB
/
cqcppsdk.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 引用 CMakeLists.txt
add_subdirectory(${CMAKE_CURRENT_LIST_DIR})
get_directory_property(CQ_CAN_BUILD_STD_MODE DIRECTORY ${CMAKE_CURRENT_LIST_DIR} DEFINITION CQ_CAN_BUILD_STD_MODE)
# 设置 app id
macro(cq_set_app_id APP_ID)
message(STATUS "app id: ${APP_ID}")
set(_CQ_APP_ID ${APP_ID})
add_definitions(-D_CQ_APP_ID="${APP_ID}")
endmacro()
# 添加酷Q应用构建目标, 在调用之前设置 CQCPPSDK_DEV_MODE 为 ON 可构建 dev 模式的可执行文件
function(cq_add_app OUT_NAME)
if (CQCPPSDK_DEV_MODE)
# dev 模式, 产生可执行文件, 用于脱离酷Q单独测试业务逻辑, 不限平台
message(STATUS "add dev mode executable: ${OUT_NAME}")
add_executable(${OUT_NAME} ${ARGN})
target_link_libraries(${OUT_NAME} cqcppsdk_dev_mode)
elseif (NOT CQ_CAN_BUILD_STD_MODE)
# 试图构建 std 模式, 但当前工具链无法构建
message(SEND_ERROR "can not build std mode dll with the current toolchain")
else ()
# std 模式, 产生 Windows 动态链接库, 即可被酷Q加载的应用(进而可打包为 CPK)
if (NOT OUT_NAME STREQUAL "app")
message(WARNING "the name of std mode dll is required to be \"app\"")
endif ()
message(STATUS "add std mode dll: ${OUT_NAME}")
add_library(${OUT_NAME} MODULE ${ARGN})
target_link_libraries(${OUT_NAME} cqcppsdk_std_mode)
set_target_properties(${OUT_NAME} PROPERTIES PREFIX "") # 去除 lib 前缀
endif ()
endfunction()
# 添加 std 模式构建目标, 可选参数为源文件列表
function(cq_add_std_app)
set(CQCPPSDK_DEV_MODE OFF)
cq_add_app(app ${ARGN})
endfunction()
# 添加 dev 模式构建目标, 可选参数为源文件列表
function(cq_add_dev_app)
set(CQCPPSDK_DEV_MODE ON)
cq_add_app(app_dev ${ARGN})
endfunction()
# 已弃用
# 添加安装脚本, 将在指定构建目标构建完成后运行, 可用于拷贝 app.dll 和 app.json 到酷Q应用目录
function(cq_add_install_script OUT_NAME INSTALL_SCRIPT)
message(DEPRECATION "cq_add_install_script is deprecated, please use cq_install_std_app instead")
if (EXISTS ${INSTALL_SCRIPT})
add_custom_command(TARGET ${OUT_NAME}
POST_BUILD
COMMAND
powershell -ExecutionPolicy Bypass -NoProfile -File ${INSTALL_SCRIPT} "$<TARGET_FILE_DIR:${OUT_NAME}>")
endif ()
endfunction()
# 安装 std 模式的酷Q应用, 可选参数为酷Q主目录位置列表, 如不传入参数则使用 CMAKE_INSTALL_PREFIX
function(cq_install_std_app)
if (NOT TARGET app)
message(WARNING "std mode target is not defined")
return()
endif ()
macro(_cq_install_std_app PREFIX)
if (PREFIX AND (NOT PREFIX MATCHES ".*[/\\]$"))
set(DESTDIR "${PREFIX}/dev/${_CQ_APP_ID}")
else ()
set(DESTDIR "${PREFIX}dev/${_CQ_APP_ID}")
endif ()
message(STATUS "install destination: ${DESTDIR}")
install(FILES
"$<TARGET_FILE_DIR:app>/app.dll"
"${CMAKE_SOURCE_DIR}/app.json"
DESTINATION ${DESTDIR})
endmacro()
if (ARGC GREATER 0)
# 如果传入了参数, 则安装到参数指定的酷Q位置
foreach (PREFIX IN LISTS ARGN)
_cq_install_std_app(${PREFIX})
endforeach ()
else ()
# 否则安装到 CMAKE_INSTALL_PREFIX 指定的位置
_cq_install_std_app("")
endif ()
endfunction()