|
6 | 6 | endif() |
7 | 7 |
|
8 | 8 | add_compile_definitions(USE_WEBGPU=1) |
| 9 | + if(onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB) |
| 10 | + add_compile_definitions(BUILD_WEBGPU_EP_STATIC_LIB=1) |
| 11 | + endif() |
| 12 | + |
9 | 13 | if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS) |
10 | 14 | add_definitions(-DENABLE_WEBASSEMBLY_THREADS=1) |
11 | 15 | endif() |
|
20 | 24 | elseif (NOT onnxruntime_WGSL_TEMPLATE STREQUAL "static") |
21 | 25 | message(FATAL_ERROR "Unsupported value for onnxruntime_WGSL_TEMPLATE: ${onnxruntime_WGSL_TEMPLATE}. Supported values are 'static' or 'dynamic'.") |
22 | 26 | endif() |
| 27 | + |
23 | 28 | file(GLOB_RECURSE onnxruntime_providers_webgpu_cc_srcs CONFIGURE_DEPENDS |
24 | 29 | "${ONNXRUNTIME_ROOT}/core/providers/webgpu/*.h" |
25 | 30 | "${ONNXRUNTIME_ROOT}/core/providers/webgpu/*.cc" |
26 | 31 | ) |
27 | 32 | if(NOT onnxruntime_DISABLE_CONTRIB_OPS) |
28 | | - source_group(TREE ${ONNXRUNTIME_ROOT} FILES ${onnxruntime_webgpu_contrib_ops_cc_srcs}) |
29 | 33 | list(APPEND onnxruntime_providers_webgpu_cc_srcs ${onnxruntime_webgpu_contrib_ops_cc_srcs}) |
30 | 34 | endif() |
31 | 35 |
|
32 | | - source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_providers_webgpu_cc_srcs}) |
33 | | - onnxruntime_add_static_library(onnxruntime_providers_webgpu ${onnxruntime_providers_webgpu_cc_srcs}) |
34 | | - target_compile_features(onnxruntime_providers_webgpu PRIVATE cxx_std_20) |
35 | | - onnxruntime_add_include_to_target(onnxruntime_providers_webgpu |
36 | | - onnxruntime_common onnx onnx_proto flatbuffers::flatbuffers Boost::mp11 safeint_interface) |
| 36 | + if(onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB) |
| 37 | + # |
| 38 | + # Build WebGPU EP as a static library |
| 39 | + # |
| 40 | + |
| 41 | + # For static library build, exclude the 'ep' folder |
| 42 | + file(GLOB_RECURSE ep_files_to_exclude |
| 43 | + "${ONNXRUNTIME_ROOT}/core/providers/webgpu/ep/*.h" |
| 44 | + "${ONNXRUNTIME_ROOT}/core/providers/webgpu/ep/*.cc" |
| 45 | + ) |
| 46 | + list(REMOVE_ITEM onnxruntime_providers_webgpu_cc_srcs ${ep_files_to_exclude}) |
| 47 | + |
| 48 | + source_group(TREE ${ONNXRUNTIME_ROOT} FILES ${onnxruntime_providers_webgpu_cc_srcs}) |
| 49 | + onnxruntime_add_static_library(onnxruntime_providers_webgpu ${onnxruntime_providers_webgpu_cc_srcs}) |
| 50 | + onnxruntime_add_include_to_target(onnxruntime_providers_webgpu |
| 51 | + onnxruntime_common onnx onnx_proto flatbuffers::flatbuffers Boost::mp11 safeint_interface) |
| 52 | + else() |
| 53 | + # |
| 54 | + # Build WebGPU EP as a shared library |
| 55 | + # |
| 56 | + if(WIN32) |
| 57 | + # Sets the DLL version info on Windows: https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource |
| 58 | + list(APPEND onnxruntime_providers_webgpu_cc_srcs "${ONNXRUNTIME_ROOT}/core/providers/webgpu/ep/versioninfo.rc") |
| 59 | + endif() |
| 60 | + source_group(TREE ${ONNXRUNTIME_ROOT} FILES ${onnxruntime_providers_webgpu_cc_srcs}) |
| 61 | + |
| 62 | + onnxruntime_add_shared_library(onnxruntime_providers_webgpu ${onnxruntime_providers_webgpu_cc_srcs}) |
| 63 | + onnxruntime_add_include_to_target(onnxruntime_providers_webgpu |
| 64 | + ${REPO_ROOT}/include/onnxruntime/core/session |
| 65 | + onnxruntime_common |
| 66 | + onnx |
| 67 | + onnx_proto |
| 68 | + flatbuffers::flatbuffers |
| 69 | + Boost::mp11 |
| 70 | + safeint_interface) |
| 71 | + |
| 72 | + target_link_libraries(onnxruntime_providers_webgpu PRIVATE |
| 73 | + onnxruntime_optimizer |
| 74 | + onnxruntime_providers |
| 75 | + onnxruntime_lora |
| 76 | + onnxruntime_framework |
| 77 | + onnxruntime_graph |
| 78 | + onnxruntime_util |
| 79 | + ${ONNXRUNTIME_MLAS_LIBS} |
| 80 | + onnxruntime_common |
| 81 | + onnxruntime_flatbuffers |
| 82 | + ${onnxruntime_EXTERNAL_LIBRARIES} |
| 83 | + ) |
| 84 | + |
| 85 | + # Add ONNX compiler definitions |
| 86 | + add_definitions("-DONNX_ML=1") |
| 87 | + add_definitions("-DONNX_NAMESPACE=onnx") |
| 88 | + add_definitions("-DONNX_USE_LITE_PROTO=1") |
| 89 | + |
| 90 | + # Set preprocessor definitions used in onnxruntime_providers_webgpu.rc |
| 91 | + if(WIN32) |
| 92 | + set(WEBGPU_DLL_FILE_DESCRIPTION "ONNX Runtime WebGPU Provider") |
| 93 | + |
| 94 | + target_compile_definitions(onnxruntime_providers_webgpu PRIVATE FILE_DESC=\"${WEBGPU_DLL_FILE_DESCRIPTION}\") |
| 95 | + target_compile_definitions(onnxruntime_providers_webgpu PRIVATE FILE_NAME=\"onnxruntime_providers_webgpu.dll\") |
| 96 | + endif() |
| 97 | + |
| 98 | + # Set linker flags for function(s) exported by EP DLL |
| 99 | + if(UNIX) |
| 100 | + if (APPLE) |
| 101 | + set_property(TARGET onnxruntime_providers_webgpu APPEND_STRING PROPERTY LINK_FLAGS |
| 102 | + "-Xlinker -dead_strip") |
| 103 | + elseif (NOT CMAKE_SYSTEM_NAME MATCHES "AIX") |
| 104 | + target_link_options(onnxruntime_providers_webgpu PRIVATE |
| 105 | + "LINKER:--version-script=${ONNXRUNTIME_ROOT}/core/providers/webgpu/ep/version_script.lds" |
| 106 | + "LINKER:--gc-sections" |
| 107 | + "LINKER:-rpath=\$ORIGIN") |
| 108 | + # TODO: -z noexecstack |
| 109 | + endif() |
| 110 | + elseif(WIN32) |
| 111 | + set_property(TARGET onnxruntime_providers_webgpu APPEND_STRING PROPERTY LINK_FLAGS |
| 112 | + "-DEF:${ONNXRUNTIME_ROOT}/core/providers/webgpu/ep/symbols.def") |
| 113 | + else() |
| 114 | + message(FATAL_ERROR "onnxruntime_providers_webgpu unknown platform, need to specify shared library exports for it") |
| 115 | + endif() |
| 116 | + |
| 117 | + set_target_properties(onnxruntime_providers_webgpu PROPERTIES LINKER_LANGUAGE CXX) |
| 118 | + |
| 119 | + if (onnxruntime_BUILD_CACHE) |
| 120 | + message(FATAL_ERROR "WebGPU EP shared library build does not support build cache. Please disable build cache or use static library build.") |
| 121 | + endif() |
| 122 | + if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") |
| 123 | + message(FATAL_ERROR "WebGPU EP shared library build is not supported on Emscripten. Please use static library build.") |
| 124 | + endif() |
| 125 | + endif() |
| 126 | + |
| 127 | + set_target_properties(onnxruntime_providers_webgpu PROPERTIES CXX_STANDARD_REQUIRED ON) |
| 128 | + set_target_properties(onnxruntime_providers_webgpu PROPERTIES FOLDER "ONNXRuntime") |
37 | 129 |
|
38 | 130 | if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") |
39 | 131 | # target "emdawnwebgpu_c" is created by Dawn, including "-fno-exceptions" in its compile options by default. |
|
89 | 181 | set(onnxruntime_providers_webgpu_dll_deps) |
90 | 182 |
|
91 | 183 | if (onnxruntime_BUILD_DAWN_SHARED_LIBRARY) |
92 | | - target_link_libraries(onnxruntime_providers_webgpu dawn::webgpu_dawn) |
| 184 | + target_link_libraries(onnxruntime_providers_webgpu PUBLIC dawn::webgpu_dawn) |
93 | 185 |
|
94 | 186 | if (WIN32) |
95 | 187 | if (onnxruntime_ENABLE_DELAY_LOADING_WIN_DLLS) |
|
116 | 208 | list(APPEND onnxruntime_providers_webgpu_dll_deps "$<TARGET_FILE:dawn::webgpu_dawn>") |
117 | 209 | else() |
118 | 210 | if (NOT onnxruntime_USE_EXTERNAL_DAWN) |
119 | | - target_link_libraries(onnxruntime_providers_webgpu dawn::dawn_native) |
| 211 | + target_link_libraries(onnxruntime_providers_webgpu PRIVATE dawn::dawn_native) |
120 | 212 | endif() |
121 | | - target_link_libraries(onnxruntime_providers_webgpu dawn::dawn_proc) |
| 213 | + target_link_libraries(onnxruntime_providers_webgpu PRIVATE dawn::dawn_proc) |
122 | 214 | endif() |
123 | 215 |
|
124 | 216 | if (WIN32 AND onnxruntime_ENABLE_DAWN_BACKEND_D3D12) |
|
153 | 245 | endif() |
154 | 246 | endif() |
155 | 247 |
|
156 | | - add_dependencies(onnxruntime_providers_webgpu ${onnxruntime_EXTERNAL_DEPENDENCIES}) |
| 248 | + target_compile_features(onnxruntime_providers_webgpu PRIVATE cxx_std_20) |
| 249 | + add_dependencies(onnxruntime_providers_webgpu onnx ${onnxruntime_EXTERNAL_DEPENDENCIES}) |
157 | 250 |
|
158 | 251 | if (onnxruntime_WGSL_TEMPLATE) |
159 | 252 | # Define the WGSL templates directory and output directory |
|
239 | 332 | # Add the generated directory to include paths |
240 | 333 | target_include_directories(onnxruntime_providers_webgpu PRIVATE ${WGSL_GENERATED_ROOT}) |
241 | 334 | elseif(onnxruntime_WGSL_TEMPLATE STREQUAL "dynamic") |
242 | | - target_link_libraries(onnxruntime_providers_webgpu duktape_static) |
| 335 | + target_link_libraries(onnxruntime_providers_webgpu PRIVATE duktape_static) |
243 | 336 | onnxruntime_add_include_to_target(onnxruntime_providers_webgpu duktape_static) |
244 | 337 |
|
245 | 338 | # Define the path to the generated templates.js file |
|
251 | 344 | add_dependencies(onnxruntime_providers_webgpu onnxruntime_webgpu_wgsl_generation) |
252 | 345 | endif() |
253 | 346 |
|
254 | | - set_target_properties(onnxruntime_providers_webgpu PROPERTIES FOLDER "ONNXRuntime") |
| 347 | + if (NOT onnxruntime_BUILD_SHARED_LIB) |
| 348 | + install(TARGETS onnxruntime_providers_webgpu EXPORT ${PROJECT_NAME}Targets |
| 349 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 350 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 351 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 352 | + FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 353 | + endif() |
0 commit comments