-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
192 lines (173 loc) · 6.48 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0042 NEW)
project("nt_native")
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
message("VCPKG_ROOT: " ${VCPKG_ROOT})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CXX_STANDARD 17)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(PKG_TOOL pnpm)
set(TARGET_ARCH x64)
if(MSVC)
set(VCPKG_TARGET_TRIPLET x64-windows-static)
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
endif()
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
include("${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
message("LD_LIBRARY_PATH:" ${LD_LIBRARY_PATH})
find_package(unofficial-sqlite3 CONFIG REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
find_package(SqliteOrm CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_program(PNPM_EXECUTABLE pnpm)
if(NOT PNPM_EXECUTABLE)
message(FATAL_ERROR "pnpm not found!")
endif()
if(WIN32)
set(PNPM_EXECUTABLE "${PNPM_EXECUTABLE}.CMD")
endif()
# message("安装 Node 包")
# execute_process(COMMAND
# ${PKG_TOOL} install
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
# )
message("CMAKE_CXX_FLAGS:${CMAKE_CXX_FLAGS}")
message("获取 cmake-js 配置")
message(${PROJECT_SOURCE_DIR})
execute_process(COMMAND
${PNPM_EXECUTABLE} --silent cmake-js --version
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CMAKE_JS_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND
${PNPM_EXECUTABLE} cmake-js print-cmakejs-src --arch ${TARGET_ARCH} --silent -l error
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CMAKE_JS_SRC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("获取 CMAKE_JS_SRC 配置: ${CMAKE_JS_SRC}")
message("PNPM_EXECUTABLE: " ${PNPM_EXECUTABLE})
execute_process(COMMAND
${PNPM_EXECUTABLE} cmake-js print-cmakejs-include --silent -l error
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CMAKE_JS_INC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# string(REPLACE ";" "\;" CMAKE_JS_INC "${CMAKE_JS_INC}")
message("CMAKE_JS_INC:" ${CMAKE_JS_INC})
foreach(item IN LISTS CMAKE_JS_INC)
message("include: ${item}")
include_directories(${item})
endforeach()
message("获取 node-addon-api 配置")
execute_process(COMMAND
node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("node-addon-api 路径:${NODE_ADDON_API_DIR}")
message("CMAKE_JS_INC: " ${CMAKE_JS_INC})
message("CMAKE_JS_SRC: " ${CMAKE_JS_SRC})
message("CMAKE_JS_LIB: " ${CMAKE_JS_LIB})
include_directories(${CMAKE_JS_SRC})
include_directories(${NODE_ADDON_API_DIR})
set(SUBHOOK_TESTS OFF)
set(SUBHOOK_STATIC ON)
set(SUBHOOK_INSTALL OFF)
add_subdirectory(thirds/subhook)
set(MODULE_NAME nt_native)
add_library(${MODULE_NAME}
SHARED
src/include/sqlite3/official/sqlite3.hh
src/include/convert.hh
src/include/hook.hh
src/include/linux_hook.hh
src/include/windows_hook.hh
src/include/db/group_msg_table.hh
src/include/disasm.hh
src/proto/message.pb.h
src/main.cc
src/hook/hook.cc
src/hook/linux_hook.cc
src/hook/windows_hook.cc
src/proto/message.pb.cc
src/db/group_msg_table.cc
src/proto/communication.pb.cc
src/disasm/custom_disasm.cc
src/yui/hosts.cc
src/yui/stmt.cc
src/yui/msf_task.cc
src/yui/msf_worker.cc
src/yui/convert.cc
src/install/hook_hosts.cc
src/install/hook_msf.cc
src/install/hook_stmt.cc
src/include/db/model/group_msg_table.hh
${CMAKE_JS_SRC}
)
if (WIN32)
message("生成 QQ.lib")
execute_process(COMMAND
${CMAKE_AR} /def:QQ.def /out:QQ.lib /machine:x86 ${CMAKE_STATIC_LINKER_FLAGS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/thirds/external
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(COMMAND
${CMAKE_AR} /def:QQ64.def /out:QQ64.lib /machine:x64 ${CMAKE_STATIC_LINKER_FLAGS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/thirds/external
COMMAND_ERROR_IS_FATAL ANY
)
target_link_libraries(${MODULE_NAME} ${PROJECT_SOURCE_DIR}/thirds/external/QQ.lib)
target_link_libraries(${MODULE_NAME} ${PROJECT_SOURCE_DIR}/thirds/external/QQ64.lib)
endif()
# target_link_libraries(${MODULE_NAME} PRIVATE unofficial::sqlite3::sqlite3)
if (WIN32)
target_link_libraries(${MODULE_NAME} subhook)
target_link_libraries(${MODULE_NAME} protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
target_link_libraries(${MODULE_NAME} sqlite_orm::sqlite_orm)
target_link_libraries(${MODULE_NAME} spdlog::spdlog)
else()
target_link_libraries(${MODULE_NAME} PRIVATE subhook)
target_link_libraries(${MODULE_NAME} PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
target_link_libraries(${MODULE_NAME} PRIVATE sqlite_orm::sqlite_orm)
target_link_libraries(${MODULE_NAME} PRIVATE spdlog::spdlog)
endif()
target_link_libraries(${MODULE_NAME} ${CMAKE_JS_LIB})
target_compile_definitions(${MODULE_NAME} PRIVATE $<$<CONFIG:Debug>:NATIVE_DEBUG=1> $<$<CONFIG:Debug>:SQLITE_DEBUG>)
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
################test##################
add_executable(test_sqlite
test/test_sqlite3.cc
)
target_link_libraries(test_sqlite PRIVATE unofficial::sqlite3::sqlite3)
# target_link_libraries(test_sqlite PRIVATE sqlite3)
add_executable(test_protobuf
test/test_protobuf.cc
./src/proto/communication.pb.cc
)
target_link_libraries(test_protobuf PRIVATE spdlog::spdlog)
target_link_libraries(test_protobuf PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
add_executable(test_orm
test/test_orm.cc
src/hook/hook.cc
src/hook/linux_hook.cc
src/yui/stmt.cc
src/db/group_msg_table.cc
src/proto/message.pb.cc
)
# target_link_libraries(test_sqlite PRIVATE unofficial::sqlite3::sqlite3)
target_link_libraries(test_orm PRIVATE sqlite_orm::sqlite_orm)
target_link_libraries(test_orm PRIVATE subhook)
target_link_libraries(test_orm PRIVATE spdlog::spdlog)
target_link_libraries(test_orm PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite)
add_executable(test
test/test.cc
)