-
Notifications
You must be signed in to change notification settings - Fork 346
/
build.sh
executable file
·79 lines (63 loc) · 2.52 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Copyright (c) 2020 The Orbit Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -euo pipefail
# We call conan by going through python3 to avoid any PATH problems.
# Sometimes tools installed by PIP are not automatically in the PATH.
if [[ $(uname -s) == "Linux" ]]; then
CONAN="python3 -m conans.conan"
else
CONAN="py -3 -m conans.conan"
fi
readonly CONAN
default_profiles=( default_release )
if [ "$#" -eq 0 ]; then
profiles=( "${default_profiles[@]}" )
else
profiles=()
for profile in "$@"; do profiles+=( "$profile" ); done
fi
readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
function create_conan_profile {
local readonly profile="$1"
if ! $CONAN profile show default >/dev/null 2>&1; then
$CONAN profile new --detect default >/dev/null || exit $?
fi
local readonly compiler="$($CONAN profile show default | grep compiler= | cut -d= -f2 | sed -e 's/Visual Studio/msvc/')"
local compiler_version="$($CONAN profile show default | grep compiler.version= | cut -d= -f2)"
if [[ $compiler == "msvc" ]]; then
compiler_version="$(echo $compiler_version | sed -e 's/^16$/2019/' | sed -e 's/^17$/2022/')"
fi
local readonly compiler_version
local readonly conan_dir=${CONAN_USER_HOME:-~}/.conan
local readonly build_type="${profile#default_}"
local readonly profile_path="$conan_dir/profiles/$profile"
echo -e "include(${compiler}${compiler_version}_${build_type})\n" > $profile_path
echo -e "[settings]\n[options]" >> $profile_path
echo -e "[build_requires]\n[env]" >> $profile_path
if [[ -v CC ]]; then
echo "CC=$CC" >> $profile_path
fi
if [[ -v CXX ]]; then
echo "CXX=$CXX" >> $profile_path
fi
}
function conan_profile_exists {
$CONAN profile show $1 >/dev/null 2>&1
return $?
}
# That's the profile that is used for tools that run on the build machine (Nasm, CMake, Ninja, etc.)
readonly build_profile="default_release"
conan_profile_exists "${build_profile}" || create_conan_profile "${build_profile}"
for profile in ${profiles[@]}; do
if [[ $profile == default_* ]]; then
conan_profile_exists "$profile" || create_conan_profile "$profile"
fi
$CONAN install -pr:b "${build_profile}" -pr:h $profile -if build_$profile/ \
--build outdated --update "$DIR" || exit $?
$CONAN build -bf build_$profile/ "$DIR" || exit $?
if [[ $profile == default_* ]]; then
echo "The build finished successfully. Start Orbit with ./build_$profile/bin/Orbit!"
fi
done