diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index ad30e3b0..4545e2c9 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -14,15 +14,26 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: '21.x' - cache: "npm" - cache-dependency-path: package-lock.json + - name: Install Ninja + run: | + sudo apt update && sudo apt install ninja-build - - name: Install npm dependencies - run: npm -g install --force --include=dev + - name: Install Conan + run: | + pip install conan + conan profile detect + conan --version + + - name: Install mapget (git+conan) + run: | + cd $(mktemp -d) + git clone "https://github.com/ndsev/mapget.git" -b use-conan + cd mapget + conan create . -s compiler.cppstd=20 -s build_type=Release -b missing \ + -pr:b default -pr:h "$GITHUB_WORKSPACE/conan-profiles/emscripten.profile" \ + -o with_httplib=False \ + -o with_service=False \ + -o with_wheel=False - name: Build demo with Emscripten run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fcea767..f93890c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.24) -project(erdblick) -include(FetchContent) +project(erdblick CXX) set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) # Treat warnings as errors, with some exceptions for Cesium. set (ERDBLICK_CXX_FLAGS @@ -15,40 +15,14 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() # External dependencies. +find_package(mapget CONFIG REQUIRED COMPONENTS model) +find_package(glm CONFIG REQUIRED) +find_package(yaml-cpp CONFIG REQUIRED) -message("Building for ${CMAKE_SYSTEM_NAME}.") - -FetchContent_Declare(glm - GIT_REPOSITORY "https://github.com/g-truc/glm.git" - GIT_TAG "0.9.9.8" - GIT_SHALLOW ON) -FetchContent_MakeAvailable(glm) - -FetchContent_Declare(mapget - GIT_REPOSITORY "https://github.com/Klebert-Engineering/mapget" - GIT_TAG "main" - GIT_SHALLOW ON) -FetchContent_MakeAvailable(mapget) - -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) - -FetchContent_Declare(yaml-cpp - GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git" - GIT_TAG "yaml-cpp-0.7.0" - GIT_SHALLOW ON) -FetchContent_MakeAvailable(yaml-cpp) - -# Erdblick Core Library +# Cesium +include(cmake/cesium.cmake) +message("Building for ${CMAKE_SYSTEM_NAME}.") add_subdirectory(libs/core) if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten") diff --git a/build-ui.bash b/build-ui.bash index 555e7f33..02c46e79 100755 --- a/build-ui.bash +++ b/build-ui.bash @@ -1,21 +1,22 @@ #!/usr/bin/env bash +set -eu -SOURCE_LOC=$1 -if [ -z $SOURCE_LOC ]; then +SOURCE_LOC="$1" + +if [ -z "$SOURCE_LOC" ]; then echo "No source location supplied." exit 1 fi echo "Using source dir @ $SOURCE_LOC." -cd "$SOURCE_LOC" || exit 1 +cd "$SOURCE_LOC" echo "Collecting npm modules." npm install echo "Building Angular distribution files." -if [[ -z "$NG_DEVELOP" ]]; then +if [[ -z "${NG_DEVELOP:-}" ]]; then npm run build -- -c production else npm run build fi -exit 0 diff --git a/ci/00_linux_setup.bash b/ci/00_linux_setup.bash index ead6317a..8b3b89de 100755 --- a/ci/00_linux_setup.bash +++ b/ci/00_linux_setup.bash @@ -1,12 +1,15 @@ #!/usr/bin/env bash +set -eu -ci_dir="$(realpath ${BASH_SOURCE[0]} | xargs -I{} dirname {})" -echo "Setting up Emscripten in: $ci_dir" -cd "$ci_dir" +BUILD_DIR="./build" +PROFILE_DIR="./conan-profiles" -git clone https://github.com/emscripten-core/emsdk.git -cd emsdk -git pull -./emsdk install latest -./emsdk activate latest -source ./emsdk_env.sh +rm -rf "$BUILD_DIR" +mkdir -p "$BUILD_DIR/deps" +mkdir -p "$BUILD_DIR/assets" + +conan install . \ + -pr:b "$PROFILE_DIR/build.profile" \ + -pr:h "$PROFILE_DIR/emscripten.profile" \ + -s build_type=Release -s compiler.cppstd=20 -b missing -b editable \ + -of "$BUILD_DIR" diff --git a/ci/10_linux_build.bash b/ci/10_linux_build.bash index 6f530fb2..2000f8c9 100755 --- a/ci/10_linux_build.bash +++ b/ci/10_linux_build.bash @@ -1,16 +1,7 @@ #!/usr/bin/env bash - set -e +source "./build/conanbuild.sh" -ci_dir="$(realpath ${BASH_SOURCE[0]} | xargs -I{} dirname {})" -source "$ci_dir/emsdk/emsdk_env.sh" -cd "$ci_dir/.." - -export EMSCRIPTEN="$ci_dir/emsdk/upstream/emscripten" - -rm -rf build && mkdir build -cd build -mkdir deps -mkdir assets -emcmake cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF .. -cmake --build . -- -j +set -eu +cmake --preset conan-release +cmake --build --preset conan-release -- -j diff --git a/ci/20_linux_rebuild.bash b/ci/20_linux_rebuild.bash index ebb72791..0affa5ed 100755 --- a/ci/20_linux_rebuild.bash +++ b/ci/20_linux_rebuild.bash @@ -1,11 +1,3 @@ #!/usr/bin/env bash - -set -e - -ci_dir="$(realpath ${BASH_SOURCE[0]} | xargs -I{} dirname {})" -source "$ci_dir/emsdk/emsdk_env.sh" - -export EMSCRIPTEN="$ci_dir/emsdk/upstream/emscripten" - -cd "$ci_dir/../build" -cmake --build . -- -j +set -eu +cmake --build --preset conan-release -- -j diff --git a/cmake/cesium.cmake b/cmake/cesium.cmake new file mode 100644 index 00000000..eae95cd4 --- /dev/null +++ b/cmake/cesium.cmake @@ -0,0 +1,48 @@ +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 + -DBUILD_SHARED_LIBS=OFF + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + INSTALL_COMMAND "" + STEP_TARGETS build) + +function (add_cesium_lib TARGET) + ExternalProject_Get_Property(cesiumnative + SOURCE_DIR BINARY_DIR) + message(STATUS "Adding Cesium library: ${TARGET} (${BINARY_DIR}/${TARGET}/${CMAKE_STATIC_LIBRARY_PREFIX}${TARGET}${CMAKE_STATIC_LIBRARY_SUFFIX})") + + add_library(${TARGET} STATIC 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") + add_dependencies(${TARGET} cesiumnative-build) +endfunction() + +add_cesium_lib(CesiumUtility) +add_cesium_lib(Cesium3DTilesWriter) +add_cesium_lib(CesiumGeospatial) +add_cesium_lib(CesiumGltf) +add_cesium_lib(CesiumGltfWriter) diff --git a/conan-profiles/build.profile b/conan-profiles/build.profile new file mode 100644 index 00000000..f2d691f0 --- /dev/null +++ b/conan-profiles/build.profile @@ -0,0 +1,7 @@ +include(default) + +[settings] +compiler.cppstd=20 + +[replace_requires] +nodejs/*: nodejs/18.15.0 diff --git a/conan-profiles/emscripten.profile b/conan-profiles/emscripten.profile new file mode 100644 index 00000000..e86313df --- /dev/null +++ b/conan-profiles/emscripten.profile @@ -0,0 +1,12 @@ +[settings] +os=Emscripten +arch=wasm +compiler=clang +compiler.version=15 +compiler.libcxx=libc++ +compiler.cppstd=20 + +[tool_requires] +# See https://github.com/emscripten-core/emsdk/blob/3.1.47/emscripten-releases-tags.json +# for latest version with linux-arm64 support +emsdk/3.1.50 diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 00000000..a6a32ac2 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,13 @@ +[requires] +mapget/dev +glm/cci.20230113 +yaml-cpp/0.8.0 + +[options] +mapget/*:with_service=False +mapget/*:with_httplib=False +mapget/*:with_wheel=False + +[generators] +CMakeDeps +CMakeToolchain diff --git a/libs/core/CMakeLists.txt b/libs/core/CMakeLists.txt index ca891874..3814c5d2 100644 --- a/libs/core/CMakeLists.txt +++ b/libs/core/CMakeLists.txt @@ -70,6 +70,7 @@ target_link_libraries(erdblick-core CesiumGeospatial CesiumGltf CesiumGltfWriter - glm - mapget-model - yaml-cpp) + CesiumUtility + glm::glm + mapget::model + yaml-cpp::yaml-cpp)