-
Notifications
You must be signed in to change notification settings - Fork 580
Expand file tree
/
Copy pathcppbuild
More file actions
executable file
·105 lines (93 loc) · 2.79 KB
/
cppbuild
File metadata and controls
executable file
·105 lines (93 loc) · 2.79 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
#!/usr/bin/env bash
SOURCE_DIR="$(pwd)"
BUILD_DIR="${SOURCE_DIR}/cppbuild/Release"
EXTRA_CMAKE_ARGS=""
BUILD_DELETE_CMAKE=false
BUILD_CMAKE_VERSION=4.3.0
BUILD_CMAKE_DIR="${SOURCE_DIR}/cppbuild/cmake"
ncpus=1
case "$(uname)" in
Darwin* )
ncpus=$(sysctl -n hw.ncpu)
BUILD_CMAKE_OS="macos-universal"
BUILD_CMAKE_PATH="${BUILD_CMAKE_DIR}/CMake.app/Contents/bin"
;;
Linux*)
ncpus=$(lscpu -p | grep -c -E -v '^#')
BUILD_CMAKE_OS="linux-$(arch)"
BUILD_CMAKE_PATH="${BUILD_CMAKE_DIR}/bin"
;;
esac
function install_cmake()
{
if [[ true = "${BUILD_DELETE_CMAKE}" ]]
then
echo "Removing old CMake installation"
rm -rf "${BUILD_CMAKE_DIR}"
fi
local version_file="${BUILD_CMAKE_DIR}/version.txt"
local version_info="${BUILD_CMAKE_VERSION}-${BUILD_CMAKE_OS}"
if [[ "${version_info}" != "$(cat "${version_file}")" ]]
then
echo "Installing CMake ${version_info}"
rm -rf "${BUILD_CMAKE_DIR}"
mkdir -p "${BUILD_CMAKE_DIR}"
(curl -LJ "https://github.com/Kitware/CMake/releases/download/v${BUILD_CMAKE_VERSION}/cmake-${BUILD_CMAKE_VERSION}-${BUILD_CMAKE_OS}.tar.gz" | tar xzf - -C "${BUILD_CMAKE_DIR}" --strip-components 1
echo "${version_info}" > "${version_file}")
fi
}
while [[ $# -gt 0 ]]
do
option="${1}"
case ${option} in
--c-warnings-as-errors)
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DC_WARNINGS_AS_ERRORS=ON"
echo "Enabling warnings as errors for C"
shift
;;
--cxx-warnings-as-errors)
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCXX_WARNINGS_AS_ERRORS=ON"
echo "Enabling warnings as errors for C++"
shift
;;
-d|--debug-build)
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=Debug"
export BUILD_DIR="${SOURCE_DIR}/cppbuild/Debug"
export BUILD_CONFIG=Debug
shift
;;
--sanitise-build)
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DSANITISE_BUILD=ON"
echo "Enabling sanitise build"
shift
;;
--rebuild-cmake)
BUILD_DELETE_CMAKE=true
shift
;;
--cmake-version)
BUILD_CMAKE_VERSION=${2}
echo "Setting BUILD_CMAKE_VERSION=${2}"
shift
shift
;;
-h|--help)
echo "${0} [--c-warnings-as-errors] [--cxx-warnings-as-errors] [--debug-build] [--sanitise-build]"
exit
;;
*)
echo "Unknown option ${option}"
echo "Use --help for help"
exit
;;
esac
done
echo "Will make with \"-j ${ncpus}\"."
if [ -d "${BUILD_DIR}" ] ; then
echo "Build directory (${BUILD_DIR}) exists, removing."
rm -rf "${BUILD_DIR}"
fi
mkdir -p "${BUILD_DIR}"
install_cmake
cd "${BUILD_DIR}" || exit
("${BUILD_CMAKE_PATH}/cmake" -G "Unix Makefiles" ${EXTRA_CMAKE_ARGS} "${SOURCE_DIR}" && make clean && make -j ${ncpus} all && "${BUILD_CMAKE_PATH}/ctest" -C Release --output-on-failure)