-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-core.sh
executable file
·128 lines (115 loc) · 4.27 KB
/
build-core.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Exit on error
set -e
# Default values for flags.
DEBUG_TYPE="Release"
NUM_JOBS=$(nproc)
MOCO="on"
CORE_BRANCH="main"
GENERATOR="Unix Makefiles"
Help() {
echo
echo "This script builds and installs the last available version of OpenSim-Core in your computer."
echo "Usage: ./scriptName [OPTION]..."
echo "Example: ./opensim-core-build.sh -j 4 -d \"Release\""
echo " -d Debug Type. Available Options:"
echo " Release (Default): No debugger symbols. Optimized."
echo " Debug: Debugger symbols. No optimizations (>10x slower). Library names ending with _d."
echo " RelWithDefInfo: Debugger symbols. Optimized. Bigger than Release, but not slower."
echo " MinSizeRel: No debugger symbols. Minimum size. Optimized."
echo " -j Number of jobs to use when building libraries (>=1)."
echo " -s Simple build without moco (Tropter and Casadi disabled)."
echo " -c Branch for opensim-core repository."
echo " -n Use the Ninja generator to build opensim-core. If not set, Unix Makefiles is used."
echo
exit
}
# Get flag values if any.
while getopts 'j:d:s:c:n' flag; do
case "${flag}" in
j) NUM_JOBS=${OPTARG} ;;
d) DEBUG_TYPE=${OPTARG} ;;
s) MOCO="off" ;;
c) CORE_BRANCH=${OPTARG} ;;
n) GENERATOR="Ninja" ;;
*) Help ;;
esac
done
# Check if parameters are valid.
if [[ $NUM_JOBS -lt 1 ]]; then
Help
fi
if [[ $DEBUG_TYPE != "Release" ]] && [[ $DEBUG_TYPE != "Debug" ]] && [[ $DEBUG_TYPE != "RelWithDebInfo" ]] && [[ $DEBUG_TYPE != "MinSizeRel" ]]; then
Help
fi
# Show values of flags:
echo
echo "Build script parameters:"
echo "DEBUG_TYPE="$DEBUG_TYPE
echo "NUM_JOBS="$NUM_JOBS
echo "MOCO="$MOCO
echo "CORE_BRANCH="$CORE_BRANCH
echo "GENERATOR="$GENERATOR
echo ""
# Check OS.
echo "LOG: CHECKING OS..."
# found this here https://unix.stackexchange.com/a/25131
OS_NAME=$(cat /etc/os-release)
echo "OS="$OS_NAME
echo ""
# Get opensim-core.
echo "LOG: CLONING OPENSIM-CORE..."
git -C ~/opensim-workspace/opensim-core-source pull ||
git clone https://github.com/opensim-org/opensim-core.git ~/opensim-workspace/opensim-core-source
cd ~/opensim-workspace/opensim-core-source
# Ignore the git checkout error if you can't check something out
git checkout $CORE_BRANCH || true
echo
# Build opensim-core dependencies.
echo "LOG: BUILDING OPENSIM-CORE DEPENDENCIES..."
mkdir -p ~/opensim-workspace/opensim-core-dependencies-build || true
cd ~/opensim-workspace/opensim-core-dependencies-build
cmake ~/opensim-workspace/opensim-core-source/dependencies \
\
-DCMAKE_CXX_FLAGS="-march=native ${CMAKE_CXX_FLAGS}" \
-DGRAPHVIZ_CUSTOM_TARGETS=TRUE \
-DCMAKE_INSTALL_PREFIX=~/opensim-workspace/opensim-core-dependencies-install/ \
-DSUPERBUILD_ezc3d=on \
-DOPENSIM_WITH_CASADI=$MOCO \
-DOPENSIM_WITH_TROPTER=$MOCO # --graphviz=deps.dot \
# -DCMAKE_CXX_FLAGS=-pg -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg
cmake . -LAH
cmake --build . --config $DEBUG_TYPE -j$NUM_JOBS
echo
# Build opensim-core.
echo "LOG: BUILDING OPENSIM-CORE..."
mkdir -p ~/opensim-workspace/opensim-core-build || true
cd ~/opensim-workspace/opensim-core-build
cmake ~/opensim-workspace/opensim-core-source \
-G"$GENERATOR" \
-DCMAKE_CXX_FLAGS="-march=native ${CMAKE_CXX_FLAGS}" \
-DOPENSIM_DEPENDENCIES_DIR=~/opensim-workspace/opensim-core-dependencies-install/ \
-DBUILD_JAVA_WRAPPING=off \
-DBUILD_PYTHON_WRAPPING=off \
-DBUILD_EXAMPLES=off \
-DBUILD_TESTING=off \
-DOPENSIM_C3D_PARSER=ezc3d \
-DCMAKE_INSTALL_PREFIX=~/opensim-core \
-DOPENSIM_INSTALL_UNIX_FHS=off \
-DSWIG_DIR=/usr/bin/swig \
-DSWIG_EXECUTABLE=/usr/bin/swig
# --graphviz=deps.dot -DGRAPHVIZ_CUSTOM_TARGETS=TRUE \
# -DCMAKE_CXX_FLAGS=-pg -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg
cmake . -LAH
cmake --build . --config $DEBUG_TYPE -j$NUM_JOBS
echo
# Test opensim-core.
echo "LOG: TESTING OPENSIM-CORE..."
# cd ~/opensim-workspace/opensim-core-build
# # TODO: Temporary for python to find Simbody libraries.
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/opensim-workspace/opensim-core-dependencies-install/simbody/lib
# ctest --parallel $NUM_JOBS --output-on-failure
# Install opensim-core.
echo "LOG: INSTALL OPENSIM-CORE..."
cd ~/opensim-workspace/opensim-core-build
cmake --install .