-
Notifications
You must be signed in to change notification settings - Fork 137
/
install.sh
executable file
·662 lines (612 loc) · 25.9 KB
/
install.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
#!/usr/bin/env bash
set -e
boost_url="https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_0.tar.gz"
boost_additional_versions="1.81.0;1.80.0;1.79.0;1.78.0;1.77.0;1.76.0;1.75.0;1.74.0;1.73.0;1.72.0;1.71.0;1.70.0"
project_dir=$(pwd)
print_help() {
cat << EOF
Usage: ./install.sh [OPTIONS]
Options:
--clean Clean the build folder before compiling a library (only valid with --build-library)
--build-library Compile a library with CMake (one of: cxx, nodejs, python, emscripten)
--build-type Choose the build type (one of: debug, release) (only valid with --build-library)
--disable-openmp Disable OpenMP in the build. (only valid with --build-library)
--install-system-deps Install dependencies for compiling libraries (only aware of apt, brew and choco at the moment)
--install-ci-deps Install curl and, when the platform is macos, installs OpenMP for the given architecture (see: --macos-architecture)
--install-boost Install Boost from source
--install-boost-from-repo Install Boost (pre-compiled) from platform specific package repositories
--install Install the CMake install targets to the prefix (see: --install-prefix)
--sudo-install Install the CMake install targets to the prefix with root privileges (see: --install-prefix)
--install-prefix Set the install prefix location for CMake installs (only valid when using --install)
--boost-prefix Set a custom path where to look for Boost
--boost-with-python Compile Boost.Python (only valid when using --install-boost)
--boost-address-model Set the address model for Boost (one of: 32, 64) (only valid when using --install-boost and --boost-with-python)
--boost-architecture Set the architecture for Boost (one of: x86, ia64, sparc, power, loongarch, mips, mips1, mips2, mips3, mips4, mips32, mips32r2, mips64, parisc, arm, riscv, s390x, arm+x86) (only valid when using --install-boost and --boost-with-python)
--boost-python-version Set the python version to look for when compiling Boost (only valid when using --install-boost and --boost-with-python)
--python-executable Set a custom path (or name of) the Python executable (only valid when using --build-library python)
--python-prefix Set the python prefix, this will be passed to CMake as Python3_ROOT_DIR, to make sure CMake is using the correct Python installation. (only valid when using --build-library python)
--python-pip-install Uses "pip install ." to compile and install the Python library (only valid when using --build-library python)
--platform Set the platform, for when auto-detection doesn't work (one of: windows, macos, linux)
--macos-architecture Set the macOS architecture to compile for (one of: arm64, x86_64), useful for cross compiling.
--docker-image Set the docker image to forward this install command to, useful for cross compiling
--docker-before-install Run given commands in the docker container before running ./install.sh, (only valid when using --docker-image)
--cmake-generator Set the CMake Generator option
--cmake-generator-platform Set the CMake Generator Platform option, useful for cross compiling on Windows with the Visual Studio generator.
--node-architecture Set the node.js architecture to compile for, useful for cross compiling.
--test Run a test script after compiling the library (only valid with --build-library)
--help Shows this help page
EOF
exit 1
}
original_args="$*"
while [[ "$#" -gt 0 ]]; do
case $1 in
--clean) OCL_CLEAN="1"; ;;
--build-library) OCL_BUILD_LIBRARY="$2"; shift ;;
--build-type) OCL_BUILD_TYPE="$2"; shift ;;
--platform) OCL_PLATFORM="$2"; shift ;;
--install-system-deps) OCL_INSTALL_SYSTEM_DEPS="1"; ;;
--install-ci-deps) OCL_INSTALL_CI_DEPS="1"; ;;
--disable-openmp) OCL_DISABLE_OPENMP="1"; ;;
--install) OCL_INSTALL="1"; ;;
--sudo-install) OCL_SUDO_INSTALL="1"; ;;
--install-prefix) OCL_INSTALL_PREFIX="$2"; shift ;;
--install-boost) OCL_INSTALL_BOOST="1"; ;;
--install-boost-from-repo) OCL_INSTALL_BOOST_FROM_REPO="1"; ;;
--boost-prefix) OCL_BOOST_PREFIX="$2"; shift ;;
--boost-address-model) OCL_BOOST_ADDRESS_MODEL="$2"; shift ;;
--boost-architecture) OCL_BOOST_ARCHITECTURE="$2"; shift ;;
--boost-with-python) OCL_BOOST_WITH_PYTHON="1"; ;;
--boost-python-version) OCL_BOOST_PYTHON_VERSION="$2"; shift ;;
--macos-architecture) OCL_MACOS_ARCHITECTURE="$2"; shift ;;
--docker-image) OCL_DOCKER_IMAGE="$2"; shift ;;
--docker-before-install) OCL_DOCKER_IMAGE_BEFORE_INSTALL="$2"; shift ;;
--cmake-generator) OCL_GENERATOR="$2"; shift ;;
--cmake-generator-platform) OCL_GENERATOR_PLATFORM="$2"; shift ;;
--python-executable) OCL_PYTHON_EXECUTABLE="$2"; shift ;;
--python-prefix) OCL_PYTHON_PREFIX="$2"; shift ;;
--python-pip-install) OCL_PYTHON_PIP_INSTALL="1"; ;;
--node-architecture) OCL_NODE_ARCH="$2"; shift ;;
--test) OCL_TEST="1"; ;;
--help|--*)
echo $1
print_help ;;
*)
esac
shift
done
verify_args() {
if [ -n "${OCL_CLEAN}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then
echo "Cannot set --clean without building a library. add the --build-library [lib] option or remove the --clean option"
exit 1
elif [ -n "${OCL_BUILD_TYPE}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then
echo "Cannot set --build-type without building a library. add the --build-library [lib] option or remove the --build-type option"
exit 1
elif [ -n "${OCL_TEST}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then
echo "Cannot set --test without building a library. add the --build-library [lib] option or remove the --test option"
exit 1
elif [ -n "${OCL_DISABLE_OPENMP}" ] && [ -z "${OCL_BUILD_LIBRARY}" ]; then
echo "Cannot set --disable-openmp without building a library. add the --build-library [lib] option or remove the --disable-openmp option"
exit 1
elif [ -n "${OCL_INSTALL_PREFIX}" ] && [ -z "${OCL_INSTALL}" ] && [ -z "${OCL_SUDO_INSTALL}" ]; then
echo "WARN: Settings --install-prefix without setting --install or --sudo-install. add --install or --sudo-install option or remove the --install-prefix option"
elif [ -n "${OCL_BOOST_WITH_PYTHON}" ] && [ -z "${OCL_INSTALL_BOOST}" ]; then
echo "WARN: Setting --boost-with-python without setting --install-boost. add --install-boost or remove the --boost-with-python option"
elif [ -n "${OCL_BOOST_WITH_PYTHON}" ] && [ -z "${OCL_BOOST_ARCHITECTURE}" ]; then
echo "WARN: Setting --boost-with-python without setting --boost-architecture. add --boost-architecture or remove the --boost-with-python option"
elif [ -n "${OCL_BOOST_ADDRESS_MODEL}" ] && [ -z "${OCL_INSTALL_BOOST}" ]; then
echo "WARN: Setting --boost-address-model without setting --install-boost. add --install-boost or remove the --boost-address-model option"
elif [ -n "${OCL_BOOST_ARCHITECTURE}" ] && [ -z "${OCL_INSTALL_BOOST}" ]; then
echo "WARN: Setting --boost-architecture without setting --install-boost. add --install-boost or remove the --boost-address-model option"
elif [ -n "${OCL_BOOST_PYTHON_VERSION}" ] && [ -z "${OCL_INSTALL_BOOST}" ]; then
echo "WARN: Setting --boost-python-version without setting --install-boost. add --install-boost or remove the --boost-python-version option"
fi
}
verify_args
if [ "${OCL_BUILD_TYPE}" = "debug" ]; then
build_type="Debug"
build_type_lower="debug"
else
build_type="RelWithDebInfo"
build_type_lower="release"
fi
build_dir="${project_dir}/build/${OCL_BUILD_LIBRARY}/${build_type_lower}"
primary='\033[1;34m'
secondary='\033[1;35m'
nc='\033[0m'
prettyprint() {
printf "${primary}${1}${nc}${secondary}${2}${nc}\n"
}
prettyprint "./install.sh " "$original_args"
get_os() {
if [ "${OCL_PLATFORM}" ]; then
echo "${OCL_PLATFORM}"
else
if [[ "${OSTYPE}" =~ ^darwin.* ]]; then
echo "macos"
elif [[ "${OSTYPE}" =~ ^linux.* ]]; then
echo "linux"
else
echo "windows"
fi
fi
}
determined_os=$(get_os)
prettyprint "Determined OS: " "${determined_os}"
num_procs() {
if [ "${determined_os}" = "macos" ]; then
sysctl -n hw.logicalcpu
elif [ "${determined_os}" = "linux" ]; then
nproc
else
echo "${NUMBER_OF_PROCESSORS:-"2"}"
fi
}
num_procs=$(num_procs)
prettyprint "Processor Cores: " "${num_procs}"
if [ -n "${OCL_DOCKER_IMAGE_BEFORE_INSTALL}" ] && [ -z "${OCL_DOCKER_IMAGE}" ]; then
prettyprint "Found before install, running: " "${OCL_DOCKER_IMAGE_BEFORE_INSTALL}"
eval "${OCL_DOCKER_IMAGE_BEFORE_INSTALL}"
fi
install_system_dependencies() {
if [ "${determined_os}" = "linux" ]; then
sudo apt update
sudo apt install -y --no-install-recommends git cmake curl build-essential
if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then
sudo apt install -y --no-install-recommends libboost-dev
fi
if [ "${OCL_BUILD_LIBRARY}" = "python" ]; then
if [ -z "${OCL_PYTHON_EXECUTABLE}" ]; then
sudo apt install -y --no-install-recommends python3
fi
if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then
sudo apt install -y --no-install-recommends libboost-python-dev
fi
fi
if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then
sudo apt install -y --no-install-recommends nodejs npm
fi
elif [ "${determined_os}" = "macos" ]; then
brew install libomp
if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then
brew install boost
fi
if [ "${OCL_BUILD_LIBRARY}" = "python" ]; then
if [ -z "${OCL_PYTHON_EXECUTABLE}" ]; then
brew install python@3.11
fi
if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then
brew install boost-python3
fi
fi
if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then
brew install node
fi
else
# @todo installing git and cmake fails in github's CI
choco install curl --no-progress
if [ -n "${OCL_INSTALL_BOOST_FROM_REPO}" ]; then
choco install boost-msvc-14.3 --no-progress
fi
if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then
choco install nodejs
fi
fi
}
command_exists() {
command -v "${1}" >/dev/null 2>&1;
}
is_root() {
[ "${EUID:-$(id -u)}" -eq 0 ];
}
install_ci_dependencies() {
if [ "${determined_os}" = "windows" ]; then
if command_exists choco; then
choco install curl --no-progress
fi
elif [ "${determined_os}" = "linux" ]; then
if command_exists apt; then
if ! is_root; then
maybe_sudo="sudo"
fi
${maybe_sudo} apt update
${maybe_sudo} apt install -y --no-install-recommends curl
elif command_exists yum; then
if ! is_root; then
maybe_sudo="sudo"
fi
${maybe_sudo} yum install curl
fi
elif [ "${determined_os}" = "macos" ]; then
prettyprint "Downloading libomp for: " "${OCL_MACOS_ARCHITECTURE}"
if [ "${OCL_MACOS_ARCHITECTURE}" = "arm64" ]; then
libomp_tar_loc=$(brew fetch --bottle-tag=arm64_big_sur libomp | grep -i downloaded | grep tar.gz | cut -f2 -d ":" | xargs echo)
else
libomp_tar_loc=$(brew fetch --bottle-tag=big_sur libomp | grep -i downloaded | grep tar.gz | cut -f2 -d ":" | xargs echo)
fi
temp_dir="/tmp"
cp "${libomp_tar_loc}" "${temp_dir}/libomp.tar.gz"
mkdir "${temp_dir}/libomp" || true
tar -xzf "${temp_dir}/libomp.tar.gz" -C "${temp_dir}/libomp"
libomp_prefix=$(find "${temp_dir}/libomp/libomp" -depth 1 | head -1)
export OPENMP_PREFIX_MACOS="${temp_dir}/libomp/libomp/fixed"
mv "${libomp_prefix}" "${OPENMP_PREFIX_MACOS}"
fi
}
download_boost() {
if [ ! -f "${TMPDIR:-"/tmp"}/boost.tar.gz" ]; then
prettyprint "Downloading boost.tar.gz"
curl "${boost_url}" --output "${TMPDIR:-"/tmp"}/boost.tar.gz" --silent --location
else
prettyprint "boost.tar.gz found, re-using..."
fi
prettyprint "Extracting boost.tar.gz..."
tar -zxf "${TMPDIR:-"/tmp"}/boost.tar.gz" -C .
prettyprint "Applying boost-python-3.11.patch"
git apply --ignore-space-change --ignore-whitespace --directory "boost_1_80_0/libs/python" "${project_dir}/.github/patches/boost-python-3.11.patch"
}
compile_boost_python() {
boost_variant="${build_type_lower}"
cd "${project_dir}/boost_1_80_0"
if [ -n "${OCL_BOOST_WITH_PYTHON}" ]; then
if [ -n "${OCL_PYTHON_EXECUTABLE}" ]; then
python_version=$(${OCL_PYTHON_EXECUTABLE} -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}".format(*version))')
python_include_dir=$(${OCL_PYTHON_EXECUTABLE} -c 'from sysconfig import get_paths as gp; print(gp()["include"])')
if [ "${determined_os}" = "windows" ]; then
python_include_dir=$(cygpath -w "${python_include_dir}")
fi
echo "using python : ${python_version} : ${OCL_PYTHON_EXECUTABLE//\\/\\\\} : ${python_include_dir//\\/\\\\} ;" > user-config.jam
elif [ -n "${OCL_BOOST_PYTHON_VERSION}" ]; then
echo "using python : ${OCL_BOOST_PYTHON_VERSION} ;" > user-config.jam
else
echo "using python ;" > user-config.jam
fi
cat user-config.jam
prettyprint "Bootstrapping boost"
if [ "${determined_os}" = "windows" ]; then
./bootstrap.bat
else
./bootstrap.sh
fi
prettyprint "Compiling boost " "${OCL_BOOST_ADDRESS_MODEL:-"64"}-bit ${OCL_BOOST_ARCHITECTURE}"
./b2 \
${OCL_CLEAN:+"-a"} \
-j2 \
--layout="system" \
--with-python \
--user-config="user-config.jam" \
threading="multi" \
variant="${boost_variant}" \
link="static" \
cxxflags="-fPIC" \
address-model="${OCL_BOOST_ADDRESS_MODEL:-"64"}" \
${OCL_BOOST_ARCHITECTURE:+"architecture=${OCL_BOOST_ARCHITECTURE}"} \
stage
fi
}
install_boost () {
cd "${project_dir}"
if [ -d boost_1_80_0 ]; then
# boost folder already exists, re-unsing
prettyprint "Boost already found, re-using..."
elif [ -f boost-precompiled.tar.gz ]; then
# boost-precompiled.tar.gz found, re-using
prettyprint "Found cached precompiled boost, installing..."
tar -zxf boost-precompiled.tar.gz -C .
elif [ -n "${OCL_BOOST_ARCHITECTURE}" ] && [ -n "${OCL_BOOST_WITH_PYTHON}" ]; then
# got enough information to try and download a pre-compiled boost with python
boost_precompiled_url="https://github.com/vespakoen/boost-python-precompiled/releases/download/1.80.0/boost-python-precompiled-${determined_os}-${OCL_BOOST_ARCHITECTURE}-${OCL_BOOST_ADDRESS_MODEL:-"64"}-bit.tar.gz"
if curl --output /dev/null --silent --head --fail "$boost_precompiled_url"; then
prettyprint "Downloading boost-precompiled.tar.gz for ${OCL_BOOST_ARCHITECTURE} ${OCL_BOOST_ADDRESS_MODEL:-"64"}-bit..."
curl "${boost_precompiled_url}" --output "${TMPDIR:-"/tmp"}/boost-precompiled.tar.gz" --silent --location
prettyprint "Extracting boost-precompiled.tar.gz..."
tar -zxf "${TMPDIR:-"/tmp"}/boost-precompiled.tar.gz" -C .
else
# precompiled boost python not available for given architecture and address model, installing from source
download_boost
if [ -n "${OCL_BOOST_WITH_PYTHON}" ]; then
compile_boost_python
fi
fi
else
download_boost
if [ -n "${OCL_BOOST_WITH_PYTHON}" ]; then
compile_boost_python
fi
fi
}
if [ -n "${OCL_DOCKER_IMAGE}" ]; then
prettyprint "Running the docker image with the following environment variables"
# collect all the options to check which ones are set and should be forwarded to the container
ALL_OPTIONS=($(compgen -A variable | grep '^OCL_'))
# create temporary env file
TMPENV="/tmp/.env${RANDOM}"
# empty the env file
echo "" > "${TMPENV}"
# escape the pwd to be used in find and replace later
ESCAPED_PWD=$(pwd | sed 's/\//\\\//g')
# look for options that are set
for OPTION in "${ALL_OPTIONS[@]}"; do
# exclude some that cause recursion or do not work in the container
if [ -n "${!OPTION}" ] && [ "${OPTION}" != "OCL_DOCKER_IMAGE" ] && [ "${OPTION}" != "OCL_INSTALL_SYSTEM_DEPS" ]; then
# save to options to the env file, replacing PWD with the container's /work mount path
FIXED_OPTION="${!OPTION//${ESCAPED_PWD}//work}"
echo "${OPTION}=${FIXED_OPTION}" >> "${TMPENV}"
prettyprint "${OPTION}: " "${FIXED_OPTION}"
fi
done
docker run --env-file "${TMPENV}" --user root -w /work -v "$(pwd):/work:rw" --rm "${OCL_DOCKER_IMAGE}" ./install.sh
exit 0
fi
# when the --macos-architecture flag is set, export the CMAKE_OSX_ARCHITECTURES variable for cross compiling and download libomp.
if [ -n "${OCL_MACOS_ARCHITECTURE}" ]; then
export CMAKE_OSX_ARCHITECTURES="${OCL_MACOS_ARCHITECTURE}"
fi
dependencies_nodejslib () {
cd "${project_dir}/src/nodejslib"
npm install --silent
}
dependencies_emscriptenlib () {
cd "${project_dir}"
if [ ! -d ../emsdk ]; then
(
cd ..
git clone https://github.com/emscripten-core/emsdk.git
)
fi
cd ../emsdk
./emsdk install latest
./emsdk activate latest
}
build_clean() {
rm -rf "${build_dir}" || true
}
cmake_build() {
if [ "${determined_os}" = "windows" ]; then
${OCL_SUDO_INSTALL:+"sudo"} cmake \
--build . \
--config "${build_type}" \
-j "${num_procs}"
else
${OCL_SUDO_INSTALL:+"sudo"} cmake \
--build . \
-j "${num_procs}"
fi
}
cmake_install() {
prettyprint "Installing"
if [ "${determined_os}" = "windows" ]; then
${OCL_SUDO_INSTALL:+"sudo"} cmake \
--install . \
--config "${build_type}"
else
${OCL_SUDO_INSTALL:+"sudo"} cmake \
--install .
fi
}
build_cxxlib() {
mkdir -p "${build_dir}"
cd "${build_dir}"
set -x
cmake \
${OCL_GENERATOR:+"-G ${OCL_GENERATOR}"} \
${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM}"} \
-D CMAKE_BUILD_TYPE="${build_type}" \
-D BUILD_CXX_LIB="ON" \
-D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \
${OCL_DISABLE_OPENMP:+"-DUSE_OPENMP=OFF"} \
${OCL_INSTALL_PREFIX:+"-DCMAKE_INSTALL_PREFIX=${OCL_INSTALL_PREFIX}"} \
${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \
../../..
set +x
cmake_build
if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then
cmake_install
fi
}
test_cxxlib() {
cd "${project_dir}/examples/cpp/test"
if [ -n "${OCL_CLEAN}" ]; then
prettyprint "Cleaning build directory..."
rm -rf build || true
fi
mkdir build || true
cd build
set -x
cmake \
${OCL_GENERATOR:+"-G ${OCL_GENERATOR}"} \
${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM}"} \
-D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \
${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \
..
set +x
cmake_build
if [ "${determined_os}" = "windows" ]; then
./test_example.exe
else
./test_example
fi
}
build_nodejslib() {
mkdir -p "${build_dir}"
cd "${build_dir}"
set -x
determined_arch=$(node -p 'process.arch')
install_prefix_fallback="${project_dir}/src/npmpackage/build/Release/${determined_os}-nodejs-${determined_arch}"
../../../src/nodejslib/node_modules/.bin/cmake-js \
build \
--directory "../../.." \
--out "." \
--parallel "${num_procs}" \
${OCL_NODE_ARCH:+"--arch=${OCL_NODE_ARCH}"} \
${OCL_GENERATOR:+"--generator=${OCL_GENERATOR}"} \
${OCL_GENERATOR_PLATFORM:+"--platform=${OCL_GENERATOR_PLATFORM}"} \
--CDBUILD_NODEJS_LIB="ON" \
--CDBoost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \
--CDCMAKE_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" \
${OCL_DISABLE_OPENMP:+"--CDUSE_OPENMP=OFF"} \
${OCL_BOOST_PREFIX:+"--CDBOOST_ROOT=${OCL_BOOST_PREFIX}"} \
--config "${build_type}"
set +x
if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then
cmake_install
fi
}
test_nodejslib() {
cd "${project_dir}/src/npmpackage"
npm install
npm run build-node
cd ../../examples/nodejs
npm link ../../src/npmpackage
if [ "${build_type}" = "debug" ]; then
export DEBUG="1"
fi
node test.js
}
get_python_executable() {
if command_exists "python3"; then
python_executable_fallback="python3"
else
python_executable_fallback="python"
fi
echo "${OCL_PYTHON_EXECUTABLE:-"${python_executable_fallback}"}"
}
build_pythonlib() {
python_executable=$(get_python_executable)
if [ -n "${OCL_PYTHON_PIP_INSTALL}" ]; then
${python_executable} -m pip install scikit-build-core distlib pyproject_metadata
# ${python_executable} -m venv env
# if [ "${determined_os}" = "windows" ]; then
# source env/Scripts/activate
# else
# source env/bin/activate
# fi
# forward cmake args
export CMAKE_ARGS="${OCL_GENERATOR:+"-G ${OCL_GENERATOR} "}\
${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM} "}\
-D CMAKE_BUILD_TYPE=${build_type} \
-D Boost_ADDITIONAL_VERSIONS=${boost_additional_versions} \
${OCL_BOOST_PREFIX:+"-D BOOST_ROOT=${OCL_BOOST_PREFIX} "}"
cd "${project_dir}"
${python_executable} -m pip install --verbose .
else
mkdir -p "${build_dir}"
cd "${build_dir}"
set -x
install_prefix_fallback=$(${python_executable} -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')
cmake \
${OCL_GENERATOR:+"-G ${OCL_GENERATOR}"} \
${OCL_GENERATOR_PLATFORM:+"-A ${OCL_GENERATOR_PLATFORM}"} \
-D CMAKE_BUILD_TYPE="${build_type}" \
-D BUILD_PY_LIB="ON" \
-D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \
-D CMAKE_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" \
${OCL_DISABLE_OPENMP:+"-DUSE_OPENMP=OFF"} \
${OCL_PYTHON_PREFIX:+"-DPython3_ROOT_DIR=${OCL_PYTHON_PREFIX}"} \
${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \
../../..
set +x
cmake_build
if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then
cmake_install
fi
fi
}
test_pythonlib() {
python_executable=$(get_python_executable)
cd "${project_dir}/examples/python"
${python_executable} test.py
}
build_emscriptenlib() {
mkdir -p "${build_dir}"
cd "${build_dir}"
source "${project_dir}/../emsdk/emsdk_env.sh"
set -x
install_prefix_fallback="${project_dir}/src/npmpackage/build"
emcmake cmake \
-G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE="${build_type}" \
-D BUILD_EMSCRIPTEN_LIB="ON" \
-D USE_OPENMP="OFF" \
-D Boost_ADDITIONAL_VERSIONS="${boost_additional_versions}" \
-D CMAKE_INSTALL_PREFIX="${OCL_INSTALL_PREFIX:-"${install_prefix_fallback}"}" \
${OCL_BOOST_PREFIX:+"-DBOOST_ROOT=${OCL_BOOST_PREFIX}"} \
../../..
if [ "${determined_os}" = "windows" ]; then
emmake make \
--config "${build_type}" \
-j "${num_procs}"
else
emmake make \
-j "${num_procs}"
fi
if [ -n "${OCL_INSTALL}" ] || [ -n "${OCL_SUDO_INSTALL}" ]; then
prettyprint "Installing"
${OCL_SUDO_INSTALL:+"sudo"} emmake make install
fi
set +x
}
test_emscriptenlib() {
cd "${project_dir}/src/npmpackage"
npm install
npm run build-emscripten
cd ../../examples/emscripten
npm link ../../src/npmpackage
npm start &
server_pid=$!
sleep 3
node test.js
kill ${server_pid}
}
if [ -n "${OCL_INSTALL_SYSTEM_DEPS}" ]; then
prettyprint "Installing system dependencies..."
install_system_dependencies
fi
if [ -n "${OCL_INSTALL_CI_DEPS}" ]; then
prettyprint "Installing ci dependencies..."
install_ci_dependencies
fi
if [ -n "${OCL_INSTALL_BOOST}" ]; then
prettyprint "Installing Boost..."
install_boost
fi
if [ -n "${OCL_CLEAN}" ]; then
prettyprint "Cleaning build directory..."
build_clean
fi
if [ "${OCL_BUILD_LIBRARY}" = "cxx" ]; then
prettyprint "Building C++ library"
build_cxxlib
if [ -n "${OCL_TEST}" ]; then
prettyprint "Testing C++ library"
test_cxxlib
fi
fi
if [ "${OCL_BUILD_LIBRARY}" = "nodejs" ]; then
prettyprint "Installing node.js dependencies"
dependencies_nodejslib
prettyprint "Building node.js library"
build_nodejslib
if [ -n "${OCL_TEST}" ]; then
prettyprint "Testing node.js library"
test_nodejslib
fi
fi
if [ "${OCL_BUILD_LIBRARY}" = "python" ]; then
prettyprint "Building Python library " "${OCL_BOOST_PYTHON_VERSION}"
build_pythonlib
if [ -n "${OCL_TEST}" ]; then
prettyprint "Testing Python library"
test_pythonlib
fi
fi
if [ "${OCL_BUILD_LIBRARY}" = "emscripten" ]; then
prettyprint "Installing emscripten dependencies"
dependencies_emscriptenlib
prettyprint "Building emscripten library"
build_emscriptenlib
if [ -n "${OCL_TEST}" ]; then
prettyprint "Testing emscripten library"
test_emscriptenlib
fi
fi