chore: 工程工具 + CMake 修复
- tools/build.sh: 一键编译(支持 Release/Debug/ASan) - tools/run_tests.sh: 运行测试 - tools/release.sh: 发布打包 - tools/format.sh: 代码格式化 - tools/clean.sh: 清理构建产物 - 修复 CMakeLists.txt: vde_compile_options 顺序错误 - 修复 src/CMakeLists.txt: 移除重复配置行
This commit is contained in:
+15
-26
@@ -6,21 +6,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# ── 选项 ──────────────────────────────────────────
|
||||
option(BUILD_TESTS "Build unit tests" ON)
|
||||
option(BUILD_EXAMPLES "Build examples" ON)
|
||||
# ── 选项 ──
|
||||
option(BUILD_TESTS "Build unit tests" ON)
|
||||
option(BUILD_EXAMPLES "Build examples" ON)
|
||||
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared library" OFF)
|
||||
option(ENABLE_SANITIZERS "Enable ASan/UBSan" OFF)
|
||||
option(ENABLE_LTO "Enable LTO" ON)
|
||||
option(VDE_BUILD_PYTHON "Build Python bindings" OFF)
|
||||
|
||||
# ── 编译设置 ──────────────────────────────────────
|
||||
# ── 编译选项接口(必须在 include(CompilerSettings) 之前创建)──
|
||||
add_library(vde_compile_options INTERFACE)
|
||||
include(cmake/CompilerSettings.cmake)
|
||||
|
||||
# ── 依赖 ──────────────────────────────────────────
|
||||
# ── 依赖 ──
|
||||
find_package(Eigen3 3.3 QUIET)
|
||||
if(NOT Eigen3_FOUND)
|
||||
message(STATUS "Eigen3 not found — using FetchContent")
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(Eigen3
|
||||
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
|
||||
@@ -28,11 +29,10 @@ if(NOT Eigen3_FOUND)
|
||||
FetchContent_MakeAvailable(Eigen3)
|
||||
endif()
|
||||
|
||||
# ── 子目录 ────────────────────────────────────────
|
||||
# ── 子目录 ──
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(src)
|
||||
|
||||
# ── 测试 ──────────────────────────────────────────
|
||||
# ── 测试 ──
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
find_package(GTest QUIET)
|
||||
@@ -47,28 +47,17 @@ if(BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
# ── 示例 ──────────────────────────────────────────
|
||||
# ── Python 绑定 ────────────────────────────────────option(VDE_BUILD_PYTHON "Build Python bindings (pybind11)" OFF)if(VDE_BUILD_PYTHON) add_subdirectory(python)endif()
|
||||
# ── 示例 ──
|
||||
if(BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
# ── 性能测试 ──────────────────────────────────────
|
||||
# ── 性能测试 ──
|
||||
if(BUILD_BENCHMARKS)
|
||||
find_package(benchmark QUIET)
|
||||
if(NOT benchmark_FOUND)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(googlebenchmark
|
||||
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.0.tar.gz
|
||||
)
|
||||
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googlebenchmark)
|
||||
endif()
|
||||
add_subdirectory(benchmarks)
|
||||
endif()
|
||||
|
||||
# ── 安装 ──────────────────────────────────────────
|
||||
include(GNUInstallDirs)
|
||||
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install(TARGETS vde EXPORT ViewDesignEngine-targets)
|
||||
install(EXPORT ViewDesignEngine-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ViewDesignEngine)
|
||||
# ── Python 绑定 ──
|
||||
if(VDE_BUILD_PYTHON)
|
||||
add_subdirectory(python)
|
||||
endif()
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
# ── 编译选项接口目标 ──────────────────────────────
|
||||
add_library(vde_compile_options INTERFACE)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/CompilerSettings.cmake)
|
||||
|
||||
# ── foundation ─────────────────────────────────────
|
||||
add_library(vde_foundation STATIC
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
BUILD_TYPE="${BUILD_TYPE:-Release}"
|
||||
BUILD_DIR="${BUILD_DIR:-build}"
|
||||
JOBS="${JOBS:-$(nproc)}"
|
||||
ENABLE_TESTS="${ENABLE_TESTS:-ON}"
|
||||
ENABLE_SANITIZERS="${ENABLE_SANITIZERS:-OFF}"
|
||||
|
||||
echo "=== ViewDesignEngine Build ==="
|
||||
echo " Build Type: $BUILD_TYPE"
|
||||
echo " Build Dir: $BUILD_DIR"
|
||||
echo " Jobs: $JOBS"
|
||||
echo " Tests: $ENABLE_TESTS"
|
||||
echo " Sanitizers: $ENABLE_SANITIZERS"
|
||||
echo ""
|
||||
|
||||
cmake -B "$BUILD_DIR" \
|
||||
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
|
||||
-DBUILD_TESTS="$ENABLE_TESTS" \
|
||||
-DBUILD_EXAMPLES=ON \
|
||||
-DENABLE_SANITIZERS="$ENABLE_SANITIZERS" \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
|
||||
cmake --build "$BUILD_DIR" -j"$JOBS"
|
||||
|
||||
echo ""
|
||||
echo "=== Build Complete ==="
|
||||
echo "Libraries: $BUILD_DIR/src/libvde*.a"
|
||||
echo "Executables: $BUILD_DIR/tests/"
|
||||
echo "Examples: $BUILD_DIR/examples/"
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
rm -rf build build-release build-debug build-asan release
|
||||
echo "Cleaned build artifacts."
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "=== Clang Format ==="
|
||||
find src include tests examples -name "*.cpp" -o -name "*.h" | while read f; do
|
||||
clang-format -i "$f" 2>/dev/null && echo " formatted: $f" || true
|
||||
done
|
||||
echo "Done."
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
VERSION="${1:-$(date +%Y%m%d)}"
|
||||
RELEASE_NAME="ViewDesignEngine-${VERSION}"
|
||||
BUILD_DIR="build-release"
|
||||
|
||||
echo "=== ViewDesignEngine Release $VERSION ==="
|
||||
|
||||
# Clean build
|
||||
rm -rf "$BUILD_DIR"
|
||||
|
||||
# Build release
|
||||
BUILD_DIR="$BUILD_DIR" BUILD_TYPE=Release ENABLE_TESTS=ON bash tools/build.sh
|
||||
|
||||
# Run tests
|
||||
echo ""
|
||||
echo "=== Running Tests ==="
|
||||
BUILD_DIR="$BUILD_DIR" bash tools/run_tests.sh
|
||||
|
||||
# Package
|
||||
echo ""
|
||||
echo "=== Packaging ==="
|
||||
mkdir -p release
|
||||
PACKAGE_DIR="release/$RELEASE_NAME"
|
||||
rm -rf "$PACKAGE_DIR"
|
||||
mkdir -p "$PACKAGE_DIR"/{lib,include,bin,docs}
|
||||
|
||||
# Headers
|
||||
cp -r include/vde "$PACKAGE_DIR/include/"
|
||||
|
||||
# Libraries
|
||||
find "$BUILD_DIR/src" -name "libvde*.a" -exec cp {} "$PACKAGE_DIR/lib/" \;
|
||||
|
||||
# Examples
|
||||
for exe in "$BUILD_DIR"/examples/*/*; do
|
||||
if [ -x "$exe" ] && [ ! -d "$exe" ]; then
|
||||
cp "$exe" "$PACKAGE_DIR/bin/"
|
||||
fi
|
||||
done
|
||||
|
||||
# Docs
|
||||
cp -r docs "$PACKAGE_DIR/"
|
||||
cp README.md LICENSE CHANGELOG.md "$PACKAGE_DIR/"
|
||||
|
||||
# Archive
|
||||
cd release
|
||||
tar -czf "${RELEASE_NAME}-linux-x64.tar.gz" "$RELEASE_NAME"
|
||||
echo ""
|
||||
echo "=== Release Package ==="
|
||||
ls -lh "${RELEASE_NAME}-linux-x64.tar.gz"
|
||||
echo " $PWD/${RELEASE_NAME}-linux-x64.tar.gz"
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
BUILD_DIR="${BUILD_DIR:-build}"
|
||||
|
||||
if [ ! -d "$BUILD_DIR" ]; then
|
||||
echo "Build directory not found. Run tools/build.sh first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=== ViewDesignEngine Tests ==="
|
||||
cd "$BUILD_DIR"
|
||||
ctest --output-on-failure -j"$(nproc)" "$@"
|
||||
Reference in New Issue
Block a user