diff --git a/etc/config.csh/settings b/etc/config.csh/settings index cc9da12d65..0b5678c8c8 100644 --- a/etc/config.csh/settings +++ b/etc/config.csh/settings @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2016-2022 OpenCFD Ltd. +# Copyright (C) 2016-2025 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -32,7 +32,7 @@ setenv WM_COMPILER_LIB_ARCH # Ending for lib directories if (! $?WM_COMPILE_OPTION ) setenv WM_COMPILE_OPTION # Adjust according to system and architecture -switch ($WM_ARCH) +switch ("$WM_ARCH") case Linux: setenv WM_ARCH linux @@ -74,11 +74,22 @@ case Linux: breaksw # arm64 or x86_64 architectures +# Note: /usr/bin/{gcc,g++} normally just symlinks to clang/clang++ +# which may not behave as expected. case Darwin: setenv WM_ARCH darwin64 if ( "$WM_COMPILER" == Gcc ) then setenv WM_COMPILER Clang - echo "openfoam (darwin): using clang instead of gcc" + # Honour use of gcc, when version=... is specifed in WM_COMPILE_CONTROL + # (eg, gcc installed via homebrew) + if ( $?WM_COMPILE_CONTROL ) then + if ( "$WM_COMPILE_CONTROL" =~ "*version=*" ) then + setenv WM_COMPILER Gcc + endif + endif + if ( "$WM_COMPILER" == Clang ) then + echo "openfoam (darwin): using clang instead of gcc" + endif endif breaksw @@ -214,8 +225,8 @@ _foamEtc -config compiler # ThirdParty base for compilers set archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH" -switch ("$WM_COMPILER_TYPE-$WM_COMPILER") -case ThirdParty-Gcc*: +switch ("${WM_COMPILER_TYPE}/${WM_COMPILER}") +case ThirdParty/Gcc*: if (! $?gmp_version ) set gmp_version=gmp-system if (! $?mpfr_version ) set mpfr_version=mpfr-system if (! $?mpc_version ) set mpc_version=mpc-system @@ -263,7 +274,7 @@ GCC_NOT_FOUND endif breaksw -case ThirdParty-Clang*: +case ThirdParty/Clang*: set clangDir="$archDir/$clang_version" # Check that the compiler directory can be found @@ -290,9 +301,9 @@ CLANG_NOT_FOUND endif breaksw -case -*: -case system-*: -case ThirdParty-*: +case /*: +case system/*: +case ThirdParty/*: # Using empty (system), system compiler or other ThirdParty compiler breaksw diff --git a/etc/config.sh/settings b/etc/config.sh/settings index 7735c4cf41..a615345631 100644 --- a/etc/config.sh/settings +++ b/etc/config.sh/settings @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2016-2022 OpenCFD Ltd. +# Copyright (C) 2016-2025 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -70,13 +70,21 @@ Linux) ;; # arm64 or x86_64 architectures +# Note: /usr/bin/{gcc,g++} normally just symlinks to clang/clang++ +# which may not behave as expected. Darwin) WM_ARCH=darwin64 - # Defult to clang (not gcc) as system compiler if [ "$WM_COMPILER" = Gcc ] then - WM_COMPILER=Clang - echo "openfoam (darwin): using clang instead of gcc" 1>&2 + # Honour use of gcc, when version=... is specifed in WM_COMPILE_CONTROL + # (eg, gcc installed via homebrew) + case "$WM_COMPILE_CONTROL" in + (*version=*) ;; + (*) + WM_COMPILER=Clang + echo "openfoam (darwin): using clang instead of gcc" 1>&2 + ;; + esac fi ;; @@ -217,8 +225,8 @@ _foamEtc -config compiler # ThirdParty base for compilers archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH" -case "$WM_COMPILER_TYPE-$WM_COMPILER" in -ThirdParty-Gcc*) +case "${WM_COMPILER_TYPE}/${WM_COMPILER}" in +(ThirdParty/Gcc*) gccDir="$archDir/$gcc_version" gmpDir="$archDir/${gmp_version:-gmp-system}" mpfrDir="$archDir/${mpfr_version:-mpfr-system}" @@ -259,7 +267,7 @@ GCC_NOT_FOUND fi ;; -ThirdParty-Clang*) +(ThirdParty/Clang*) clangDir="$archDir/$clang_version" # Check that the compiler directory can be found @@ -285,11 +293,11 @@ CLANG_NOT_FOUND fi ;; --* | system-* | ThirdParty-*) +(/* | system/* | ThirdParty/*) # Using empty (system), system compiler or other ThirdParty compiler ;; -*) +(*) /bin/cat << UNKNOWN_TYPE 1>&2 =============================================================================== Unknown WM_COMPILER_TYPE="$WM_COMPILER_TYPE" - treating as 'system' diff --git a/etc/config.sh/umpire b/etc/config.sh/umpire new file mode 100644 index 0000000000..f8db340506 --- /dev/null +++ b/etc/config.sh/umpire @@ -0,0 +1,30 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | www.openfoam.com +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# Copyright (C) 2025 OpenCFD Ltd. +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +# +# File +# etc/config.sh/umpire +# [experimental] +# +# Description +# Setup for UMPIRE include/libraries (usually ThirdParty installation). +# +# Note +# No csh version. This file is only used by wmake. +# +#------------------------------------------------------------------------------ +# USER EDITABLE PART: Changes made here may be lost with the next upgrade + +umpire_version=umpire-2025.03.0 +export UMPIRE_ARCH_PATH="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$umpire_version" + +# END OF (NORMAL) USER EDITABLE PART +#------------------------------------------------------------------------------ diff --git a/src/OSspecific/POSIX/Allwmake b/src/OSspecific/POSIX/Allwmake index 0da34ed520..7bc223e001 100755 --- a/src/OSspecific/POSIX/Allwmake +++ b/src/OSspecific/POSIX/Allwmake @@ -4,12 +4,58 @@ targetType=libo # Preferred library type . ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments $* #------------------------------------------------------------------------------ +# Hack for MacOS (with Gcc). +# The gcc compiler include path has something like this: +# /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include +# +# but xcode flex installs under this: +# /Applications/Xcode.app/Contents/Developer/ +# Toolchains/XcodeDefault.xctoolchain/usr/include + +case "${WM_ARCH}/${WM_COMPILER}" in +(darwin*/Gcc*) + if [ ! -f FlexLexer.h ] + then + # Remove stale link(s) + rm -f FlexLexer.h lnInclude/FlexLexer.h + + for include in \ + /usr/include \ + /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include \ + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include \ + ; + do + if [ -f "$include"/FlexLexer.h ] + then + echo "Adding FlexLexer.h link to ${PWD##*/} (darwin/gcc)" 1>&2 + ln -sf "$include"/FlexLexer.h FlexLexer.h + + if [ -d lnInclude ] + then + (cd lnInclude && ln -sf ../FlexLexer.h .) + fi + break + fi + done + fi + ;; +(*) + if [ -f FlexLexer.h ] + then + echo "Removing old FlexLexer.h link from ${PWD##*/}" 1>&2 + rm -f FlexLexer.h lnInclude/FlexLexer.h + fi + ;; +esac + +#------------------------------------------------------------------------------ + unset COMP_FLAGS LINK_FLAGS # If is available (Linux) if [ -f /usr/include/sys/inotify.h ] then - echo " found -- enabling inotify for file monitoring." + echo " found -- using inotify for file monitoring" 1>&2 export COMP_FLAGS="-DFOAM_USE_INOTIFY" fi diff --git a/wmake/rules/darwin64/link-c b/wmake/rules/darwin64/link-c new file mode 100644 index 0000000000..efaeba873f --- /dev/null +++ b/wmake/rules/darwin64/link-c @@ -0,0 +1,11 @@ +#------------------------------------------------------------------------------ +# Linking on MacOS - without rpath components +#------------------------------------------------------------------------------ + +LINK_LIBS = $(cDBUG) + +LINKLIBSO = $(cc) $(cARCH) -Wl,-dylib,-undefined,dynamic_lookup + +LINKEXE = $(cc) $(cARCH) -Wl,-execute,-undefined,dynamic_lookup + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64/link-c++ b/wmake/rules/darwin64/link-c++ new file mode 100644 index 0000000000..9a3eccfc99 --- /dev/null +++ b/wmake/rules/darwin64/link-c++ @@ -0,0 +1,13 @@ +#------------------------------------------------------------------------------ +# Linking on MacOS +# with or without rpath components +# - current default is with rpath unless explicitly disabled +#------------------------------------------------------------------------------ + +ifneq (,$(findstring ~rpath,$(WM_COMPILE_CONTROL))) + include $(ARCHITECTURE_RULES)/link-no-c++ +else + include $(ARCHITECTURE_RULES)/link-rpath-c++ +endif + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64/link-no-path-c++ b/wmake/rules/darwin64/link-no-path-c++ new file mode 100644 index 0000000000..02d418e941 --- /dev/null +++ b/wmake/rules/darwin64/link-no-path-c++ @@ -0,0 +1,13 @@ +#------------------------------------------------------------------------------ +# Linking on MacOS - without rpath components +#------------------------------------------------------------------------------ + +LINK_LIBS = $(c++DBUG) + +LINKLIBSO = $(CC) $(c++FLAGS) \ + -Wl,-dylib,-undefined,dynamic_lookup + +LINKEXE = $(CC) $(c++FLAGS) \ + -Wl,-execute,-undefined,dynamic_lookup + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64Clang/link-rpath-c++ b/wmake/rules/darwin64/link-rpath-c++ similarity index 75% rename from wmake/rules/darwin64Clang/link-rpath-c++ rename to wmake/rules/darwin64/link-rpath-c++ index f7a7cd6001..9fa0c6aa5b 100644 --- a/wmake/rules/darwin64Clang/link-rpath-c++ +++ b/wmake/rules/darwin64/link-rpath-c++ @@ -1,5 +1,8 @@ #------------------------------------------------------------------------------ -include $(DEFAULT_RULES)/rpath +# Linking on MacOS - with rpath components +#------------------------------------------------------------------------------ + +include $(ARCHITECTURE_RULES)/rpath LINK_LIBS = $(c++DBUG) diff --git a/wmake/rules/darwin64Clang/rpath b/wmake/rules/darwin64/rpath similarity index 88% rename from wmake/rules/darwin64Clang/rpath rename to wmake/rules/darwin64/rpath index 834b8f1693..e6d61e0408 100644 --- a/wmake/rules/darwin64Clang/rpath +++ b/wmake/rules/darwin64/rpath @@ -1,4 +1,6 @@ #------------------------------------------------------------------------------ +# Linking with rpath components (MacOS) +#------------------------------------------------------------------------------ # Compile-time rpath information: diff --git a/wmake/rules/darwin64Clang/c b/wmake/rules/darwin64Clang/c index 3083b281ed..0ad4dc8a37 100644 --- a/wmake/rules/darwin64Clang/c +++ b/wmake/rules/darwin64Clang/c @@ -17,10 +17,7 @@ cFLAGS = \ ctoo = $(WM_SCHEDULER) $(cc) $(cFLAGS) -c $< -o $@ -LINK_LIBS = $(cDBUG) - -LINKLIBSO = $(cc) $(cARCH) -Wl,-dylib,-undefined,dynamic_lookup - -LINKEXE = $(cc) $(cARCH) -Wl,-execute,-undefined,dynamic_lookup +# MacOS linking +include $(ARCHITECTURE_RULES)/link-c #------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64Clang/c++ b/wmake/rules/darwin64Clang/c++ index 7793657344..746b3fe7b3 100644 --- a/wmake/rules/darwin64Clang/c++ +++ b/wmake/rules/darwin64Clang/c++ @@ -21,15 +21,7 @@ cpptoo = $(Ctoo) cxxtoo = $(Ctoo) -# Linking: -# with or without rpath components on MacOS -# - current default is with rpath unless explicitly disabled - -ifneq (,$(findstring ~rpath,$(WM_COMPILE_CONTROL))) - include $(DEFAULT_RULES)/link-c++ - -else - include $(DEFAULT_RULES)/link-rpath-c++ -endif +# MacOS linking (with or without rpath components) +include $(ARCHITECTURE_RULES)/link-c++ #------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64Clang/link-c++ b/wmake/rules/darwin64Clang/link-c++ deleted file mode 100644 index d1c1f6e6a7..0000000000 --- a/wmake/rules/darwin64Clang/link-c++ +++ /dev/null @@ -1,9 +0,0 @@ -#------------------------------------------------------------------------------ - -LINK_LIBS = $(c++DBUG) - -LINKLIBSO = $(CC) $(c++FLAGS) -Wl,-dylib,-undefined,dynamic_lookup - -LINKEXE = $(CC) $(c++FLAGS) -Wl,-execute,-undefined,dynamic_lookup - -#------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64Gcc/c b/wmake/rules/darwin64Gcc/c new file mode 100644 index 0000000000..cf3924bb6c --- /dev/null +++ b/wmake/rules/darwin64Gcc/c @@ -0,0 +1,23 @@ +#------------------------------------------------------------------------------ +include $(GENERAL_RULES)/Gcc/c + +## ifneq (,$(findstring +xcrun,$(WM_COMPILE_CONTROL))) +## cc := xcrun cc +## endif + +cARCH := -m64 -ftrapping-math + +ifneq (,$(strip $(WM_COMPILE_OPTION))) + sinclude $(DEFAULT_RULES)/c$(WM_COMPILE_OPTION) +endif + +cFLAGS = \ + $(cARCH) $(GFLAGS) $(cWARN) $(cOPT) $(cDBUG) \ + $(FOAM_EXTRA_CFLAGS) $(LIB_HEADER_DIRS) -fPIC + +ctoo = $(WM_SCHEDULER) $(cc) $(cFLAGS) -c $< -o $@ + +# MacOS linking +include $(ARCHITECTURE_RULES)/link-c + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64Gcc/c++ b/wmake/rules/darwin64Gcc/c++ new file mode 100644 index 0000000000..e10fcaa713 --- /dev/null +++ b/wmake/rules/darwin64Gcc/c++ @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------ +include $(GENERAL_RULES)/Gcc/c++ + +## ifneq (,$(findstring +xcrun,$(WM_COMPILE_CONTROL))) +## CC := xcrun c++ -std=c++17 +## endif + +c++ARCH := -m64 -pthread -ftrapping-math + +ifneq (,$(strip $(WM_COMPILE_OPTION))) + sinclude $(DEFAULT_RULES)/c++$(WM_COMPILE_OPTION) +endif + +c++FLAGS = \ + $(c++ARCH) $(GFLAGS) $(c++WARN) $(c++OPT) $(c++DBUG) $(ptFLAGS) \ + $(FOAM_EXTRA_CXXFLAGS) $(LIB_HEADER_DIRS) -fPIC + +Ctoo = $(WM_SCHEDULER) $(CC) $(c++FLAGS) -c $< -o $@ +cctoo = $(Ctoo) +cpptoo = $(Ctoo) +cxxtoo = $(Ctoo) + + +# MacOS linking (with or without rpath components) +include $(ARCHITECTURE_RULES)/link-c++ + +#------------------------------------------------------------------------------ diff --git a/wmake/rules/darwin64Gcc/general b/wmake/rules/darwin64Gcc/general new file mode 100644 index 0000000000..64c1945a66 --- /dev/null +++ b/wmake/rules/darwin64Gcc/general @@ -0,0 +1,16 @@ +CPP = cpp -traditional-cpp $(GFLAGS) + +include $(GENERAL_RULES)/standard +include $(GENERAL_RULES)/Gcc/openmp + +ifneq (,$(findstring ~openmp,$(WM_COMPILE_CONTROL))) + include $(GENERAL_RULES)/no-openmp +endif + +include $(DEFAULT_RULES)/c +include $(DEFAULT_RULES)/c++ + +# Shared library extension (with '.' separator) +EXT_SO = .dylib + +# ----------------------------------------------------------------------------- diff --git a/wmake/scripts/have_umpire b/wmake/scripts/have_umpire new file mode 100644 index 0000000000..46991e678b --- /dev/null +++ b/wmake/scripts/have_umpire @@ -0,0 +1,169 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | www.openfoam.com +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# Copyright (C) 2025 OpenCFD Ltd. +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +# +# Script +# have_umpire +# +# Description +# Detection/setup of UMPIRE +# +# Requires +# UMPIRE_ARCH_PATH +# +# Functions provided +# have_umpire, no_umpire, echo_umpire, query_umpire, search_umpire +# +# Variables set on success +# HAVE_UMPIRE +# UMPIRE_ARCH_PATH +# UMPIRE_INC_DIR +# UMPIRE_LIB_DIR +# +#------------------------------------------------------------------------------ +. ${WM_PROJECT_DIR:?}/wmake/scripts/sysFunctions # General system functions + +#------------------------------------------------------------------------------ + +# Reset +no_umpire() +{ + unset HAVE_UMPIRE UMPIRE_INC_DIR UMPIRE_LIB_DIR +} + + +# Report +echo_umpire() +{ + echo "umpire=${HAVE_UMPIRE:-false}" + echo "root=\"$UMPIRE_ARCH_PATH\"" + echo "include=\"$UMPIRE_INC_DIR\"" + echo "library=\"$UMPIRE_LIB_DIR\"" +} + + +# Search +# $1 : prefix (*_ARCH_PATH, system, ...) +# +# On success, return 0 and export variables +# -> HAVE_UMPIRE, UMPIRE_INC_DIR, UMPIRE_LIB_DIR +search_umpire() +{ + local warn # warn="==> skip umpire" + local incName="Umpire.hpp" + local libName="libumpire" + + local prefix="${1:-system}" + local header library + + # ---------------------------------- + if isNone "$prefix" + then + [ -n "$warn" ] && echo "$warn (disabled)" + return 1 + elif hasAbsdir "$prefix" + then + header=$(findFirstFile "$prefix/include/umpire/$incName") + library=$(findExtLib "$libName") + elif isSystem "$prefix" + then + header=$(findFirstFile \ + "/usr/local/include/umpire/$incName" \ + "/usr/include/umpire/$incName" \ + ) + prefix=$(sysPrefix "$header") + else + unset prefix + fi + # ---------------------------------- + + # Header + [ -n "$header" ] || { + [ -n "$warn" ] && echo "$warn (no header)" + return 2 + } + + # Library + [ -n "$library" ] \ + || library=$(findLibrary -prefix="$prefix" -name="$libName") \ + || { + [ -n "$warn" ] && echo "$warn (no library)" + return 2 + } + + # ---------------------------------- + + # OK + export HAVE_UMPIRE=true + export UMPIRE_ARCH_PATH="$prefix" + export UMPIRE_INC_DIR="${header%/*}" # Basename + export UMPIRE_LIB_DIR="${library%/*}" # Basename + + # Expect path/include/umpire -> path/include + UMPIRE_INC_DIR="${UMPIRE_INC_DIR%/umpire}" +} + + +# Output as per search_* function +have_umpire() +{ + local warn # warn="==> skip umpire" + local config="config.sh/umpire" + local file + + if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")" + then + . "$file" + else + [ -n "$warn" ] && echo "$warn (no $config)" + return 2 + fi + + search_umpire "$UMPIRE_ARCH_PATH" +} + + +# Query settings +query_umpire() +{ + local config="config.sh/umpire" + local file + + if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")" + then + . "$file" + _process_query umpire "$UMPIRE_ARCH_PATH" + else + echo "(no $config)" 1>&2 + echo "umpire=unknown" + fi +} + + +#------------------------------------------------------------------------------ + +# Reset +no_umpire + +# Test/query +case "$1" in +-test | -debug-test) + [ "$1" = "-debug-test" ] && set -x + have_umpire + [ "$1" = "-debug-test" ] && set +x + echo_umpire + ;; +-query) + query_umpire + ;; +esac + +#------------------------------------------------------------------------------