forked from WasmEdge/WasmEdge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
236 lines (215 loc) · 11 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
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2019-2024 Second State INC
cmake_minimum_required(VERSION 3.18)
cmake_policy(SET CMP0091 NEW)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
project(WasmEdge LANGUAGES CXX C)
# CMake build type.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
# Overwrite it if you want to use static MSVC runtime library.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
# WasmEdge CAPI and so versions.
set(WASMEDGE_CAPI_VERSION "0.1.0" CACHE STRING "WasmEdge C API library version")
set(WASMEDGE_CAPI_SOVERSION "0" CACHE STRING "WasmEdge C API library soversion")
set(WASMEDGE_WASI_NN_VERSION "0.1.0" CACHE STRING "WasmEdge WASI-NN library version")
set(WASMEDGE_WASI_NN_SOVERSION "0" CACHE STRING "WasmEdge WASI-NN library soversion")
# Set cpack package version.
find_program(GIT_CMD git)
# Assuming the git command is not found and .git folder is not available.
set(GIT_VERSION_NOT_FOUND 1)
if(GIT_CMD AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
execute_process(COMMAND
${GIT_CMD} describe --match "[0-9].[0-9]*" --tag
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE CPACK_PACKAGE_VERSION
RESULT_VARIABLE GIT_VERSION_NOT_FOUND
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(GIT_VERSION_NOT_FOUND AND NOT GIT_VERSION_NOT_FOUND EQUAL 0)
set(CPACK_PACKAGE_VERSION "0.0.0-unreleased")
endif()
# Overwrite version information once there is a VERSION file.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" LOCAL_VERSION)
set(CPACK_PACKAGE_VERSION ${LOCAL_VERSION})
unset(LOCAL_VERSION)
endif()
# Add the CMake module path.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Export compile commands.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Find threads and filesystem.
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Filesystem REQUIRED Final Experimental)
find_package(Threads REQUIRED)
# List of WasmEdge options
option(WASMEDGE_BUILD_TESTS "Generate build targets for the wasmedge unit tests." OFF)
option(WASMEDGE_BUILD_COVERAGE "Generate coverage report. Require WASMEDGE_BUILD_TESTS." OFF)
option(WASMEDGE_BUILD_SHARED_LIB "Generate the WasmEdge shared library." ON)
option(WASMEDGE_BUILD_STATIC_LIB "Generate the WasmEdge static library." OFF)
option(WASMEDGE_BUILD_TOOLS "Generate wasmedge and wasmedgec tools. Depend on and will build the WasmEdge shared library." ON)
option(WASMEDGE_BUILD_FUZZING "Generate fuzzing test tools. Couldn't build with wasmedge tools and unit tests." OFF)
option(WASMEDGE_BUILD_PLUGINS "Generate plugins." ON)
option(WASMEDGE_BUILD_EXAMPLE "Generate examples." OFF)
option(WASMEDGE_BUILD_WASI_NN_RPC "Generate WASI-NN RPC." OFF)
option(WASMEDGE_USE_LLVM "Enable WasmEdge LLVM-based compilation runtime." ON)
if(WASMEDGE_BUILD_AOT_RUNTIME)
message(WARNING "WASMEDGE_BUILD_AOT_RUNTIME option was renamed to WASMEDGE_USE_LLVM.")
set(WASMEDGE_USE_LLVM "${WASMEDGE_BUILD_AOT_RUNTIME}" CACHE STRING "Enable WasmEdge LLVM-based compilation runtime.")
unset(WASMEDGE_BUILD_AOT_RUNTIME CACHE)
endif()
option(WASMEDGE_USE_CXX11_ABI "Enable cxx11 abi when building WasmEdge." ON)
option(WASMEDGE_FORCE_DISABLE_LTO "Forcefully disable link time optimization when linking even in Release/RelWithDeb build." OFF)
option(WASMEDGE_LINK_LLVM_STATIC "Statically link the LLVM library into the WasmEdge tools and libraries." OFF)
option(WASMEDGE_LINK_TOOLS_STATIC "Statically link the wasmedge and wasmedgec tools. Will forcefully link the LLVM library statically." OFF)
option(WASMEDGE_ENABLE_UB_SANITIZER "Enable undefined behavior sanitizer." OFF)
option(WASMEDGE_DISABLE_LIBTINFO "Disable linking against libtinfo when linking LLVM." OFF)
# Options about plug-ins.
# WASI plug-in: WASI-Crypto proposal.
option(WASMEDGE_PLUGIN_WASI_CRYPTO "Enable and build WasmEdge wasi-crypto plugin." OFF)
# WASI plug-in: WASI-Http proposal.
option(WASMEDGE_PLUGIN_WASI_HTTP "Enable and build WasmEdge wasi-http plugin." OFF)
# WASI plug-in: WASI-Logging proposal.
# Note: WASMEDGE_PLUGIN_WASI_LOGGING is not used until the new plug-in mechanism ready in 0.15.0.
option(WASMEDGE_PLUGIN_WASI_LOGGING "Enable and build WasmEdge wasi-logging plugin." ON)
# WASI plug-in: WASI-NN proposal with backends.
set(WASMEDGE_PLUGIN_WASI_NN_BACKEND "" CACHE STRING "Enable and build WasmEdge Wasi-NN plugin with backends.")
option(WASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_NATIVE "Enable LLAMA_NATIVE(AVX/AVX2/FMA) in the WASI-NN GGML backend." ON)
option(WASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_BLAS "Enable LLAMA_BLAS in the WASI-NN GGML backend." OFF)
option(WASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_CUBLAS "Enable LLAMA_CUBLAS in the WASI-NN GGML backend." OFF)
option(WASMEDGE_PLUGIN_WASI_NN_GGML_LLAMA_METAL "Enable LLAMA_METAL in the WASI-NN GGML backend. Available on MacOS arm64 only." ON)
option(WASMEDGE_PLUGIN_WASI_NN_WHISPER_METAL "Enable GGML_METAL in the WASI-NN WHISPER backend. Available on MacOS arm64 only." ON)
option(WASMEDGE_PLUGIN_WASI_NN_WHISPER_CUDA "Enable GGML_CUDA in the WASI-NN WHISPER backend." OFF)
# WASI plug-in: WASI-Poll proposal.
option(WASMEDGE_PLUGIN_WASI_POLL "Enable and build WasmEdge wasi-poll plugin." OFF)
# WasmEdge plug-in: wasm-bpf.
option(WASMEDGE_PLUGIN_WASM_BPF "Enable and build WasmEdge wasm-bpf plugin." OFF)
# WasmEdge plug-in: ffmpeg.
option(WASMEDGE_PLUGIN_FFMPEG "Enable and build WasmEdge ffmpeg plugin." OFF)
# WasmEdge plug-in: Image.
option(WASMEDGE_PLUGIN_IMAGE "Enable and build WasmEdge image plugin." OFF)
# WasmEdge plug-in: LLMC.
option(WASMEDGE_PLUGIN_LLMC "Enable and build WasmEdge LLMC plugin." OFF)
# WasmEdge plug-in: OCR.
option(WASMEDGE_PLUGIN_OCR "Enable and build WasmEdge OCR plugin." OFF)
# WasmEdge plug-in: OpenCV-mini.
option(WASMEDGE_PLUGIN_OPENCVMINI "Enable and build WasmEdge opencvmini plugin." OFF)
# WasmEdge plug-in: Process.
option(WASMEDGE_PLUGIN_PROCESS "Enable and build WasmEdge process plugin." OFF)
# WasmEdge plug-in: Stable-diffusion.
option(WASMEDGE_PLUGIN_STABLEDIFFUSION "Enable and build WasmEdge stable-diffusion plugin." OFF)
option(WASMEDGE_PLUGIN_STABLEDIFFUSION_CUBLAS "Enable CUBLAS in the stable-diffusion plugin." OFF)
option(WASMEDGE_PLUGIN_STABLEDIFFUSION_METAL "Enable Metal in the stable-diffusion plugin." OFF)
option(WASMEDGE_PLUGIN_STABLEDIFFUSION_OPENMP "Enable OpenMP in the stable-diffusion plugin." OFF)
# WasmEdge plug-in: TensorFlow.
option(WASMEDGE_PLUGIN_TENSORFLOW "Enable and build WasmEdge TensorFlow plugin." OFF)
# WasmEdge plug-in: TensorFlow-Lite.
option(WASMEDGE_PLUGIN_TENSORFLOWLITE "Enable and build WasmEdge TensorFlow-Lite plugin." OFF)
# WasmEdge plug-in: zlib.
option(WASMEDGE_PLUGIN_ZLIB "Enable and build WasmEdge zlib plugin." OFF)
# Fuzzing and tools and tests are exclusive.
if(WASMEDGE_BUILD_TOOLS AND WASMEDGE_BUILD_FUZZING)
message(FATAL_ERROR "wasmedge tool and fuzzing tool are exclusive options.")
endif()
if(WASMEDGE_BUILD_TESTS AND WASMEDGE_BUILD_FUZZING)
message(FATAL_ERROR "unit tests and fuzzing tool are exclusive options.")
endif()
# Static library will forcefully turn off the LTO.
if(WASMEDGE_BUILD_STATIC_LIB)
set(WASMEDGE_FORCE_DISABLE_LTO ON)
endif()
# WasmEdge tool options.
if(WASMEDGE_BUILD_TOOLS)
if(WASMEDGE_LINK_TOOLS_STATIC)
# Static tools will link LLVM statically.
set(WASMEDGE_LINK_LLVM_STATIC ON)
# Tools will forcefully turn on the static library building.
set(WASMEDGE_BUILD_STATIC_LIB ON)
if(WASMEDGE_BUILD_PLUGINS)
message(WARNING "For tuning on the WASMEDGE_LINK_TOOLS_STATIC option, the plugins will not work.")
endif()
else()
# Tools will forcefully turn on the shared library building.
set(WASMEDGE_BUILD_SHARED_LIB ON)
endif()
endif()
if(WASMEDGE_BUILD_WASI_NN_RPC)
# * Homebrew: grpc
# * Debian, Ubuntu: libgrpc-dev, libgrpc++-dev
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(gRPCPP grpc++)
endif()
# Do not check find_package(gRPC), because libgrpc-dev for Ubuntu 22.04 does not contain cmake files.
# https://packages.ubuntu.com/search?keywords=libgrpc-dev
# Do not check find_package(protobuf), because libprotobuf-dev for Ubuntu does not contain cmake files.
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1027876
if(gRPCPP_FOUND AND WASMEDGE_BUILD_SHARED_LIB)
message(STATUS "If you see an error related to gRPC or protobuf, try setting WASMEDGE_BUILD_WASI_NN_RPC to OFF.")
endif()
if(WASMEDGE_BUILD_WASI_NN_RPC AND NOT WASMEDGE_BUILD_SHARED_LIB)
message(FATAL_ERROR "WASMEDGE_BUILD_WASI_NN_RPC depends on WASMEDGE_BUILD_SHARED_LIB.")
endif()
endif()
set(WASMEDGE_BUILD_PACKAGE "DEB;RPM" CACHE STRING "Package generate types")
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpack_config.cmake)
if(WASMEDGE_BUILD_COVERAGE)
set(GCOVR_ADDITIONAL_ARGS "--exclude-unreachable-branches;--exclude-throw-branches")
include(CodeCoverage)
append_coverage_compiler_flags()
endif()
include(FetchContent)
include(Helper)
include(GNUInstallDirs)
set(CPACK_PACKAGE_VENDOR Second State LLC)
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}")
set(CPACK_STRIP_FILES ON)
set(CPACK_PACKAGE_CONTACT "Shen-Ta Hsieh <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "High performance WebAssembly Virtual Machine")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_ARCHIVE_WASMEDGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}")
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_MAIN_COMPONENT "WasmEdge")
set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_WASMEDGE_PACKAGE_NAME wasmedge)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_COMPRESSION_TYPE xz)
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/WasmEdge/WasmEdge/")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION ON)
set(CPACK_GENERATOR "${WASMEDGE_BUILD_PACKAGE}")
set(CPACK_PACKAGE_DESCRIPTION "WasmEdge is a high performance, extensible, and hardware optimized WebAssembly Virtual Machine for cloud, AI, and blockchain applications.")
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
# If WasmEdge is the top project, only pack the WasmEdge component.
set(CPACK_COMPONENTS_ALL "WasmEdge")
endif()
add_subdirectory(include)
add_subdirectory(lib)
if(WASMEDGE_BUILD_PLUGINS AND (WASMEDGE_BUILD_STATIC_LIB OR WASMEDGE_BUILD_SHARED_LIB))
# Plug-ins should depend on the WasmEdge library.
if(WASMEDGE_BUILD_STATIC_LIB AND NOT WASMEDGE_BUILD_SHARED_LIB)
# Link to the static library if only the WasmEdge static library is built.
# If the WasmEdge shared library is built, the plug-ins will link to the shared library.
set(WASMEDGE_LINK_PLUGINS_STATIC ON)
endif()
add_subdirectory(plugins)
endif()
add_subdirectory(thirdparty)
if(WASMEDGE_BUILD_TOOLS OR WASMEDGE_BUILD_FUZZING)
add_subdirectory(tools)
endif()
if(WASMEDGE_BUILD_TESTS)
include(CTest)
add_subdirectory(test)
endif()
if(WASMEDGE_BUILD_EXAMPLE)
add_subdirectory(examples/plugin/get-string)
endif()
include(CPack)
include(CPackComponent)