Skip to content

Commit

Permalink
cmake: Use ExternalProject for Cesium
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Mar 8, 2024
1 parent 41c4feb commit d51500c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 50 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ jobs:
- name: Install Ninja
run: |
sudo apt update && sudo apt install ninja-build
- name: Install Conan
run: |
pip install conan
conan profile detect
- name: Install mapget (git+conan)
run: |
cd $(mktemp -d)
git clone "https://github.com/ndsev/mapget.git" -b conan-pkg
cd mapget
conan create . -o with_service=False -s compiler.cppstd=20 -b missing
- name: Build demo with Emscripten
run: |
$GITHUB_WORKSPACE/ci/00_linux_setup.bash
Expand Down
43 changes: 6 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.24)
include(FetchContent)
project(erdblick)

set(CMAKE_CXX_STANDARD 20)

Expand All @@ -13,45 +13,14 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif()

# External dependencies.

message("Building for ${CMAKE_SYSTEM_NAME}.")

find_package(glm REQUIRED)
find_package(mapget REQUIRED COMPONENTS model)
find_package(glm REQUIRED)
find_package(yaml-cpp REQUIRED)

FetchContent_Declare(mapget
GIT_REPOSITORY "https://github.com/Klebert-Engineering/mapget"
GIT_TAG "relations"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(mapget)

# Fetch cesium-native
set(CESIUM_TESTS_ENABLED OFF)
set(CESIUM_GLM_STRICT_ENABLED OFF)
set(CESIUM_TRACING_ENABLED OFF)
set(DRACO_JS_GLUE OFF CACHE BOOL "Disable JS glue for Draco" FORCE)
FetchContent_Declare(
cesiumnative
GIT_REPOSITORY https://github.com/Klebert-Engineering/cesium-native.git
GIT_TAG "spdlog-upgrade"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(cesiumnative)

if (NOT TARGET mapget)
if (MAPGET_DIR)
FetchContent_Declare(mapget
SOURCE_DIR "${MAPGET_DIR}"
PATCH_COMMAND conan install "${MAPGET_DIR}" -of "${CMAKE_BINARY_DIR}" --build=missing)
else()
FetchContent_Declare(mapget
GIT_REPOSITORY "https://github.com/Klebert-Engineering/mapget"
GIT_TAG "main"
GIT_SHALLOW ON
PATCH_COMMAND conan install "${MAPGET_DIR}" -of "${CMAKE_BINARY_DIR}" --build=missing)
endif()
FetchContent_MakeAvailable(mapget)
endif()
# Cesium
include(cmake/cesium.cmake)

message("Building for ${CMAKE_SYSTEM_NAME}.")
add_subdirectory(libs/core)

if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
Expand Down
2 changes: 1 addition & 1 deletion ci/00_linux_setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ mkdir -p build/deps
mkdir -p build/assets

conan install . -pr:b default -pr:h conan-profiles/emscripten.profile \
-s build_type=Release -b missing -of build
-s build_type=Release -s compiler.cppstd=20 -b missing -of build
9 changes: 2 additions & 7 deletions ci/10_linux_build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ set -e
source "./build/conanbuild.sh"

set -eu

cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CONAN=OFF \
-DCMAKE_BUILD_TYPE=Release

cmake --build build -- -j
cmake --preset conan-release
cmake --build --preset conan-release -- -j
3 changes: 1 addition & 2 deletions ci/20_linux_rebuild.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env bash
set -eu

cmake --build build -- -j
cmake --build --preset conan-release -- -j
45 changes: 45 additions & 0 deletions cmake/cesium.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
include(FetchContent)
include(ExternalProject)

# Use fetch content for cloning the repository durring
# configure phase. We do not call `FetchContent_MakeAvailable`,
# but instead use `ExternalProject_Add` to compile Cesium in
# isolation.
FetchContent_Declare(cesiumnative_src
GIT_REPOSITORY "https://github.com/Klebert-Engineering/cesium-native.git"
GIT_TAG "main"
GIT_SUBMODULES_RECURSE YES
GIT_PROGRESS YES)

FetchContent_GetProperties(cesiumnative_src)
if (NOT cesiumnative_src_POPULATED)
FetchContent_Populate(cesiumnative_src)
endif()

ExternalProject_Add(cesiumnative
SOURCE_DIR ${cesiumnative_src_SOURCE_DIR}
CMAKE_ARGS
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCESIUM_TESTS_ENABLED=OFF
-DCESIUM_GLM_STRICT_ENABLED=OFF
-DCESIUM_TRACING_ENABLED=OFF
-DDRACO_JS_GLUE=OFF
#-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} # FIXME: Is this needed?
INSTALL_COMMAND "")

function (add_cesium_lib TARGET)
message(STATUS "Adding Cesium library: ${TARGET}")
ExternalProject_Get_Property(cesiumnative
SOURCE_DIR BINARY_DIR)

add_library(${TARGET} SHARED IMPORTED)
set_target_properties(${TARGET} PROPERTIES
IMPORTED_LOCATION "${BINARY_DIR}/${TARGET}/${CMAKE_STATIC_LIBRARY_PREFIX}${TARGET}${CMAKE_STATIC_LIBRARY_SUFFIX}"
INTERFACE_INCLUDE_DIRECTORIES "${SOURCE_DIR}/${TARGET}/include")
endfunction()

add_cesium_lib(CesiumUtility)
add_cesium_lib(Cesium3DTilesWriter)
add_cesium_lib(CesiumGeospatial)
add_cesium_lib(CesiumGltf)
add_cesium_lib(CesiumGltfWriter)
4 changes: 4 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[requires]
mapget/dev
glm/cci.20230113
yaml-cpp/0.8.0

[options]
mapget/*:with_service=False

[generators]
CMakeDeps
CMakeToolchain
7 changes: 4 additions & 3 deletions libs/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ target_link_libraries(erdblick-core
CesiumGeospatial
CesiumGltf
CesiumGltfWriter
glm
mapget-model
yaml-cpp)
CesiumUtility
glm::glm
mapget::model
yaml-cpp::yaml-cpp)

add_custom_target(erdblick-ui ALL
COMMAND bash "${CMAKE_SOURCE_DIR}/build-ui.bash" "${CMAKE_SOURCE_DIR}"
Expand Down

0 comments on commit d51500c

Please sign in to comment.