ScreenLockDetector/build_mac.sh

118 lines
3.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# macOS Build Script for ScreenLockDetector
# This script builds the project on macOS
set -e # Exit on error
echo "=========================================="
echo "Building ScreenLockDetector for macOS"
echo "=========================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if we're on macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
echo -e "${RED}Error: This script is for macOS only${NC}"
exit 1
fi
# Function to find Qt installation
find_qt() {
# Try to find Qt in common locations
QT_PATHS=(
"/opt/local" # MacPorts
"/usr/local/opt/qt@5" # Homebrew (Intel)
"/opt/homebrew/opt/qt@5" # Homebrew (Apple Silicon)
"$HOME/Qt/5.15.2/clang_64" # Official Qt installer
"$HOME/sdk/qt-5.15.2" # Custom installation
)
for path in "${QT_PATHS[@]}"; do
if [ -d "$path" ]; then
# Check if Qt cmake files exist
if [ -f "$path/lib/cmake/Qt5/Qt5Config.cmake" ]; then
echo "$path"
return 0
fi
fi
done
return 1
}
# Find Qt installation
echo "Searching for Qt installation..."
QT_PATH=$(find_qt)
if [ -z "$QT_PATH" ]; then
echo -e "${YELLOW}Warning: Qt not found in common locations${NC}"
echo "Please install Qt 5 using one of these methods:"
echo " 1. MacPorts: sudo port install qt5"
echo " 2. Homebrew: brew install qt@5"
echo " 3. Official installer: https://www.qt.io/download"
echo ""
echo "Or set Qt5_DIR environment variable manually:"
echo " export Qt5_DIR=/path/to/qt/lib/cmake/Qt5"
# Ask user if they want to continue anyway
read -p "Do you want to continue and let CMake search for Qt? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
else
echo -e "${GREEN}Found Qt at: $QT_PATH${NC}"
export Qt5_DIR="$QT_PATH/lib/cmake/Qt5"
fi
# Create build directory
BUILD_DIR="build"
if [ -d "$BUILD_DIR" ]; then
echo "Cleaning existing build directory..."
rm -rf "$BUILD_DIR"
fi
echo "Creating build directory..."
mkdir -p "$BUILD_DIR"
# Run CMake
echo ""
echo "Running CMake configuration..."
cd "$BUILD_DIR"
if [ -n "$Qt5_DIR" ]; then
cmake .. -DCMAKE_BUILD_TYPE=Release -DQt5_DIR="$Qt5_DIR"
else
cmake .. -DCMAKE_BUILD_TYPE=Release
fi
# Build the project
echo ""
echo "Building project..."
make -j$(sysctl -n hw.ncpu)
# Check if build succeeded
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}=========================================="
echo "Build completed successfully!"
echo "==========================================${NC}"
echo ""
echo "Executable location: $BUILD_DIR/bin/ScreenLockDetector"
echo ""
echo "To run the application:"
echo " ./run_mac.sh"
echo " or"
echo " ./build/bin/ScreenLockDetector"
else
echo -e "${RED}=========================================="
echo "Build failed!"
echo "==========================================${NC}"
exit 1
fi