-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathCMakeLists.txt
75 lines (62 loc) · 2.27 KB
/
CMakeLists.txt
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
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0042 NEW)
set(CMAKE_JS_VERSION "7.3.0")
set(CMAKE_JS_INC
"${CMAKE_CURRENT_LIST_DIR}/node_modules/node-api-headers/include;${CMAKE_CURRENT_LIST_DIR}/node_modules/node-addon-api"
)
if(WIN32)
set(CMAKE_JS_SRC "${CMAKE_CURRENT_LIST_DIR}/node_modules/cmake-js/lib/cpp/win_delay_load_hook.cc")
endif()
set(NODE_RUNTIME "node")
set(NODE_RUNTIMEVERSION "20.11.1")
# set(NODE_ARCH "x64")
if(WIN32)
set(CMAKE_JS_LIB "${CMAKE_BINARY_DIR}/node.lib")
set(CMAKE_JS_NODELIB_DEF "${CMAKE_CURRENT_LIST_DIR}/node_modules/node-api-headers/def/node_api.def")
set(CMAKE_JS_NODELIB_TARGET ${CMAKE_JS_LIB})
endif()
if(WIN32)
set(CMAKE_SHARED_LINKER_FLAGS "/delayload:node.exe")
link_libraries(delayimp)
elseif(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
endif()
add_definitions(-DNAPI_VERSION=8)
add_definitions(-DNODE_API_NO_EXTERNAL_BUFFERS_ALLOWED)
include_directories(${CMAKE_JS_INC})
set(maa_node_src
src/main.cpp
src/utility/utility.cpp
src/instance/context.cpp
src/instance/controller.cpp
src/instance/resource.cpp
src/instance/tasker.cpp
src/toolkit/config.cpp
src/toolkit/find.cpp
src/toolkit/pi.cpp)
add_library(MaaNode SHARED ${maa_node_src} ${CMAKE_JS_SRC})
set_target_properties(MaaNode PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(MaaNode ${CMAKE_JS_LIB} MaaFramework MaaToolkit)
target_compile_definitions(MaaNode PRIVATE NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS)
if(WIN32
AND CMAKE_JS_NODELIB_DEF
AND CMAKE_JS_NODELIB_TARGET)
# Generate node.lib
if(MSVC)
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET}
${CMAKE_STATIC_LINKER_FLAGS})
else()
execute_process(COMMAND ${CMAKE_LINKER} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET}
${CMAKE_STATIC_LINKER_FLAGS})
endif()
endif()
install(
TARGETS MaaNode
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
ARCHIVE DESTINATION lib)
if(WIN32)
install(FILES $<TARGET_PDB_FILE:MaaNode> DESTINATION symbol OPTIONAL)
endif()
# if(WIN32) add_custom_command( TARGET MaaNode POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${MaaDlls}
# $<TARGET_FILE_DIR:MaaNode> COMMAND_EXPAND_LISTS) endif()