forked from holepunchto/sodium-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
241 lines (212 loc) · 4.66 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
cmake_minimum_required(VERSION 3.25)
find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch)
find_package(cmake-napi REQUIRED PATHS node_modules/cmake-napi)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
project(sodium_native C ASM)
fetch_package("github:jedisct1/libsodium#stable" SOURCE_DIR sodium)
include(TestBigEndian)
bare_target(target)
file(COPY_FILE "${sodium}/builds/msvc/version.h" "${sodium}/src/libsodium/include/sodium/version.h")
file(GLOB_RECURSE sodium_headers CONFIGURE_DEPENDS "${sodium}/src/libsodium/**/*.h")
file(GLOB_RECURSE sodium_sources CONFIGURE_DEPENDS "${sodium}/src/libsodium/**/*.c")
file(GLOB_RECURSE sodium_asm_sources CONFIGURE_DEPENDS "${sodium}/src/libsodium/**/*.S")
add_library(sodium OBJECT)
target_sources(
sodium
INTERFACE
${sodium_headers}
PRIVATE
${sodium_sources}
)
target_include_directories(
sodium
INTERFACE
"${sodium}/src/libsodium/include"
PRIVATE
"${sodium}/src/libsodium/include/sodium"
)
if(NOT target MATCHES "win32")
target_compile_options(
sodium
PRIVATE
-fvisibility=hidden
-fno-strict-aliasing
-fwrapv
-flax-vector-conversions
)
endif()
target_compile_definitions(
sodium
PUBLIC
SODIUM_STATIC=1
PRIVATE
_GNU_SOURCE=1
CONFIGURED=1
DEV_MODE=1
HAVE_ATOMIC_OPS=1
HAVE_C11_MEMORY_FENCES=1
HAVE_CET_H=1
HAVE_GCC_MEMORY_FENCES=1
HAVE_INLINE_ASM=1
HAVE_INTTYPES_H=1
HAVE_STDINT_H=1
HAVE_TI_MODE=1
)
if(target MATCHES "darwin|ios")
target_compile_definitions(
sodium
PRIVATE
ASM_HIDE_SYMBOL=.private_extern
TLS=_Thread_local
HAVE_ARC4RANDOM=1
HAVE_ARC4RANDOM_BUF=1
HAVE_CATCHABLE_ABRT=1
HAVE_CATCHABLE_SEGV=1
HAVE_CLOCK_GETTIME=1
HAVE_GETPID=1
HAVE_MADVISE=1
HAVE_MEMSET_S=1
HAVE_MLOCK=1
HAVE_MMAP=1
HAVE_MPROTECT=1
HAVE_NANOSLEEP=1
HAVE_POSIX_MEMALIGN=1
HAVE_PTHREAD=1
HAVE_PTHREAD_PRIO_INHERIT=1
HAVE_RAISE=1
HAVE_SYSCONF=1
HAVE_SYS_MMAN_H=1
HAVE_SYS_PARAM_H=1
HAVE_WEAK_SYMBOLS=1
)
if(NOT target MATCHES "ios")
target_compile_definitions(
sodium
PRIVATE
HAVE_GETENTROPY=1
HAVE_SYS_RANDOM_H=1
)
endif()
endif()
if(target MATCHES "linux")
target_compile_definitions(
sodium
PRIVATE
ASM_HIDE_SYMBOL=.hidden
TLS=_Thread_local
HAVE_CATCHABLE_ABRT=1
HAVE_CATCHABLE_SEGV=1
HAVE_CLOCK_GETTIME=1
HAVE_GETPID=1
HAVE_MADVISE=1
HAVE_MLOCK=1
HAVE_MMAP=1
HAVE_MPROTECT=1
HAVE_NANOSLEEP=1
HAVE_POSIX_MEMALIGN=1
HAVE_PTHREAD_PRIO_INHERIT=1
HAVE_PTHREAD=1
HAVE_RAISE=1
HAVE_SYSCONF=1
HAVE_SYS_AUXV_H=1
HAVE_SYS_MMAN_H=1
HAVE_SYS_PARAM_H=1
HAVE_SYS_RANDOM_H=1
HAVE_WEAK_SYMBOLS=1
)
endif()
if(target MATCHES "win32")
target_compile_definitions(
sodium
PRIVATE
_CRT_SECURE_NO_WARNINGS=1
HAVE_RAISE=1
)
endif()
if(target MATCHES "x64")
target_compile_definitions(
sodium
PRIVATE
HAVE_CPUID=1
HAVE_RDRAND=1
HAVE_EMMINTRIN_H=1 # SSE2
HAVE_PMMINTRIN_H=1 # SSE3
HAVE_TMMINTRIN_H=1 # SSSE3
HAVE_SMMINTRIN_H=1 # SSE4.1
HAVE_WMMINTRIN_H=1 # AES
HAVE_AVXINTRIN_H=1 # AVX
HAVE_AVX2INTRIN_H=1 # AVX2
HAVE_AVX512FINTRIN_H # AVX512F
)
if(NOT target MATCHES "win32")
target_compile_definitions(
sodium
PRIVATE
HAVE_AMD64_ASM=1
HAVE_AVX_ASM=1
)
target_sources(
sodium
PRIVATE
${sodium_asm_sources}
)
endif()
endif()
if(target MATCHES "arm64")
target_compile_definitions(
sodium
PRIVATE
HAVE_ARMCRYPTO=1
)
endif()
test_big_endian(is_big_endian)
if(is_big_endian)
target_compile_definitions(
sodium
PRIVATE
NATIVE_BIG_ENDIAN=1
)
else()
target_compile_definitions(
sodium
PRIVATE
NATIVE_LITTLE_ENDIAN=1
)
endif()
add_bare_module(sodium_native_bare)
target_sources(
${sodium_native_bare}
PRIVATE
binding.c
macros.h
extensions/tweak/tweak.c
extensions/tweak/tweak.h
extensions/pbkdf2/pbkdf2.c
extensions/pbkdf2/pbkdf2.h
)
target_link_libraries(
${sodium_native_bare}
PRIVATE
$<TARGET_OBJECTS:sodium>
PUBLIC
sodium
)
add_napi_module(sodium_native_node)
target_sources(
${sodium_native_node}
PRIVATE
binding.c
macros.h
extensions/tweak/tweak.c
extensions/tweak/tweak.h
extensions/pbkdf2/pbkdf2.c
extensions/pbkdf2/pbkdf2.h
)
target_link_libraries(
${sodium_native_node}
PRIVATE
$<TARGET_OBJECTS:sodium>
PUBLIC
sodium
)