Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,52 @@ jobs:
run: |
cd build
ctest -V
WasmBuild:
strategy:
fail-fast: false
matrix:
platform: [wasm64-emscripten]
build_type: [Debug, RelWithDebInfo]
name: "${{matrix.platform}} / ${{matrix.build_type}}"
env:
CACHE_KEY: "${{ matrix.platform }}"
runs-on: ubuntu-24.04
steps:
- name: Install latest CMake 3 and Ninja
uses: lukka/get-cmake@latest
with:
cmakeVersion: "3.31.6"
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v14
with:
version: 4.0.10
actions-cache-folder: "emsdk-cache"
- name: Install latest clang
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 19
- name: Install gcc-multilib for 32-bit support
run: |
sudo apt-get install gcc-multilib
- name: Set CC and CXX
run: |
echo "CC=/usr/bin/clang-19" >> "$GITHUB_ENV"
echo "CXX=/usr/bin/clang++-19" >> "$GITHUB_ENV"
- name: Check out repository code
uses: actions/checkout@v4
with:
submodules: recursive
- name: sccache
uses: hendrikmuhs/[email protected]
with:
key: ccache-${{ env.CACHE_KEY}}-${{matrix.build_type}}-1
variant: sccache
- name: Compile ${{matrix.build_type}} Configuration
run: |
emcmake cmake -B build -S . -DCMAKE_BUILD_TYPE=${{matrix.build_type}}
cmake --build build --config debug --target cesium-native-tests -j22
# - name: Test ${{matrix.build_type}} Configuration
# run: |
# cd build
# ctest -V
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug WebAssembly Build",
"program": "${workspaceFolder}/build/CesiumNativeTests/cesium-native-tests.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
}

]
}
51 changes: 47 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ cmake_minimum_required(VERSION 3.15)
if (NOT VCPKG_LIBRARY_LINKAGE)
set(VCPKG_LIBRARY_LINKAGE static)
endif()

get_filename_component(toolchainFile "${CMAKE_TOOLCHAIN_FILE}" NAME)
if(toolchainFile STREQUAL "Emscripten.cmake")
set(CESIUM_TARGET_WASM ON)
# Include the toolchain directly as ezvcpkg will overwrite the
# toolchain before it's loaded
include(${CMAKE_TOOLCHAIN_FILE})
endif()

# By default, Use ezvcpkg to install dependencies. But don't use
# ezvcpkg if it appears that this configuration is using vcpkg
Expand All @@ -16,7 +24,6 @@ set(CESIUM_USE_EZVCPKG_DEFAULT ON)
if (VCPKG_MANIFEST_MODE)
set(CESIUM_USE_EZVCPKG_DEFAULT OFF)
elseif (CMAKE_TOOLCHAIN_FILE)
get_filename_component(toolchainFile "${CMAKE_TOOLCHAIN_FILE}" NAME)
if(toolchainFile STREQUAL "vcpkg.cmake")
set(CESIUM_USE_EZVCPKG_DEFAULT OFF)
endif()
Expand Down Expand Up @@ -78,6 +85,10 @@ if (NOT VCPKG_OVERLAY_TRIPLETS)
endif()
endif()

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/triplets")
list(APPEND VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/triplets")
endif()

message(STATUS "VCPKG_OVERLAY_TRIPLETS ${VCPKG_OVERLAY_TRIPLETS}")

# These packages are used in the public headers of Cesium libraries, so we need to distribute the headers and binaries
Expand All @@ -89,14 +100,27 @@ set(PACKAGES_PUBLIC asyncplusplus expected-lite fmt glm rapidjson spdlog stb ada
# to distribute the binaries for linking, but not the headers, as downstream consumers don't need them
# OpenSSL and abseil are both dependencies of s2geometry
set(PACKAGES_PRIVATE
abseil curl draco ktx modp-base64 meshoptimizer openssl s2geometry
abseil draco ktx modp-base64 meshoptimizer openssl s2geometry
libjpeg-turbo sqlite3 tinyxml2 libwebp zlib-ng picosha2
earcut-hpp cpp-httplib[core] libmorton zstd
)

if(NOT CESIUM_TARGET_WASM)
list(APPEND PACKAGES_PRIVATE curl)
endif()

# Packages only used for testing
set(PACKAGES_TEST doctest)

if(CESIUM_TARGET_WASM)
# vcpkg will attempt to second-guess our CMAKE_C_COMPILER setting, choosing to go with the value of CC instead.
# While normally this is the correct value to go with, for wasm we need to be using emcc and em++.
# So we set CC and CXX to emcc and em++ here so vcpkg will pick them up properly.
# Does this make sense? No. Does it work? Somehow. ¯\_(ツ)_/¯
set(ENV{CC} ${CMAKE_C_COMPILER})
set(ENV{CXX} ${CMAKE_CXX_COMPILER})
endif()

if(CESIUM_USE_EZVCPKG)
set(PACKAGES_ALL ${PACKAGES_PUBLIC})
list(APPEND PACKAGES_ALL ${PACKAGES_PRIVATE})
Expand All @@ -112,6 +136,11 @@ if(CESIUM_USE_EZVCPKG)
# Force the installation of each package one at a time, or the Travis CI build will time out waiting for output
SERIALIZE
)

if(CESIUM_TARGET_WASM)
# vcpkg will attempt to make this wasm32-emscripten if we don't declare it
set(VCPKG_TARGET_TRIPLET wasm64-emscripten)
endif()
endif()

if (NOT CMAKE_TOOLCHAIN_FILE)
Expand All @@ -128,6 +157,14 @@ project(cesium-native
LANGUAGES CXX C
)

if(CESIUM_TARGET_WASM)
# YES we have sixty four bits!
set(CMAKE_SIZEOF_VOID_P 8)

# Tells emscripten to output an HTML harness for the generated WASM
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()

include(GNUInstallDirs)
include(CMakeDependentOption)

Expand Down Expand Up @@ -292,7 +329,6 @@ find_package(modp_b64 REQUIRED)

find_package(ada CONFIG REQUIRED)
find_package(Async++ CONFIG REQUIRED)
find_package(CURL REQUIRED)
find_package(doctest CONFIG REQUIRED)
find_package(draco CONFIG REQUIRED)
find_package(expected-lite CONFIG REQUIRED)
Expand All @@ -309,6 +345,10 @@ find_package(tinyxml2 CONFIG REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
find_package(WebP CONFIG REQUIRED)

if(NOT CESIUM_TARGET_WASM)
find_package(CURL REQUIRED)
endif()

# Private Library (s2geometry)
add_subdirectory(extern EXCLUDE_FROM_ALL)

Expand All @@ -334,7 +374,10 @@ add_subdirectory(CesiumIonClient)
add_subdirectory(CesiumITwinClient)
add_subdirectory(CesiumQuantizedMeshTerrain)
add_subdirectory(CesiumVectorData)
add_subdirectory(CesiumCurl)

if(NOT CESIUM_TARGET_WASM)
add_subdirectory(CesiumCurl)
endif()

# Private Targets
if (CESIUM_TESTS_ENABLED)
Expand Down
1 change: 1 addition & 0 deletions Cesium3DTilesContent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ target_link_libraries(Cesium3DTilesContent
CesiumGltfContent
CesiumGltfReader
CesiumUtility
spdlog::spdlog_header_only
PRIVATE
libmorton::libmorton
)
2 changes: 1 addition & 1 deletion Cesium3DTilesSelection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ target_link_libraries(Cesium3DTilesSelection
CesiumQuantizedMeshTerrain
CesiumRasterOverlays
CesiumUtility
spdlog::spdlog spdlog::spdlog_header_only
spdlog::spdlog_header_only
# PRIVATE
libmorton::libmorton
draco::draco
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ TEST_CASE("Future from loadSchema rejects if schemaUri can't be loaded") {
.thenInMainThread(
[&wasResolved](const TilesetMetadata*) { wasResolved = true; })
.catchInMainThread([&wasRejected](const std::exception& exception) {
INFO(exception.what());
CHECK(std::string(exception.what()).find("") != std::string::npos);
wasRejected = true;
});
Expand Down
2 changes: 1 addition & 1 deletion CesiumAsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cesium_target_include_directories(
target_link_libraries(CesiumAsync
PUBLIC
CesiumUtility
spdlog::spdlog spdlog::spdlog_header_only
spdlog::spdlog_header_only
Async++
PRIVATE
unofficial::sqlite3::sqlite3
Expand Down
4 changes: 3 additions & 1 deletion CesiumGltfWriter/test/TestGltfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ TEST_CASE("Writes glb with binaryChunkByteAlignment of 8") {
REQUIRE(glbBytesExtraPadding.size() == 88);
}

TEST_CASE("Reports an error if asked to write a GLB larger than 4GB") {
TEST_CASE(
"Reports an error if asked to write a GLB larger than 4GB" *
doctest::skip(true)) {
CesiumGltf::Model model;
model.asset.version = "2.0";
CesiumGltf::Buffer& buffer = model.buffers.emplace_back();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <CesiumJsonWriter/ExtensionWriterContext.h>
#include <CesiumJsonWriter/JsonWriter.h>

#include <spdlog/fmt/fmt.h>
#include <fmt/format.h>

namespace CesiumJsonWriter {

Expand Down
40 changes: 37 additions & 3 deletions CesiumNativeTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set(cesium_native_targets
Cesium3DTilesSelection
Cesium3DTilesWriter
CesiumAsync
CesiumCurl
CesiumGeometry
CesiumGeospatial
CesiumGltf
Expand All @@ -26,6 +25,10 @@ set(cesium_native_targets
CesiumUtility
)

if(NOT CESIUM_TARGET_WASM)
list(APPEND cesium_native_targets CesiumCurl)
endif()

cesium_glob_files(test_sources
${CMAKE_CURRENT_LIST_DIR}/src/*.cpp
)
Expand Down Expand Up @@ -72,6 +75,33 @@ foreach(target ${cesium_native_targets})
endif()
endforeach()

if(CESIUM_TARGET_WASM)
file(GLOB directories_list LIST_DIRECTORIES true "${CMAKE_SOURCE_DIR}/Cesium*")
foreach(dir ${directories_list})
if(IS_DIRECTORY ${dir}/test/data)
list(APPEND CESIUM_TEST_DATA_DIRS --embed)
list(APPEND CESIUM_TEST_DATA_DIRS "${dir}/test/data")
endif()
endforeach()

list(APPEND CESIUM_TEST_DATA_DIRS --embed)
list(APPEND CESIUM_TEST_DATA_DIRS "${CMAKE_SOURCE_DIR}/data")

message("${CESIUM_TEST_DATA_DIRS}")

set(CESIUM_NATIVE_TESTS_DATA_OBJ ${CMAKE_CURRENT_BINARY_DIR}/cesium-native-tests-data.o)
add_custom_target(
cesium-native-tests-data
COMMAND ${EMSCRIPTEN_ROOT_PATH}/tools/file_packager none.data --wasm64 ${CESIUM_TEST_DATA_DIRS} --obj-output=${CESIUM_NATIVE_TESTS_DATA_OBJ})

add_library(cesium-native-tests-data-lib OBJECT IMPORTED)
add_dependencies(cesium-native-tests-data-lib cesium-native-tests-data)
set_property(TARGET cesium-native-tests-data-lib PROPERTY IMPORTED_OBJECTS
"${CESIUM_NATIVE_TESTS_DATA_OBJ}")

list(APPEND cesium_native_targets cesium-native-tests-data-lib)
endif()

target_sources(
cesium-native-tests
PRIVATE
Expand All @@ -96,9 +126,13 @@ PRIVATE

target_compile_definitions(cesium-native-tests
PRIVATE
CESIUM_NATIVE_DATA_DIR=\"${CMAKE_CURRENT_LIST_DIR}/../data\"
CESIUM_NATIVE_DATA_DIR=\"${CMAKE_SOURCE_DIR}/data\"
)

include(CTest)
include(doctest)
doctest_discover_tests(cesium-native-tests)

if(NOT CESIUM_TARGET_WASM)
# doctest_discover_tests can't handle the target being an html file, so we just avoid it on a wasm build
doctest_discover_tests(cesium-native-tests)
endif()
1 change: 1 addition & 0 deletions CesiumRasterOverlays/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ target_link_libraries(CesiumRasterOverlays
CesiumGltfReader
CesiumUtility
nonstd::expected-lite
spdlog::spdlog_header_only
PRIVATE
tinyxml2::tinyxml2
)
2 changes: 1 addition & 1 deletion CesiumRasterOverlays/src/RasterOverlayTileProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <fmt/format.h>
#include <glm/ext/vector_double2.hpp>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>

#include <any>
#include <cstddef>
Expand Down
2 changes: 1 addition & 1 deletion CesiumRasterOverlays/src/RasterizedPolygonsOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <glm/common.hpp>
#include <glm/ext/vector_double2.hpp>
#include <glm/geometric.hpp>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>

#include <cstddef>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion CesiumRasterOverlays/src/TileMapServiceRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <glm/common.hpp>
#include <nonstd/expected.hpp>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>
#include <tinyxml2.h>

#include <cstddef>
Expand Down
2 changes: 1 addition & 1 deletion CesiumUtility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ target_link_libraries(
CesiumUtility
PUBLIC
zlib-ng::zlib-ng
spdlog::spdlog
spdlog::spdlog_header_only
glm::glm
ada::ada
)
Loading
Loading