Skip to content

Commit 04e6461

Browse files
authored
Merge pull request #11 from monkey0722/update/settings
feat: Enhance CMake and build scripts with improved configuration
2 parents ac8b0ab + 2eacebd commit 04e6461

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

CMakeLists.txt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,56 @@ project(CLAVIS LANGUAGES CXX)
44
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_CXX_STANDARD_REQUIRED True)
66

7-
# Collect Source Files
7+
# Set build type (default is Debug)
8+
if(NOT CMAKE_BUILD_TYPE)
9+
set(CMAKE_BUILD_TYPE Debug)
10+
endif()
11+
12+
# Basic compiler flags
13+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
15+
endif()
16+
17+
# Collect source files
818
file(GLOB CORE_SOURCES
919
src/*.cpp
1020
src/graph/*.hpp
1121
src/data_structure/*.hpp
1222
src/sorting/*.hpp
1323
)
1424

15-
# Collect Test Files
25+
# Collect test files
1626
file(GLOB TEST_SOURCES
1727
tests/*.cpp
1828
tests/graph/*.cpp
1929
tests/data_structure/*.cpp
2030
tests/sorting/*.cpp
2131
)
2232

23-
# Integrate All Sources
33+
# Combine all sources
2434
set(SOURCES ${CORE_SOURCES})
2535

26-
# Create Library
36+
# Create library
2737
add_library(clavis_algorithm ${SOURCES})
2838

29-
# Google Test Setup
39+
# Set include directories
40+
target_include_directories(clavis_algorithm PUBLIC
41+
${CMAKE_SOURCE_DIR}/src
42+
)
43+
44+
# Google Test configuration
3045
find_package(GTest REQUIRED)
3146
enable_testing()
3247

33-
# Test Execution File
48+
# Test executable
3449
add_executable(clavis_algorithm_test ${TEST_SOURCES})
3550

36-
# Include Directories
51+
# Set include directories for tests
3752
target_include_directories(clavis_algorithm_test PRIVATE
3853
${CMAKE_SOURCE_DIR}/src
3954
)
4055

4156
target_link_libraries(clavis_algorithm_test clavis_algorithm GTest::GTest GTest::Main)
4257

43-
# Register Test
58+
# Register test
4459
add_test(NAME AlgorithmTest COMMAND clavis_algorithm_test)

scripts/build_debug.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ print_usage() {
88
echo "Options:"
99
echo " -c, --clean Remove old executable before building"
1010
echo " -r, --run Run program after building"
11+
echo " -j, --jobs N Compile with N parallel jobs (default: all cores)"
1112
echo " -h, --help Show this help message"
1213
echo ""
1314
echo "Example: $0 sort.cpp -r"
1415
}
1516

16-
# Set default values
17+
# Set default values
1718
CLEAN_MODE=0
1819
RUN_AFTER_BUILD=0
20+
NUM_JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
1921

2022
# Create build directory
2123
BUILD_DIR="build"
2224
if [ ! -d "$BUILD_DIR" ]; then
2325
mkdir -p "$BUILD_DIR"
2426
fi
2527

26-
# Show usage if no arguments
28+
# Show help if no arguments
2729
if [ $# -eq 0 ]; then
2830
print_usage
2931
exit 1
@@ -45,6 +47,14 @@ case "$1" in
4547
-r|--run)
4648
RUN_AFTER_BUILD=1
4749
;;
50+
-j|--jobs)
51+
if [[ $2 =~ ^[0-9]+$ ]]; then
52+
NUM_JOBS=$2
53+
shift
54+
else
55+
NUM_JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
56+
fi
57+
;;
4858
-h|--help)
4959
print_usage
5060
exit 0
@@ -66,12 +76,18 @@ fi
6676

6777
# Run debug build
6878
echo "Building in debug mode..."
69-
g++ -std=c++20 -DDEBUG_LOG -g "$SOURCE_FILE" -o "$OUTPUT_FILE"
79+
g++ -std=c++20 -DDEBUG_LOG -g -Wall -Wextra "$SOURCE_FILE" -o "$OUTPUT_FILE"
7080

71-
echo "Build complete: $OUTPUT_FILE"
81+
# Check build result
82+
if [ $? -eq 0 ]; then
83+
echo "Build complete: $OUTPUT_FILE"
7284

73-
# Run after build if requested
74-
if [ $RUN_AFTER_BUILD -eq 1 ]; then
75-
echo "Running program..."
76-
"$OUTPUT_FILE"
85+
# Run after build (if requested)
86+
if [ $RUN_AFTER_BUILD -eq 1 ]; then
87+
echo "Running program..."
88+
"$OUTPUT_FILE"
89+
fi
90+
else
91+
echo "Build failed."
92+
exit 1
7793
fi

scripts/run_tests.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
2-
set -eux
2+
set -e # Exit immediately if a command exits with a non-zero status
33

4-
# Create build directory if it doesn't exist
4+
# Create build directory (if it doesn't exist)
55
if [ ! -d "build" ]; then
66
mkdir build
77
fi
@@ -14,8 +14,9 @@ cmake -DCMAKE_BUILD_TYPE=Debug \
1414
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
1515
..
1616

17-
# Build
18-
cmake --build . -- -j"$(nproc)"
17+
# Build (using parallel build)
18+
JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
19+
cmake --build . -- -j"$JOBS"
1920

20-
# Run tests via CTest
21+
# Run tests
2122
GTEST_COLOR=1 ctest --verbose --output-on-failure

0 commit comments

Comments
 (0)