From 8624d65c5a8bc7b2a40787ce34b120594fc20445 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 2 Dec 2021 15:59:42 +0100 Subject: [PATCH] ENH: support alternative build-root location (#2286) - specify any of these ./Allwmake -build-root=... wmake -build-root=... FOAM_BUILDROOT=... wmake these specify an alternative root where build artifacts are to land. Currently only used as an alternative for the 'build/' hierarchy since the 'platforms/' target normally includes inputs as well. Possible use: ``` ( export WM_MPLIB="%{foam_mplib}" export FOAM_MPI="%{foam_mpi}" export MPI_ARCH_PATH="%{mpi_prefix}" export FOAM_BUILDROOT=/tmp/mpibuild export FOAM_MPI_LIBBIN="$FOAM_BUILDROOT/platforms/$WM_OPTIONS/lib/$FOAM_MPI" src/Pstream/Allwmake-mpi ) ``` --- wmake/scripts/AllwmakeParseArguments | 11 ++++++++++- wmake/scripts/wmakeFunctions | 9 +++++++-- wmake/wmake | 18 +++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/wmake/scripts/AllwmakeParseArguments b/wmake/scripts/AllwmakeParseArguments index a7333dc57b..80453348c5 100644 --- a/wmake/scripts/AllwmakeParseArguments +++ b/wmake/scripts/AllwmakeParseArguments @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2014-2017 OpenFOAM Foundation -# Copyright (C) 2019-2020 OpenCFD Ltd. +# Copyright (C) 2019-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -28,6 +28,8 @@ # Parsed options (wmake) # -debug # -q | -queue +# -build-root=... +# Exports FOAM_BUILDROOT value. # -module-prefix=... # Exports FOAM_MODULE_PREFIX value. # Unsets FOAM_MODULE_APPBIN, FOAM_MODULE_LIBBIN. @@ -107,6 +109,13 @@ do # Pass onwards to other Allwmake scripts ;; + -build-root=*) + # Alternative location for build intermediates + export FOAM_BUILDROOT="${arg#*=}" + echo "Build-root = ${FOAM_BUILDROOT:-[]}" 1>&2 + continue # Argument handled, remove it + ;; + -module-prefix=* | -prefix=* | --prefix=*) # As per setModulePrefix (wmakeFunctions) export FOAM_MODULE_PREFIX="${arg#*=}" diff --git a/wmake/scripts/wmakeFunctions b/wmake/scripts/wmakeFunctions index d564c6883b..5225e90109 100644 --- a/wmake/scripts/wmakeFunctions +++ b/wmake/scripts/wmakeFunctions @@ -214,7 +214,7 @@ cdSource() # - the objectsDir # # Global variables used: -# - WM_PROJECT_DIR, WM_OPTIONS +# - FOAM_BUILDROOT, WM_PROJECT_DIR, WM_OPTIONS findObjectDir() { local project="$(expandPath "$WM_PROJECT_DIR")" @@ -225,8 +225,13 @@ findObjectDir() relativeDir="${absdir#${project}/}" if [ "$relativeDir" != "$absdir" ] then - [ -w "$WM_PROJECT_DIR" ] && \ + if [ -n "$FOAM_BUILDROOT" ] && [ -w "$FOAM_BUILDROOT" ] + then + objectsDir="${FOAM_BUILDROOT}/build/${WM_OPTIONS}/${relativeDir}" + elif [ -w "$WM_PROJECT_DIR" ] + then objectsDir="${WM_PROJECT_DIR}/build/${WM_OPTIONS}/${relativeDir}" + fi fi # Default (local) build directory diff --git a/wmake/wmake b/wmake/wmake index 7410841500..078c27d935 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -37,6 +37,7 @@ # 3. (OR) descend into each sub-directory and repeat. # # Environment +# FOAM_BUILDROOT # FOAM_EXTRA_CFLAGS FOAM_EXTRA_CXXFLAGS FOAM_EXTRA_LDFLAGS # FOAM_MODULE_PREFIX # @@ -69,6 +70,7 @@ if [ -n "$1" ] then cat<&2 + ;; + -module-prefix=*) setModulePrefix "${1#*=}" ;; @@ -599,15 +606,20 @@ fi # files and options being built in parallel #------------------------------------------------------------------------------ -# Mini-version of findObjectDir +# Mini-version of findObjectDir (from wmakeFunctions) unset objectsDir -# Handle project/{applications,src} as out-of-source build +# Handle project/{applications,src} as out-of-source build. relativeDir="${PWD#${WM_PROJECT_DIR}/}" if [ "$relativeDir" != "$PWD" ] then - [ -w "$WM_PROJECT_DIR" ] && \ + if [ -n "$FOAM_BUILDROOT" ] && [ -w "$FOAM_BUILDROOT" ] + then + objectsDir="${FOAM_BUILDROOT}/build/${WM_OPTIONS}/${relativeDir}" + elif [ -w "$WM_PROJECT_DIR" ] + then objectsDir="${WM_PROJECT_DIR}/build/${WM_OPTIONS}/${relativeDir}" + fi fi # Default (local) build directory