Skip to content

Instantly share code, notes, and snippets.

@ojroques
Last active January 30, 2023 13:43
Show Gist options
  • Save ojroques/9824c85cfd1eabafb3c0be5530c35b5a to your computer and use it in GitHub Desktop.
Save ojroques/9824c85cfd1eabafb3c0be5530c35b5a to your computer and use it in GitHub Desktop.
buildme.sh for CMake
#!/bin/bash
set -e
SOURCE_DIR=$(cd "$(dirname "$0")" && pwd)
BUILD_DIR="$SOURCE_DIR"/build
# Options
CMAKE_BUILD_TYPE="RELEASE"
# Remove old build environment
if [[ "$1" == "--force" ]]; then
rm -rf "$BUILD_DIR"
fi
# Generate build environment
cmake -S "$SOURCE_DIR" -B "$BUILD_DIR" \
-D CMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
-D CMAKE_EXPORT_COMPILE_COMMANDS="ON"
# Build
cmake --build "$BUILD_DIR" --parallel
# Install
sudo cmake --install "$BUILD_DIR"
# Link compile commands
ln -sfv "$BUILD_DIR"/compile_commands.json "$SOURCE_DIR"/compile_commands.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment