-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.generate_compile_commands.sh
More file actions
executable file
·62 lines (49 loc) · 2 KB
/
Copy path.generate_compile_commands.sh
File metadata and controls
executable file
·62 lines (49 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#!/usr/bin/env bash
set -e
# ============================================================================
# Generate compile_commands.json for IDE integration (clangd, Pylance, etc.)
#
# This script generates the CMake compilation database for better IDE support.
# It works with the new CMake-based build system.
#
# Usage:
# ./generate_compile_commands.sh # Default (release mode)
# ./generate_compile_commands.sh rebuild # Force clean rebuild
# ============================================================================
# Configuration
BUILD_DIR="build-cmake"
FORCE_REBUILD="${1:-OFF}"
echo "▶ Generating compile_commands.json"
echo "▶ Build dir: ${BUILD_DIR}"
echo "▶ Force rebuild: ${FORCE_REBUILD}"
# Create build directory if it doesn't exist
if [ ! -d "${BUILD_DIR}" ]; then
echo "▶ Creating build directory..."
mkdir -p "${BUILD_DIR}"
fi
cd "${BUILD_DIR}"
# Clean build if requested
if [ "${FORCE_REBUILD}" = "rebuild" ]; then
echo "▶ Cleaning previous build..."
rm -rf CMakeFiles CMakeCache.txt cmake_install.cmake Makefile
fi
# Configure with CMake, ensuring compile commands are exported
echo "▶ Configuring CMake with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON..."
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. 2>&1 | tail -5
# Optional: Build to ensure all compilation paths are captured
# Uncomment if you want a full build (takes longer)
# echo "▶ Building to ensure full command generation..."
# make -j$(nproc) 2>&1 | tail -10
cd ..
# Copy compile_commands.json to repository root for IDE integration
if [ -f "${BUILD_DIR}/compile_commands.json" ]; then
cp "${BUILD_DIR}/compile_commands.json" ./compile_commands.json
echo "✔ compile_commands.json successfully generated and copied to repository root"
echo "✔ IDE tools (clangd, Pylance, etc.) should now have full C++ support"
exit 0
else
echo "✖ ERROR: compile_commands.json not found in ${BUILD_DIR}/"
echo "✖ CMake configuration may have failed. Check the output above."
exit 1
fi