-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·174 lines (150 loc) · 4.43 KB
/
build.sh
File metadata and controls
executable file
·174 lines (150 loc) · 4.43 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
# Genetic Algorithm Framework Build Script
# This script provides a simple way to build the project using CMake
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if CMake is available
check_cmake() {
if ! command -v cmake &> /dev/null; then
print_error "CMake is not installed. Please install CMake first."
echo "Ubuntu/Debian: sudo apt install cmake"
echo "macOS: brew install cmake"
echo "Windows: Download from https://cmake.org/download/"
exit 1
fi
print_success "CMake found: $(cmake --version | head -n1)"
}
# Check if C++ compiler is available
check_compiler() {
if command -v g++ &> /dev/null; then
print_success "GCC found: $(g++ --version | head -n1)"
elif command -v clang++ &> /dev/null; then
print_success "Clang found: $(clang++ --version | head -n1)"
else
print_error "No C++ compiler found. Please install a C++17 compatible compiler."
echo "Ubuntu/Debian: sudo apt install build-essential"
echo "macOS: xcode-select --install"
exit 1
fi
}
# Parse command line arguments
BUILD_TYPE="Release"
CLEAN_BUILD=false
RUN_TESTS=false
INSTALL=false
VERBOSE=false
while [[ $# -gt 0 ]]; do
case $1 in
--debug)
BUILD_TYPE="Debug"
shift
;;
--clean)
CLEAN_BUILD=true
shift
;;
--run)
RUN_TESTS=true
shift
;;
--install)
INSTALL=true
shift
;;
--verbose)
VERBOSE=true
shift
;;
--help|-h)
echo "Genetic Algorithm Framework Build Script"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --debug Build in debug mode"
echo " --clean Clean build directory before building"
echo " --run Run tests after building"
echo " --install Install to system after building"
echo " --verbose Verbose output"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 # Build in release mode"
echo " $0 --debug --run # Build in debug mode and run tests"
echo " $0 --clean --verbose # Clean build with verbose output"
exit 0
;;
*)
print_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Main build function
main() {
print_status "Starting build process..."
# Check prerequisites
check_cmake
check_compiler
# Create build directory
if [ "$CLEAN_BUILD" = true ]; then
print_status "Cleaning build directory..."
rm -rf build
fi
mkdir -p build
cd build
# Configure with CMake
print_status "Configuring with CMake (Build type: $BUILD_TYPE)..."
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=$BUILD_TYPE"
if [ "$VERBOSE" = true ]; then
CMAKE_ARGS="$CMAKE_ARGS --debug-output"
fi
cmake .. $CMAKE_ARGS
# Build the project
print_status "Building project..."
BUILD_ARGS=""
if [ "$VERBOSE" = true ]; then
BUILD_ARGS="--verbose"
fi
cmake --build . $BUILD_ARGS
print_success "Build completed successfully!"
# Run tests if requested
if [ "$RUN_TESTS" = true ]; then
print_status "Running tests..."
if [ -f "bin/simple_ga_test" ]; then
./bin/simple_ga_test
else
print_error "Executable not found: bin/simple_ga_test"
exit 1
fi
fi
# Install if requested
if [ "$INSTALL" = true ]; then
print_status "Installing to system..."
sudo cmake --build . --target install
print_success "Installation completed!"
fi
print_success "All tasks completed successfully!"
print_status "Executable location: build/bin/simple_ga_test"
}
# Run main function
main "$@"