@@ -4,6 +4,14 @@ if (NOT VCPKG_LIBRARY_LINKAGE)
44 set (VCPKG_LIBRARY_LINKAGE static )
55endif ()
66
7+ get_filename_component (toolchainFile "${CMAKE_TOOLCHAIN_FILE} " NAME )
8+ if (toolchainFile STREQUAL "Emscripten.cmake" )
9+ set (CESIUM_TARGET_WASM ON )
10+ # Include the toolchain directly as ezvcpkg will overwrite the
11+ # toolchain before it's loaded
12+ include (${CMAKE_TOOLCHAIN_FILE} )
13+ endif ()
14+
715# By default, Use ezvcpkg to install dependencies. But don't use
816# ezvcpkg if it appears that this configuration is using vcpkg
917# manifest mode already, either by building cesium-native directly,
@@ -24,6 +32,13 @@ endif()
2432
2533option (CESIUM_USE_EZVCPKG "use ezvcpkg helper" ${CESIUM_USE_EZVCPKG_DEFAULT} )
2634option (CESIUM_DISABLE_CURL "Disable cesium-native's use of libcurl" OFF )
35+ option (CESIUM_DISABLE_LIBJPEG_TURBO "Disable cesium-native's use of libjpeg-turbo. JPEG images will be decoded with STB instead." OFF )
36+ option (CESIUM_WASM64 "Enable 64-bit WebAssembly target" OFF )
37+
38+ if (CESIUM_TARGET_WASM)
39+ # Make sure curl is disabled on wasm builds, as it is not supported.
40+ set (CESIUM_DISABLE_CURL ON )
41+ endif ()
2742
2843if (CESIUM_USE_EZVCPKG)
2944 # Keep vcpkg from running in manifset mode. It will try to because
@@ -50,6 +65,15 @@ if (NOT VCPKG_TRIPLET)
5065 elseif (DETECTED_VCPKG_TRIPLET STREQUAL "x64-windows" )
5166 # cesium-native requires static linking on Windows
5267 set (VCPKG_TRIPLET "x64-windows-static-md" )
68+ elseif (DETECTED_VCPKG_TRIPLET STREQUAL "wasm32-emscripten" )
69+ # Use our custom triplet for wasm builds. Most importantly, this
70+ # enables multithreading support. Also switch to 64-bit wasm if
71+ # requested.
72+ if (CESIUM_WASM64)
73+ set (VCPKG_TRIPLET "wasm64-emscripten-cesium" )
74+ else ()
75+ set (VCPKG_TRIPLET "wasm32-emscripten-cesium" )
76+ endif ()
5377 else ()
5478 set (VCPKG_TRIPLET "${DETECTED_VCPKG_TRIPLET} " )
5579 endif ()
@@ -87,6 +111,10 @@ if (NOT VCPKG_OVERLAY_TRIPLETS)
87111 endif ()
88112endif ()
89113
114+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /extern/vcpkg/triplets" )
115+ list (APPEND VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR} /extern/vcpkg/triplets" )
116+ endif ()
117+
90118message (STATUS "VCPKG_OVERLAY_TRIPLETS ${VCPKG_OVERLAY_TRIPLETS} " )
91119
92120# These packages are used in the public headers of Cesium libraries, so we need to distribute the headers and binaries
@@ -98,13 +126,13 @@ set(PACKAGES_PUBLIC asyncplusplus expected-lite fmt glm rapidjson spdlog stb ada
98126# to distribute the binaries for linking, but not the headers, as downstream consumers don't need them
99127# OpenSSL and abseil are both dependencies of s2geometry
100128set (PACKAGES_PRIVATE
101- abseil draco ktx modp-base64 meshoptimizer openssl s2geometry
102- libjpeg-turbo sqlite3 tinyxml2 libwebp zlib-ng picosha2
103- earcut-hpp cpp-httplib[core] libmorton zstd
129+ abseil draco ktx[core] modp-base64 meshoptimizer openssl s2geometry
130+ sqlite3 tinyxml2 libwebp zlib-ng picosha2
131+ earcut-hpp libmorton zstd
104132)
105133
106- # asmjit needed by blend2d on non-iOS platforms (iOS doesn 't support JIT)
107- if (NOT IOS AND NOT VCPKG_CMAKE_SYSTEM_NAME MATCHES "iOS" )
134+ # asmjit needed by blend2d on non-iOS platforms (iOS and Wasm don 't support JIT)
135+ if (NOT CESIUM_TARGET_WASM AND NOT IOS AND NOT VCPKG_CMAKE_SYSTEM_NAME MATCHES "iOS" )
108136 list (APPEND PACKAGES_PRIVATE blend2d asmjit)
109137else ()
110138 # Use [core] feature to disable default jit feature.
@@ -115,16 +143,37 @@ if(NOT CESIUM_DISABLE_CURL)
115143 list (APPEND PACKAGES_PRIVATE curl)
116144endif ()
117145
146+ if (NOT CESIUM_DISABLE_LIBJPEG_TURBO)
147+ list (APPEND PACKAGES_PRIVATE libjpeg-turbo)
148+ endif ()
149+
150+ # We use cpp-httplib to host a local web server for OAuth2 authorization. That's not
151+ # going to work at all on the web, and the latest versions of cpp-httplib only support
152+ # 64-bit platforms anyway, so skip it entirely for WebAssembly builds.
153+ if (NOT CESIUM_TARGET_WASM)
154+ list (APPEND PACKAGES_PRIVATE "cpp-httplib[core]" )
155+ endif ()
156+
118157# Packages only used for testing
119158set (PACKAGES_TEST doctest)
120159
160+ if (CESIUM_TARGET_WASM)
161+ # vcpkg will attempt to second-guess our CMAKE_C_COMPILER setting, choosing to go with the value of CC instead.
162+ # While normally this is the correct value to go with, for wasm we need to be using emcc and em++.
163+ # So we set CC and CXX to emcc and em++ here so vcpkg will pick them up properly.
164+ # Does this make sense? No. Does it work? Somehow. ¯\_(ツ)_/¯
165+ set (ENV{CC} ${CMAKE_C_COMPILER} )
166+ set (ENV{CXX} ${CMAKE_CXX_COMPILER} )
167+ endif ()
168+
121169if (CESIUM_USE_EZVCPKG)
122170 set (PACKAGES_ALL ${PACKAGES_PUBLIC} )
123171 list (APPEND PACKAGES_ALL ${PACKAGES_PRIVATE} )
124172 list (APPEND PACKAGES_ALL ${PACKAGES_TEST} )
125173
126174 ezvcpkg_fetch(
127- COMMIT 2025.09.17
175+ COMMIT afc0a2e01ae104a2474216a2df0e8d78516fd5af
176+ REPO microsoft/vcpkg
128177 PACKAGES ${PACKAGES_ALL}
129178 # Clean the build trees after building, so that we don't use a ton a disk space on the CI cache
130179 CLEAN_BUILDTREES
@@ -149,6 +198,16 @@ project(cesium-native
149198 LANGUAGES CXX C
150199)
151200
201+ if (CESIUM_TARGET_WASM)
202+ if (CESIUM_WASM64)
203+ set (CMAKE_SIZEOF_VOID_P 8)
204+ else ()
205+ set (CMAKE_SIZEOF_VOID_P 4)
206+ endif ()
207+ # Tells emscripten to output an HTML harness for the generated WASM
208+ set (CMAKE_EXECUTABLE_SUFFIX ".html" )
209+ endif ()
210+
152211include (GNUInstallDirs)
153212include (CMakeDependentOption)
154213
@@ -318,9 +377,7 @@ find_package(doctest CONFIG REQUIRED)
318377find_package (draco CONFIG REQUIRED)
319378find_package (expected-lite CONFIG REQUIRED)
320379find_package (glm CONFIG REQUIRED)
321- find_package (httplib CONFIG REQUIRED)
322380find_package (Ktx CONFIG REQUIRED)
323- find_package (libjpeg-turbo CONFIG REQUIRED)
324381find_package (libmorton CONFIG REQUIRED)
325382find_package (meshoptimizer CONFIG REQUIRED)
326383find_package (OpenSSL REQUIRED)
@@ -331,15 +388,23 @@ find_package(unofficial-sqlite3 CONFIG REQUIRED)
331388find_package (WebP CONFIG REQUIRED)
332389find_package (zlib-ng CONFIG REQUIRED)
333390
334- # asmjit should not be included with iOS builds as iOS doesn 't support JIT compilation.
335- if (NOT IOS AND NOT VCPKG_CMAKE_SYSTEM_NAME MATCHES "iOS" )
391+ # asmjit should not be included with iOS or Wasm builds as they don 't support JIT compilation.
392+ if (NOT CESIUM_TARGET_WASM AND NOT IOS AND NOT VCPKG_CMAKE_SYSTEM_NAME MATCHES "iOS" )
336393 find_package (asmjit CONFIG REQUIRED)
337394endif ()
338395
339396if (NOT CESIUM_DISABLE_CURL)
340397 find_package (CURL REQUIRED)
341398endif ()
342399
400+ if (NOT CESIUM_DISABLE_LIBJPEG_TURBO)
401+ find_package (libjpeg-turbo CONFIG REQUIRED)
402+ endif ()
403+
404+ if (NOT CESIUM_TARGET_WASM)
405+ find_package (httplib CONFIG REQUIRED)
406+ endif ()
407+
343408# Private Library (s2geometry)
344409add_subdirectory (extern EXCLUDE_FROM_ALL )
345410
0 commit comments