-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
157 lines (149 loc) · 5.85 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
message(STATUS "================== node-nim ==================")
cmake_minimum_required(VERSION 3.12.0)
set(TARGET_NAME node-nim)
project(${TARGET_NAME})
set(CMAKE_CXX_STANDARD 17)
# platform specific settings
if (WIN32)
set(NPX_EXUTABLE "npx.cmd")
set(NPM_EXUTABLE "npm.cmd")
else ()
set(NPX_EXUTABLE "npx")
set(NPM_EXUTABLE "npm")
endif ()
if (UNIX)
if (NOT APPLE)
add_link_options("LINKER:--exclude-libs,ALL" "LINKER:--as-needed")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif ()
add_compile_options(-fvisibility=hidden)
endif ()
if (MSVC)
ADD_COMPILE_OPTIONS(/wd4819)
ADD_COMPILE_OPTIONS("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
ADD_COMPILE_OPTIONS("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Gm- /Zi")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif ()
# get CMAKE_JS variables
if (CONAN_SETTINGS_ARCH STREQUAL "x86")
set(CMAKE_JS_ARCH "ia32")
elseif (CONAN_SETTINGS_ARCH STREQUAL "x86_64")
set(CMAKE_JS_ARCH "x64")
elseif (CONAN_SETTINGS_ARCH STREQUAL "armv8")
set(CMAKE_JS_ARCH "arm64")
endif ()
if (TARGET nim_cpp_wrapper)
execute_process(COMMAND ${NPM_EXUTABLE} install --ignoreDownloadSdk
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_QUIET)
else ()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/.cmake/")
include(PlatformSettings)
include(GetGitRevisionDescription)
execute_process(COMMAND ${NPM_EXUTABLE} install --nimSdkUrl=${NIM_SDK_URL}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_QUIET)
endif ()
execute_process(COMMAND ${NPX_EXUTABLE} cmake-js print-configure -l error -r electron -v 8.5.5 -a ${CMAKE_JS_ARCH}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE CMAKE_JS_CONFIGURE_OUTPUT
RESULT_VARIABLE AA)
string(REPLACE "[" "" CMAKE_JS_CONFIGURE_OUTPUT "${CMAKE_JS_CONFIGURE_OUTPUT}")
string(REPLACE "]" "" CMAKE_JS_CONFIGURE_OUTPUT "${CMAKE_JS_CONFIGURE_OUTPUT}")
string(REPLACE "\n" ";" CMAKE_JS_CONFIGURE_OUTPUT_LIST "${CMAKE_JS_CONFIGURE_OUTPUT}")
foreach (item ${CMAKE_JS_CONFIGURE_OUTPUT_LIST})
string(FIND ${item} "CMAKE_JS_INC" CMAKE_JS_INC_INDEX)
string(FIND ${item} "CMAKE_JS_SRC" CMAKE_JS_SRC_INDEX)
string(FIND ${item} "CMAKE_JS_LIB" CMAKE_JS_LIB_INDEX)
string(FIND ${item} "CMAKE_CXX_FLAGS" CMAKE_CXX_FLAGS_INDEX)
string(FIND ${item} "CMAKE_SHARED_LINKER_FLAGS" CMAKE_SHARED_LINKER_FLAGS_INDEX)
if (NOT CMAKE_JS_INC_INDEX EQUAL -1)
string(REGEX REPLACE "^.*CMAKE_JS_INC=(.*)\'.*" "\\1" CMAKE_JS_INC ${item})
elseif (NOT CMAKE_JS_SRC_INDEX EQUAL -1)
string(REGEX REPLACE "^.*CMAKE_JS_SRC=(.*)\'.*" "\\1" CMAKE_JS_SRC ${item})
elseif (NOT CMAKE_JS_LIB_INDEX EQUAL -1)
string(REGEX REPLACE "^.*CMAKE_JS_LIB=(.*)\'.*" "\\1" CMAKE_JS_LIB ${item})
elseif (NOT CMAKE_CXX_FLAGS_INDEX EQUAL -1)
string(REGEX REPLACE "^.*CMAKE_CXX_FLAGS=(.*)\'.*" "\\1" CMAKE_CXX_FLAGS ${item})
elseif (NOT CMAKE_SHARED_LINKER_FLAGS_INDEX EQUAL -1)
string(REGEX REPLACE "^.*CMAKE_SHARED_LINKER_FLAGS=(.*)\'.*" "\\1" CMAKE_SHARED_LINKER_FLAGS ${item})
endif ()
endforeach ()
message(STATUS "CMAKE_JS_INC ${CMAKE_JS_INC}")
message(STATUS "CMAKE_JS_SRC ${CMAKE_JS_SRC}")
message(STATUS "CMAKE_JS_LIB ${CMAKE_JS_LIB}")
message(STATUS "CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}")
# get NODE_ADDON_API_DIR
add_definitions(-DNAPI_VERSION=4)
execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
message(STATUS "NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}")
# configure project
add_definitions(-DNIM_SDK_DLL_IMPORT -DENABLE_NIM_V1)
file(GLOB_RECURSE NIM_NODE_SOURCE ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp
${CMAKE_CURRENT_LIST_DIR}/src/*.cc
${CMAKE_CURRENT_LIST_DIR}/src/*.c
)
ne_add_library(${TARGET_NAME}
FRAMEWORK OFF
NO_SYMLINKS ON
${NIM_NODE_SOURCE}
${CMAKE_JS_SRC}
)
target_include_directories(${TARGET_NAME} PRIVATE
${NODE_ADDON_API_DIR}
${CMAKE_JS_INC}
${CMAKE_CURRENT_LIST_DIR}/src
)
if (TARGET nim_cpp_wrapper)
# build as subproject of nim
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/nim/api/
${CMAKE_SOURCE_DIR}/nim/nim_defines/
${CMAKE_SOURCE_DIR}/nim_chatroom/api/
${CMAKE_SOURCE_DIR}/nim_chatroom/nim_chatroom_defines/
${CMAKE_SOURCE_DIR}/nim/nim_qchat_defines/
${CMAKE_SOURCE_DIR}/public_defines/
${CMAKE_SOURCE_DIR}/v2
${CMAKE_SOURCE_DIR}/wrapper
)
else ()
# build with sdk package
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/sdk/wrapper
${CMAKE_CURRENT_LIST_DIR}/sdk/include
${CMAKE_CURRENT_LIST_DIR}/sdk/v2
)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/sdk/wrapper)
endif ()
target_link_libraries(${TARGET_NAME}
${CMAKE_JS_LIB}
nim_cpp_wrapper
nim_chatroom_cpp_wrapper
nim_tools_cpp_wrapper
nim_qchat_cpp_wrapper
nim_wrapper_util)
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
if (APPLE)
set_target_properties(${TARGET_NAME}
PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
INSTALL_RPATH "@loader_path")
endif ()
# installation
install(
TARGETS ${TARGET_NAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if (MSVC)
install(FILES $<TARGET_PDB_FILE:${TARGET_NAME}> DESTINATION pdb OPTIONAL)
endif ()