Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/build_cmake.sh
Show All 10 Lines | 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 " --clang: build with clang/clang++" | ||||
echo " --gcc: build with gcc/g++" | echo " --gcc: build with gcc/g++" | ||||
echo " --junit: enable Junit reports generation" | echo " --junit: enable Junit reports generation" | ||||
echo " --no-build: Only run the configuration step and skip the build" | |||||
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 || true | git clean -xffd || true | ||||
read -a CMAKE_FLAGS <<< "${CMAKE_FLAGS}" | read -a CMAKE_FLAGS <<< "${CMAKE_FLAGS}" | ||||
BUILD="yes" | |||||
TARGETS=() | TARGETS=() | ||||
while [[ $# -gt 0 ]]; do | while [[ $# -gt 0 ]]; do | ||||
case $1 in | case $1 in | ||||
--clang) | --clang) | ||||
CMAKE_FLAGS+=( | CMAKE_FLAGS+=( | ||||
"-DCMAKE_C_COMPILER=clang" | "-DCMAKE_C_COMPILER=clang" | ||||
"-DCMAKE_CXX_COMPILER=clang++" | "-DCMAKE_CXX_COMPILER=clang++" | ||||
) | ) | ||||
shift | shift | ||||
;; | ;; | ||||
--gcc) | --gcc) | ||||
CMAKE_FLAGS+=( | CMAKE_FLAGS+=( | ||||
"-DCMAKE_C_COMPILER=gcc" | "-DCMAKE_C_COMPILER=gcc" | ||||
"-DCMAKE_CXX_COMPILER=g++" | "-DCMAKE_CXX_COMPILER=g++" | ||||
) | ) | ||||
shift | shift | ||||
;; | ;; | ||||
--junit) | --junit) | ||||
CMAKE_FLAGS+=( | CMAKE_FLAGS+=( | ||||
"-DENABLE_JUNIT_REPORT=ON" | "-DENABLE_JUNIT_REPORT=ON" | ||||
) | ) | ||||
shift | shift | ||||
;; | ;; | ||||
--no-build) | |||||
BUILD="no" | |||||
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 20 Lines | do | ||||
if [[ ! " ${VALID_TARGETS[*]} " =~ \ ${TARGET}\ ]]; then | if [[ ! " ${VALID_TARGETS[*]} " =~ \ ${TARGET}\ ]]; then | ||||
echo "Trying to build an invalid target: ${TARGET}" | echo "Trying to build an invalid target: ${TARGET}" | ||||
exit 2 | exit 2 | ||||
fi | fi | ||||
done | done | ||||
fi | fi | ||||
# Run build | # Run build | ||||
if [ "${BUILD}" == "yes" ] | |||||
then | |||||
ninja "${TARGETS[@]}" | ninja "${TARGETS[@]}" | ||||
fi |