Skip to content

Commit

Permalink
Merge pull request #17 from massenz/conan-v2
Browse files Browse the repository at this point in the history
Updated the build script to use Conan v2
  • Loading branch information
massenz authored Nov 5, 2024
2 parents 4ba6af4 + 1d5c087 commit 4dbcdcf
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
#!/bin/bash
#
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Copyright (c) 2020-2024 AlertAvert.com. All rights reserved.
# Author: Marco Massenzio ([email protected])
#

#
# Usage: build [build_type]
#
# Where `build_type` can be one of either `Release` or `Debug` (default)
# Usage: build [--debug] [-h]

set -eu

if [[ -z ${COMMON_UTILS} || ! -d ${COMMON_UTILS} ]]; then
echo "[ERROR] The \$UTILS_DIR env var must be defined and " \
"point to the directory which contains the Common Utilities"
exit 1
if [[ ${1:-} == "-h" ]]; then
echo "Usage: build [--debug] [-h]"
echo "Builds the project using CMake, with an optional --debug flag to build in Debug mode."
exit 0
fi

# shellcheck disable=SC2155
declare -r COMMON_UTILS="$(realpath $0/..)"
declare -r UTILS="-DCOMMON_UTILS_DIR=${COMMON_UTILS}"
source "${COMMON_UTILS}"/utils.sh
source env.sh

BUILD=${1:-Debug}
if [[ ${1:-} == "--debug" ]]; then
PRESET=conan-debug
BUILD_TYPE=Debug
else
PRESET=conan-release
BUILD_TYPE=Release
fi

msg "Build folder in ${BUILDDIR}"
mkdir -p "${BUILDDIR}"
if [[ -f conanfile.txt ]]; then
msg "Installing binary dependencies..."
conan install . -if="${BUILDDIR}" -pr=default --build=missing
conan install . -pr=default \
--build=missing -s build_type=${BUILD_TYPE}
success "Dependencies installed"
fi

UTILS="-DCOMMON_UTILS_DIR=${COMMON_UTILS}"

cd "${BUILDDIR}"
cmake -DCMAKE_CXX_COMPILER="${CLANG}" \
-DCMAKE_BUILD_TYPE="${BUILD}" \
"${UTILS}" ..
cmake --build . --target all -- -j 6
success "Build complete"
msg "Running CMake to configure the build"
cmake --preset ${PRESET} "${UTILS}"
success "CMake configuration complete"
msg "Building the project"
cmake --build --preset ${PRESET} "${UTILS}" --target all -- -j 6
success "Build complete, targets available in $(realpath ./build/${BUILD_TYPE})"

0 comments on commit 4dbcdcf

Please sign in to comment.