Skip to content

Commit d52b252

Browse files
Increase build script options to include different build targets
1 parent b01943e commit d52b252

File tree

2 files changed

+76
-11
lines changed

2 files changed

+76
-11
lines changed

CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@ project(competitive_programming_library LANGUAGES CXX)
88
set(CMAKE_CXX_STANDARD 20)
99
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

11-
add_subdirectory(tools EXCLUDE_FROM_ALL)
12-
add_subdirectory(benchmarks EXCLUDE_FROM_ALL)
13-
add_subdirectory(cpl)
11+
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
12+
13+
# Should almost* always build tests to verify correctness, regardless of if you intend to run them or not.
14+
# Only case where this should be omitted is if you are building this library as a dependency where
15+
# correctness can be assumed.
16+
option(BUILD_TESTING "Build tests" ON)
17+
option(BUILD_TOOLS "Build tools" OFF)
18+
19+
if(BUILD_BENCHMARKS)
20+
add_subdirectory(benchmarks)
21+
endif()
1422

15-
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
23+
if(BUILD_TOOLS)
24+
add_subdirectory(tools)
25+
endif()
26+
27+
if(BUILD_TESTING)
1628
enable_testing()
1729
add_subdirectory(tests)
1830
endif()
31+
32+
add_subdirectory(cpl)

build.sh

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,63 @@
33
# Copyright (c) Brandon Pacewic
44
# SPDX-License-Identifier: MIT
55

6-
if [ -d "build" ]; then
7-
rm -rf build/
8-
fi
6+
set -e
7+
8+
BUILD_DIR="build"
9+
BUILD_TESTS=ON
10+
RUN_TESTS=OFF
11+
BUILD_BENCH=OFF
12+
BUILD_TOOLS=OFF
13+
CMAKE_GENERATOR="Unix Makefiles"
14+
15+
while [ $# -gt 0 ]; do
16+
case "$1" in
17+
--clean)
18+
rm -rf "$BUILD_DIR"
19+
shift
20+
;;
21+
--build-tests)
22+
BUILD_TESTS=OFF
23+
shift
24+
;;
25+
--test)
26+
RUN_TESTS=ON
27+
shift
28+
;;
29+
--bench)
30+
BUILD_BENCH=ON
31+
shift
32+
;;
33+
--tools)
34+
BUILD_TOOLS=ON
35+
shift
36+
;;
37+
--build-dir=*)
38+
BUILD_DIR="${1#*=}"
39+
shift
40+
;;
41+
--help)
42+
echo "Usage: $0 [--clean] [--build-tests] [--test] [--bench] [--tools] [--build-dir=<dir>] [--help]"
43+
exit 0
44+
;;
45+
*)
46+
echo "Unknown option: $1"
47+
exit 1
48+
;;
49+
esac
50+
done
51+
52+
mkdir -p "$BUILD_DIR"
53+
cd "$BUILD_DIR"
54+
55+
cmake -G "$CMAKE_GENERATOR" \
56+
-DBUILD_TESTING="$BUILD_TESTS" \
57+
-DBUILD_BENCHMARKS="$BUILD_BENCH" \
58+
-DBUILD_TOOLS="$BUILD_TOOLS" \
59+
..
960

10-
mkdir build/
11-
cd build/
12-
cmake -G "Unix Makefiles" ../
1361
make
14-
ctest --output-on-failure
62+
63+
if [ "$RUN_TESTS" = "ON" ]; then
64+
ctest --output-on-failure
65+
fi

0 commit comments

Comments
 (0)