migration: add install_bgviewer.sh; make FindBgViewer search ./external/BgViewer and respect BGVIEWER_DIR

This commit is contained in:
Copilot authored and Torsten Wierschin committed 2026-07-20 13:10:36 +02:00
1 parent 2a3bfb7aea
commit a31ae77087
2 files changed
+66 -12

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
# install_bgviewer.sh
# Extract or copy a BgViewer/dtEntity vendor archive or directory into ./external/BgViewer
# Usage: ./install_bgviewer.sh /path/to/bgviewer.tar.gz_or_dir [target_dir]
SRC="$1"
TARGET_DIR="${2:-./external/BgViewer}"
if [[ -z "$SRC" ]]; then
echo "Usage: $0 /path/to/bgviewer.tar.gz_or_dir [target_dir]"
exit 1
fi
# Create target dir (prefer non-root)
if ! mkdir -p "$TARGET_DIR" 2>/dev/null; then
sudo mkdir -p "$TARGET_DIR"
fi
if ! chown $(id -u):$(id -g) "$TARGET_DIR" 2>/dev/null; then
sudo chown $(id -u):$(id -g) "$TARGET_DIR" || true
fi
if [[ -d "$SRC" ]]; then
echo "Copying BgViewer directory $SRC -> $TARGET_DIR"
rsync -a --delete "$SRC/" "$TARGET_DIR/"
elif [[ -f "$SRC" ]]; then
echo "Extracting archive $SRC -> $TARGET_DIR"
case "$SRC" in
*.tar.gz|*.tgz) tar xzf "$SRC" -C "$TARGET_DIR" --strip-components=1 ;;
*.tar.bz2) tar xjf "$SRC" -C "$TARGET_DIR" --strip-components=1 ;;
*.zip) unzip -q "$SRC" -d "$TARGET_DIR" ;;
*) echo "Unknown archive format: $SRC"; exit 1 ;;
esac
else
echo "Source $SRC not found" >&2
exit 1
fi
echo "BgViewer installed to $TARGET_DIR"
echo "You may set -DBGVIEWER_DIR=$TARGET_DIR or ensure CMAKE_PREFIX_PATH includes $TARGET_DIR when configuring CMake."
+25 -12
View File
@@ -21,16 +21,29 @@
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
INCLUDE(FindLibraryWithDebug) INCLUDE(FindLibraryWithDebug)
FIND_LIBRARY_WITH_DEBUG(BGVIEWER_DTENTITY_LIBRARY WIN32_DEBUG_POSTFIX d dtEntity) # Allow user to supply BGVIEWER_DIR or check ./external/BgViewer by default
FIND_LIBRARY_WITH_DEBUG(BGVIEWER_DTENTITYOSG_LIBRARY WIN32_DEBUG_POSTFIX d dtEntityOSG) if(NOT DEFINED BGVIEWER_DIR)
FIND_PATH(BGVIEWER_INCLUDE_DIR dtEntity/export.h) if(DEFINED ENV{EXTERNAL_DIR})
set(_external_hint "$ENV{EXTERNAL_DIR}")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(BgViewer DEFAULT_MSG else()
BGVIEWER_DTENTITY_LIBRARY set(_external_hint "${CMAKE_SOURCE_DIR}/external")
BGVIEWER_DTENTITYOSG_LIBRARY endif()
BGVIEWER_INCLUDE_DIR) set(BGVIEWER_DIR "${_external_hint}/BgViewer" CACHE PATH "BgViewer root directory (optional)")
SET(BGVIEWER_LIBRARIES ${BGVIEWER_DTENTITYOSG_LIBRARY} endif()
# Search in common system locations and in BGVIEWER_DIR
set(_hints "${BGVIEWER_DIR}/lib" "${BGVIEWER_DIR}/lib/*" "${BGVIEWER_DIR}/lib/*/*")
FIND_LIBRARY_WITH_DEBUG(BGVIEWER_DTENTITY_LIBRARY WIN32_DEBUG_POSTFIX d dtEntity HINTS ${_hints})
FIND_LIBRARY_WITH_DEBUG(BGVIEWER_DTENTITYOSG_LIBRARY WIN32_DEBUG_POSTFIX d dtEntityOSG HINTS ${_hints})
FIND_PATH(BGVIEWER_INCLUDE_DIR dtEntity/export.h HINTS "${BGVIEWER_DIR}/include" "${BGVIEWER_DIR}/include/dtEntity" ${_hints} )
FIND_PACKAGE_HANDLE_STANDARD_ARGS(BgViewer DEFAULT_MSG
BGVIEWER_DTENTITY_LIBRARY
BGVIEWER_DTENTITYOSG_LIBRARY
BGVIEWER_INCLUDE_DIR)
SET(BGVIEWER_LIBRARIES ${BGVIEWER_DTENTITYOSG_LIBRARY}
${BGVIEWER_DTENTITY_LIBRARY}) ${BGVIEWER_DTENTITY_LIBRARY})