@@ -374,35 +374,36 @@ EOF
374374}
375375
376376_installOrTools () {
377- os=$1
378- osVersion=$2
379- arch=$3
380- orToolsVersionBig=9.11
381- orToolsVersionSmall=${orToolsVersionBig} .4210
377+ local os=$1
378+ local osVersion=$2
379+ local arch=$3
380+ local orToolsVersionBig=9.11
381+ local orToolsVersionSmall=${orToolsVersionBig} .4210
382+
383+ # Define the installation path.
384+ local orToolsPath=${PREFIX:- " /opt/or-tools" }
385+ if command -v brew & > /dev/null; then
386+ orToolsPath=" $( brew --prefix or-tools) "
387+ fi
388+
389+ # Check if a key library file from the installation already exists.
390+ local lib_path=" ${orToolsPath} /lib/libortools.so.${orToolsVersionSmall} "
391+ if [[ -f " ${lib_path} " ]]; then
392+ echo " OR-Tools v${orToolsVersionSmall} is already installed."
393+ CMAKE_PACKAGE_ROOT_ARGS+=" -D ortools_ROOT=$( realpath " ${orToolsPath} " ) "
394+ return
395+ fi
396+
397+ # --- If not installed, proceed with installation ---
398+ echo " OR-Tools v${orToolsVersionSmall} not found. Installing..."
382399
383400 rm -rf " ${baseDir} "
384401 mkdir -p " ${baseDir} "
385- if [[ ! -z " ${PREFIX} " ]]; then mkdir -p " ${PREFIX} " ; fi
402+ if [[ -n " ${PREFIX} " ]]; then mkdir -p " ${PREFIX} " ; fi
386403 cd " ${baseDir} "
387404
388- # Disable exit on error for 'find' command, as it might return non zero
389- set +euo pipefail
390- LIST=($( find /local* /opt* /lib* /usr* /bin* -type f -name " libortools.so*" 2> /dev/null) )
391- # Bring back exit on error
392- set -euo pipefail
393- # Return if right version of or-tools is installed
394- for lib in ${LIST[@]} ; do
395- if [[ " $lib " =~ .* " /libortools.so.${orToolsVersionSmall} " ]]; then
396- echo " OR-Tools is already installed"
397- CMAKE_PACKAGE_ROOT_ARGS+=" -D ortools_ROOT=$( realpath $( dirname $lib ) /..) "
398- return
399- fi
400- done
401-
402- orToolsPath=${PREFIX:- " /opt/or-tools" }
403405 if [ " $( uname -m) " == " aarch64" ]; then
404- echo " OR-TOOLS NOT FOUND"
405- echo " Installing OR-Tools for aarch64..."
406+ echo " Installing OR-Tools for aarch64 from source..."
406407 git clone --depth=1 -b " v${orToolsVersionBig} " https://github.com/google/or-tools.git
407408 cd or-tools
408409 ${cmakePrefix} /bin/cmake -S. -Bbuild -DBUILD_DEPS:BOOL=ON -DBUILD_EXAMPLES:BOOL=OFF -DBUILD_SAMPLES:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -DCMAKE_INSTALL_PREFIX=${orToolsPath} -DCMAKE_CXX_FLAGS=" -w" -DCMAKE_C_FLAGS=" -w"
@@ -415,11 +416,9 @@ _installOrTools() {
415416 # FIXME make do with or-tools for 24.04 until an official release for 25.04 is available
416417 osVersion=24.04
417418 fi
418- orToolsFile=or-tools_${arch} _${os} -${osVersion} _cpp_v${orToolsVersionSmall} .tar.gz
419+ local orToolsFile=or-tools_${arch} _${os} -${osVersion} _cpp_v${orToolsVersionSmall} .tar.gz
419420 eval wget https://github.com/google/or-tools/releases/download/v${orToolsVersionBig} /${orToolsFile}
420- if command -v brew & > /dev/null; then
421- orToolsPath=" $( brew --prefix or-tools) "
422- fi
421+
423422 mkdir -p ${orToolsPath}
424423 tar --strip 1 --dir ${orToolsPath} -xf ${orToolsFile}
425424 rm -rf ${baseDir}
0 commit comments