-
Notifications
You must be signed in to change notification settings - Fork 82
/
emscripten.toolchain.cmake
258 lines (231 loc) · 11.9 KB
/
emscripten.toolchain.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#-------------------------------------------------------------------------------
# emscripten.toolchain.cmake
# Fips cmake toolchain file for cross-compiling to emscripten.
#
# The following cmake defines must be passed on the command line:
#
# EMSCRIPTEN_ROOT: absolute path to the directory with emcc and system/includes
#-------------------------------------------------------------------------------
set(FIPS_PLATFORM EMSCRIPTEN)
set(FIPS_PLATFORM_NAME "emsc")
set(FIPS_EMSCRIPTEN 1)
set(FIPS_POSIX 1)
# tweakable options
option(FIPS_EMSCRIPTEN_USE_FS "enable FS module" OFF)
option(FIPS_EMSCRIPTEN_USE_DFE "enable Duplicate Function Elimination" OFF)
option(FIPS_EMSCRIPTEN_USE_WASM "enable WebAssembly" ON)
option(FIPS_EMSCRIPTEN_USE_SAFE_HEAP "enable SAFE_HEAP checks" OFF)
option(FIPS_EMSCRIPTEN_USE_ASAN "enable address sanitizer" OFF)
option(FIPS_EMSCRIPTEN_USE_CPU_PROFILER "enable the built-in CPU profiler" OFF)
option(FIPS_EMSCRIPTEN_USE_MEMORY_PROFILER "enable the built-in memory profiler" OFF)
option(FIPS_EMSCRIPTEN_USE_WEBGL2 "use WebGL2" OFF)
option(FIPS_EMSCRIPTEN_USE_WEBGPU "use WebGPU" OFF)
option(FIPS_EMSCRIPTEN_USE_CLOSURE "run closure compiler on JS code" OFF)
option(FIPS_EMSCRIPTEN_USE_EMMALLOC "use emmalloc allocator" OFF)
option(FIPS_EMSCRIPTEN_USE_EMBIND "use embind" OFF)
option(FIPS_EMSCRIPTEN_ALLOW_MEMORY_GROWTH "allow memory growth" ON)
option(FIPS_EMSCRIPTEN_USE_WASM_TRAP_MODE_CLAMP "use trap-mode clamp for wasm" OFF)
option(FIPS_EMSCRIPTEN_DEMANGLE "compile with libcxxabi-provided demangling support" OFF)
option(FIPS_EMSCRIPTEN_USE_FETCH "use fetch API" OFF)
option(FIPS_EMSCRIPTEN_USE_MINIMAL_RUNTIME "use the minimal JS runtime" OFF)
option(FIPS_EMSCRIPTEN_USE_LTO "enable link-time optimization" ON)
set(FIPS_EMSCRIPTEN_INITIAL_MEMORY 33554432 CACHE STRING "initial heap size in bytes")
set(FIPS_EMSCRIPTEN_STACK_SIZE "512KB" CACHE STRING "max stack size")
set(FIPS_EMSCRIPTEN_SHELL_HTML "" CACHE STRING "path to shell html file")
set(FIPS_EMSCRIPTEN_POSTFIX ".html" CACHE STRING "emscripten output postfix")
if (FIPS_EMSCRIPTEN_RELATIVE_SHELL_HTML)
set(FIPS_EMSCRIPTEN_SHELL_HTML "${CMAKE_SOURCE_DIR}/${FIPS_EMSCRIPTEN_RELATIVE_SHELL_HTML}")
endif()
set(EMSC_COMMON_FLAGS)
set(EMSC_COMMON_FLAGS_RELEASE)
set(EMSC_CXX_FLAGS)
set(EMSC_LINKER_FLAGS)
set(EMSC_LINKER_FLAGS_RELEASE)
set(EMSC_EXE_LINKER_FLAGS)
set(EMSC_AR_FLAGS)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s STACK_SIZE=${FIPS_EMSCRIPTEN_STACK_SIZE}")
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s INITIAL_MEMORY=${FIPS_EMSCRIPTEN_INITIAL_MEMORY}")
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1")
if (FIPS_EMSCRIPTEN_ALLOW_MEMORY_GROWTH)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
endif()
if (FIPS_EMSCRIPTEN_USE_WASM_TRAP_MODE_CLAMP)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s \"BINARYEN_TRAP_MODE='clamp'\"")
endif()
if (FIPS_PROFILING)
set(EMSC_TRACING 1)
set(EMSC_COMMON_FLAGS "${EMSC_COMMON_FLAGS} --tracing")
else()
set(EMSC_TRACING 0)
endif()
if (FIPS_EMSCRIPTEN_USE_SAFE_HEAP)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s SAFE_HEAP=1")
endif()
if (FIPS_EMSCRIPTEN_USE_ASAN)
set(EMSC_COMMON_FLAGS "${EMSC_COMMON_FLAGS} -fsanitize=address")
endif()
if (FIPS_EMSCRIPTEN_USE_WEBGL2)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s USE_WEBGL2=1")
endif()
if (FIPS_EMSCRIPTEN_USE_WEBGPU)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s USE_WEBGPU=1")
endif()
if (FIPS_EMSCRIPTEN_USE_EMMALLOC)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s \"MALLOC='emmalloc'\"")
endif()
if (FIPS_EMSCRIPTEN_USE_EMBIND)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} --bind")
endif()
if (FIPS_EMSCRIPTEN_USE_FS)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s NO_FILESYSTEM=0")
else()
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s NO_FILESYSTEM=1")
endif()
if (FIPS_EMSCRIPTEN_USE_DFE)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s ELIMINATE_DUPLICATE_FUNCTIONS=1")
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS=1")
endif()
if (FIPS_COMPILE_VERBOSE)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s VERBOSE=1")
endif()
if (FIPS_EMSCRIPTEN_USE_CPU_PROFILER)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} --cpuprofiler")
endif()
if (FIPS_EMSCRIPTEN_USE_MEMORY_PROFILER)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} --memoryprofiler")
endif()
set(EMSCRIPTEN_OPT "-O3")
if (FIPS_EXCEPTIONS)
set(EMSC_COMMON_FLAGS "${EMSC_COMMON_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0")
else()
set(EMSC_COMMON_FLAGS "${EMSC_COMMON_FLAGS} -s DISABLE_EXCEPTION_CATCHING=1")
set(EMSC_CXX_FLAGS "${EMSC_CXX_FLAGS} -fno-exceptions")
endif()
if (NOT FIPS_RTTI)
set(EMSC_CXX_FLAGS "${EMSC_CXX_FLAGS} -fno-rtti")
endif()
if (FIPS_EMSCRIPTEN_USE_LTO)
set(EMSC_COMMON_FLAGS_RELEASE "${EMSC_COMMON_FLAGS_RELEASE} -flto")
endif()
if (FIPS_EMSCRIPTEN_USE_WASM)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s WASM=1")
else()
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s WASM=0")
endif()
if (FIPS_EMSCRIPTEN_USE_CLOSURE)
set(EMSC_LINKER_FLAGS_RELEASE "${EMSC_LINKER_FLAGS_RELEASE} --closure 1")
endif()
if (FIPS_EMSCRIPTEN_DEMANGLE)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s DEMANGLE_SUPPORT=1")
endif()
set(EMSC_LINKER_FLAGS_RELEASE "${EMSC_LINKER_FLAGS_RELEASE} -s ASSERTIONS=0")
if (FIPS_EMSCRIPTEN_USE_FETCH)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s FETCH=1")
endif()
if (FIPS_EMSCRIPTEN_USE_MINIMAL_RUNTIME)
set(EMSC_LINKER_FLAGS "${EMSC_LINKER_FLAGS} -s MINIMAL_RUNTIME=2 -s ENVIRONMENT=web")
endif()
if (NOT FIPS_EMSCRIPTEN_SHELL_HTML STREQUAL "")
set(EMSC_EXE_LINKER_FLAGS "${EMSC_EXE_LINKER_FLAGS} --shell-file ${FIPS_EMSCRIPTEN_SHELL_HTML}")
endif()
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(COMPILING ON)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSTEM_PROCESSOR x86)
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
# tool suffic (.bat on windows)
if (CMAKE_HOST_WIN32)
set(EMCC_SUFFIX ".bat")
else()
set(EMCC_SUFFIX "")
endif()
# define configurations
set(CMAKE_CONFIGURATION_TYPES Debug Release Profiling)
# specify cross-compilers
set(CMAKE_C_COMPILER "${EMSCRIPTEN_ROOT}/emcc${EMCC_SUFFIX}" CACHE PATH "gcc" FORCE)
set(CMAKE_CXX_COMPILER "${EMSCRIPTEN_ROOT}/em++${EMCC_SUFFIX}" CACHE PATH "g++" FORCE)
set(CMAKE_AR "${EMSCRIPTEN_ROOT}/emar${EMCC_SUFFIX}" CACHE PATH "archive" FORCE)
set(CMAKE_LINKER "${EMSCRIPTEN_ROOT}/emcc${EMCC_SUFFIX}" CACHE PATH "linker" FORCE)
set(CMAKE_RANLIB "${EMSCRIPTEN_ROOT}/emranlib${EMCC_SUFFIX}" CACHE PATH "ranlib" FORCE)
# override cmake modules with emscripten cmake modules
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${EMSCRIPTEN_ROOT}/cmake/Modules")
# only search for libraries and includes in the toolchain
set(CMAKE_FIND_ROOT_PATH ${EMSCRIPTEN_ROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_SYSTEM_INCLUDE_PATH "${EMSCRIPTEN_ROOT}/system/include")
set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1)
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1)
set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@")
set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@")
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_SKIP_COMPATIBILITY_TESTS 1)
set(CMAKE_SIZEOF_CHAR 1)
set(CMAKE_SIZEOF_UNSIGNED_SHORT 2)
set(CMAKE_SIZEOF_SHORT 2)
set(CMAKE_SIZEOF_INT 4)
set(CMAKE_SIZEOF_UNSIGNED_LONG 4)
set(CMAKE_SIZEOF_UNSIGNED_INT 4)
set(CMAKE_SIZEOF_LONG 4)
set(CMAKE_SIZEOF_VOID_P 4)
set(CMAKE_SIZEOF_FLOAT 4)
set(CMAKE_SIZEOF_DOUBLE 8)
set(CMAKE_C_SIZEOF_DATA_PTR 4)
set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
set(CMAKE_HAVE_LIMITS_H 1)
set(CMAKE_HAVE_UNISTD_H 1)
set(CMAKE_HAVE_PTHREAD_H 1)
set(CMAKE_HAVE_SYS_PRCTL_H 1)
set(CMAKE_WORDS_BIGENDIAN 0)
set(CMAKE_DL_LIBS)
# c++ compiler flags
set(CMAKE_CXX_FLAGS "${EMSC_COMMON_FLAGS} ${EMSC_CXX_FLAGS} -fstrict-aliasing -Wall -Wno-multichar -Wextra -Wno-unknown-pragmas -Wno-ignored-qualifiers -Wno-long-long -Wno-overloaded-virtual -Wno-deprecated-writable-strings -Wno-unused-volatile-lvalue -Wno-inconsistent-missing-override -Wno-warn-absolute-paths -Wno-expansion-to-defined")
set(CMAKE_CXX_FLAGS_RELEASE "${EMSC_COMMON_FLAGS_RELEASE} ${EMSCRIPTEN_OPT} -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -D_DEBUG_ -D_DEBUG -DFIPS_DEBUG=1")
set(CMAKE_CXX_FLAGS_PROFILING "${EMSCRIPTEN_OPT} -DNDEBUG --profiling")
# c compiler flags
set(CMAKE_C_FLAGS "${EMSC_COMMON_FLAGS} -fstrict-aliasing -Wall -Wextra -Wno-multichar -Wno-unknown-pragmas -Wno-ignored-qualifiers -Wno-long-long -Wno-overloaded-virtual -Wno-deprecated-writable-strings -Wno-unused-volatile-lvalue -Wno-warn-absolute-paths -Wno-expansion-to-defined")
set(CMAKE_C_FLAGS_RELEASE "${EMSCRIPTEN_OPT} ${EMSC_COMMON_FLAGS_RELEASE} -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -D_DEBUG_ -D_DEBUG -DFIPS_DEBUG=1")
set(CMAKE_C_FLAGS_PROFILING "${EMSCRIPTEN_OPT} -DNDEBUG --profiling")
# linker flags
set(CMAKE_EXE_LINKER_FLAGS "${EMSC_COMMON_FLAGS} ${EMSC_LINKER_FLAGS} ${EMSC_EXE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${EMSCRIPTEN_OPT} ${EMSC_COMMON_FLAGS_RELEASE} ${EMSC_LINKER_FLAGS_RELEASE}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-O0 -g")
set(CMAKE_EXE_LINKER_FLAGS_PROFILING "--profiling ${EMSCRIPTEN_OPT} ${EMSC_LINKER_FLAGS_RELEASE}")
# static library flags (for CMAKE_AR)
set(CMAKE_STATIC_LINKER_FLAGS "${EMSC_AR_FLAGS}")
# dynamic lib linker flags
set(CMAKE_SHARED_LINKER_FLAGS "-shared ${EMSC_COMMON_FLAGS} ${EMSC_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${EMSCRIPTEN_OPT} ${EMSC_COMMON_FLAGS_RELEASE} ${EMSC_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${EMSCRIPTEN_OPT} -g")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "--profiling ${EMSCRIPTEN_OPT} ${EMSC_LINKER_FLAGS_RELEASE}")
# update cache variables for cmake gui
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Config Type" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "Generic C++ Compiler Flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "C++ Debug Compiler Flags" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "C++ Release Compiler Flags" FORCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Generic C Compiler Flags" FORCE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "C Debug Compiler Flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "C Release Compiler Flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "Generic Linker Flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "Debug Linker Flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Release Linker Flags" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" CACHE STRING "Generic Shared Linker Flags" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING "Debug Shared Linker Flags" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" CACHE STRING "Release Shared Linker Flags" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS}" CACHE STRING "Static Lib Flags" FORCE)
# set the build type to use
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Compile Type" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release Profiling)