#!/usr/bin/env bash set -eu PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SRC_DIR=$(realpath "${PWD}/..") CXX_SRC=${SRC_DIR}/cpp # The following can be set : "${CMAKE:=cmake}" error() { echo "$@" >&2 exit 1 } check_installed() { which "$1" > /dev/null } parse_argv() { check_installed docopts || error "docopts is missing, install with 'pip install docopts'" # Parse the argv into an associative array stored in a local variable named # __args. We cannot write in the `args` implicit scoped variable due to # redefinition and shadowing. eval "$(docopts -A __args -V - -h - : "$@" < Prepare a cmake build directory for arrow. Options: --cc= Set C compiler [default: cc]. --cxx= Set C++ compiler [default: c++]. --cxx-flags= Set extra compiler flags. --generator= CMake generator type [default: Ninja]. --build-type= CMake build type [default: DEBUG]. --warn-level= Warning level, possible options are EVERYTHING, CHECKIN, PRODUCTION [default: CHECKIN]. --cmake-extra= CMake extra argument to pass. --with-tests= Activate tests [default: ON]. --with-benchmarks= Activate benchmarks [default: ON]. --with-python= Activate python bindings [default: ON]. --with-parquet= Activate parquet component [default: ON]. --with-gandiva= Activate gandiva component [default: ON]. --with-plasma= Activate plasma component [default: ON]. --with-flight= Activate flight component [default: OFF]. --with-asan= Activate ASAN sanitization [default: OFF]. --force Delete exisiting build dir if found. --trace Trace this script. --help Show help options. ---- EOF )" # copy __args into args # disable shellcheck since __args is defined in the previous eval. # shellcheck disable=SC2154 for k in "${!__args[@]}"; do args+=(["$k"]=${__args["$k"]}); done # enable `set -x` if tracing is requested if [[ "${args[--trace]}" == "true" ]]; then set -x; fi } build_cmake_argv() { # Define generator cmake_argv+=("-G${args[--generator]}") # toolchain export "CC=${args[--cc]}" export "CXX=${args[--cxx]}" if [[ ! -z "${args[--cxx-flags]:-}" ]]; then cmake_argv+=("-DARROW_CXXFLAGS=${args[--cxx-flags]}") fi # Build type cmake_argv+=("-DCMAKE_BUILD_TYPE=${args[--build-type]}") cmake_argv+=("-DARROW_BUILD_TESTS=${args[--with-tests]}") cmake_argv+=("-DARROW_BUILD_BENCHMARKS=${args[--with-benchmarks]}") cmake_argv+=("-DBUILD_WARNING_LEVEL=${args[--warn-level]}") cmake_argv+=("-DARROW_USE_ASAN=${args[--with-asan]}") # Components cmake_argv+=("-DARROW_PYTHON=${args[--with-python]}") cmake_argv+=("-DARROW_PARQUET=${args[--with-parquet]}") cmake_argv+=("-DARROW_GANDIVA=${args[--with-gandiva]}") cmake_argv+=("-DARROW_PLASMA=${args[--with-plasma]}") cmake_argv+=("-DARROW_FLIGHT=${args[--with-flight]}") # conda-ism if [[ ! -z "${CONDA_PREFIX:-}" ]]; then local arrow_home=${CONDA_PREFIX} for v in ARROW_HOME ARROW_BUILD_TOOLCHAIN PARQUET_HOME BOOST_HOME; do export "${v}=${arrow_home}" done cmake_argv+=("-DCMAKE_INSTALL_PREFIX=${arrow_home}") cmake_argv+=("-DCMAKE_INSTALL_LIBDIR=lib") fi if [[ ! -z "${args[--cmake-extra]:-}" ]]; then cmake_argv+=(${args[--cmake-extra]}) fi cmake_argv+=("$CXX_SRC") } invoke_cmake() { local build_dir=${args[]} local force=${args[--force]} # Deal with existing build_dir if [[ -e "$build_dir" ]]; then if [[ "$force" != "true" ]]; then error "$build_dir already exists, pass --force to override" fi rm -r "$build_dir" fi # CMake 3.13 supports the `-B` option, until then we resort to the # old pushd/popd mechanism. mkdir "$build_dir" pushd "$build_dir" "${CMAKE}" "${cmake_argv[@]}" popd } arrow_create_cpp_build() { # The following local variables are captured by lexical scope due to bash # incapacity to accept/return array variables (without using nameref which # are found only in bash 4.3 and later). # Parse docopts arguments into `args` associative map. declare -A args # Define a local array to store cmake arguments. declare -a cmake_argv parse_argv "$@" build_cmake_argv invoke_cmake } main() { arrow_create_cpp_build "$@" } # Invoke main only if the script is executed and not sourced. [[ "${BASH_SOURCE[0]}" != "${0}" ]] || main "$@"