Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/build_cmake.sh
#!/usr/bin/env bash | #!/usr/bin/env bash | ||||
export LC_ALL=C | export LC_ALL=C | ||||
set -euxo pipefail | set -euxo pipefail | ||||
: "${TOPLEVEL:=$(git rev-parse --show-toplevel)}" | : "${TOPLEVEL:=$(git rev-parse --show-toplevel)}" | ||||
: "${BUILD_DIR:=${TOPLEVEL}/build}" | : "${BUILD_DIR:=${TOPLEVEL}/build}" | ||||
function usage() { | |||||
echo "Usage: $0 [--Werror]" | |||||
echo "Build the default target using cmake and ninja." | |||||
echo "Options:" | |||||
echo " --Werror: add -Werror to the compiler flags" | |||||
echo "Environment variables:" | |||||
echo " CMAKE_FLAGS: array of the CMAKE flags to use for the build" | |||||
echo " BUILD_DIR: the build directory, (default: ${BUILD_DIR}})" | |||||
echo " TOPLEVEL: the project root directory, (default: ${TOPLEVEL}})" | |||||
} | |||||
# Default to nothing | # Default to nothing | ||||
: "${CMAKE_FLAGS:=}" | : "${CMAKE_FLAGS:=}" | ||||
mkdir -p "${BUILD_DIR}" | mkdir -p "${BUILD_DIR}" | ||||
cd ${BUILD_DIR} | cd ${BUILD_DIR} | ||||
git clean -xffd | git clean -xffd | ||||
read -a CMAKE_FLAGS <<< "${CMAKE_FLAGS}" | read -a CMAKE_FLAGS <<< "${CMAKE_FLAGS}" | ||||
cmake -GNinja .. -DENABLE_CLANG_TIDY=OFF "${CMAKE_FLAGS[@]}" | |||||
case "$1" in | |||||
"--Werror") | |||||
CMAKE_FLAGS+=( | |||||
"-DCMAKE_C_FLAGS=-Werror" | |||||
"-DCMAKE_CXX_FLAGS=-Werror" | |||||
) | |||||
;; | |||||
*) | |||||
usage | |||||
exit 1 | |||||
;; | |||||
esac | |||||
cmake -GNinja .. "${CMAKE_FLAGS[@]}" | |||||
# Run build | # Run build | ||||
ninja | ninja |