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() { | function usage() { | ||||
echo "Usage: $0 [--Werror] [targets]" | echo "Usage: $0 [--Werror] [targets]" | ||||
echo "Build the targets using cmake and ninja." | echo "Build the targets using cmake and ninja." | ||||
echo "If no target is provided the default (all) target is built." | echo "If no target is provided the default (all) target is built." | ||||
echo | echo | ||||
echo "Options:" | echo "Options:" | ||||
echo " --clang: build with clang/clang++" | |||||
echo " --gcc: build with gcc/g++" | |||||
echo " --Werror: add -Werror to the compiler flags" | echo " --Werror: add -Werror to the compiler flags" | ||||
echo "Environment variables:" | echo "Environment variables:" | ||||
echo " CMAKE_FLAGS: array of the CMAKE flags to use for the build" | echo " CMAKE_FLAGS: array of the CMAKE flags to use for the build" | ||||
echo " BUILD_DIR: the build directory, (default: ${BUILD_DIR}})" | echo " BUILD_DIR: the build directory, (default: ${BUILD_DIR}})" | ||||
echo " TOPLEVEL: the project root directory, (default: ${TOPLEVEL}})" | 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}" | ||||
TARGETS=() | TARGETS=() | ||||
while [[ $# -gt 0 ]]; do | while [[ $# -gt 0 ]]; do | ||||
case $1 in | case $1 in | ||||
--clang) | |||||
CMAKE_FLAGS+=( | |||||
"-DCMAKE_C_COMPILER=clang" | |||||
"-DCMAKE_CXX_COMPILER=clang++" | |||||
) | |||||
shift | |||||
;; | |||||
--gcc) | |||||
CMAKE_FLAGS+=( | |||||
"-DCMAKE_C_COMPILER=gcc" | |||||
"-DCMAKE_CXX_COMPILER=g++" | |||||
) | |||||
shift | |||||
;; | |||||
--Werror) | --Werror) | ||||
CMAKE_FLAGS+=( | CMAKE_FLAGS+=( | ||||
"-DCMAKE_C_FLAGS=-Werror" | "-DCMAKE_C_FLAGS=-Werror" | ||||
"-DCMAKE_CXX_FLAGS=-Werror" | "-DCMAKE_CXX_FLAGS=-Werror" | ||||
) | ) | ||||
shift | shift | ||||
;; | ;; | ||||
*) | *) | ||||
Show All 29 Lines |