From b4420e712ad557e175f5f93e2c0e3b614053fcfa Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Sat, 28 Feb 2026 17:06:25 -0500 Subject: [PATCH 1/3] v3: Updates for macOS Flang from Homebrew --- CHANGELOG.md | 2 ++ operating_system/osx_extras.cmake | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b57ed8f..4e5a291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixes for using Homebrew flang on macOS + ### Removed ### Added diff --git a/operating_system/osx_extras.cmake b/operating_system/osx_extras.cmake index 063db8d..d3b9f03 100644 --- a/operating_system/osx_extras.cmake +++ b/operating_system/osx_extras.cmake @@ -56,3 +56,13 @@ set (ENABLE_RELATIVE_RPATHS FALSE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-headerpad_max_install_names") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-headerpad_max_install_names") + +# 5) Flang compiler workarounds for macOS shared libraries +# CMake natively uses Apple's '-dynamiclib' and '-install_name' for shared libraries, +# but the LLVM flang frontend strictly rejects them. +# We force flang to use '-shared' (which it correctly translates down to the linker) +# and use -Xlinker to safely pass the soname without space-parsing errors. +if(CMAKE_Fortran_COMPILER_ID MATCHES "Flang" OR CMAKE_Fortran_COMPILER_ID MATCHES "LLVMFlang") + set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-shared -Wl,-headerpad_max_install_names") + set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Xlinker -install_name -Xlinker ") +endif() From f7b2b527f14d20ff2009e63c06c4ecb023732f9b Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Fri, 6 Mar 2026 08:40:30 -0500 Subject: [PATCH 2/3] add extra flag --- compiler/flags/LLVMFlang_Fortran.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/flags/LLVMFlang_Fortran.cmake b/compiler/flags/LLVMFlang_Fortran.cmake index 0b90b50..d589b16 100644 --- a/compiler/flags/LLVMFlang_Fortran.cmake +++ b/compiler/flags/LLVMFlang_Fortran.cmake @@ -68,7 +68,7 @@ set (common_Fortran_fpe_flags "${TRACEBACK}") # GEOS Debug # ---------- -set (GEOS_Fortran_Debug_Flags "${FOPT0} ${DEBINFO}") +set (GEOS_Fortran_Debug_Flags "${FOPT0} ${DEBINFO} -fno-omit-frame-pointer") set (GEOS_Fortran_Debug_FPE_Flags "${common_Fortran_fpe_flags}") # GEOS Release From 42b3662cbdaf7dc8f3e1fdab2ea65a84c63a9dbe Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Mon, 9 Mar 2026 13:08:25 -0400 Subject: [PATCH 3/3] Flags for macOS --- CHANGELOG.md | 2 ++ compiler/flags/LLVMFlang_Fortran.cmake | 26 ++++++++++++++++---------- operating_system/osx_extras.cmake | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 376a9ed..305a91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Enable flang architecture flags + ### Deprecated ## [3.74.0] - 2026-03-09 diff --git a/compiler/flags/LLVMFlang_Fortran.cmake b/compiler/flags/LLVMFlang_Fortran.cmake index d589b16..820aaea 100644 --- a/compiler/flags/LLVMFlang_Fortran.cmake +++ b/compiler/flags/LLVMFlang_Fortran.cmake @@ -35,20 +35,29 @@ set (ARCH_CONSISTENCY "") set (FTZ "") set (ALIGN_ALL "") set (NO_ALIAS "") +set (STACK_ARRAYS "-fstack-arrays") set (NO_RANGE_CHECK "") +set(NO_FMA "-ffp-contract=off") + +# NOTE: There is currently a bug(?) in flang that says you have to pass +# -fno-integrated-as when doing save temps (see https://github.com/llvm/llvm-project/pull/119624) +# It does seem to work, but a PR says this might have issues with offloading: +# NOTE 2: I found a bug with this and flang: https://github.com/llvm/llvm-project/issues/184802 +# Turning off for now. +#set(SAVE_TEMPS "-fno-integrated-as -save-temps=obj") + cmake_host_system_information(RESULT proc_description QUERY PROCESSOR_DESCRIPTION) -# NOT SURE ABOUT ANY OF THIS... if ( ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL aarch64 ) - set (FLANG_TARGET_ARCH "-mcpu=armv8.2-a+crypto+crc+fp16+rcpc+dotprod") + set (FLANG_TARGET_ARCH "armv8.2-a+crypto+crc+fp16+rcpc+dotprod") elseif (${proc_description} MATCHES "Apple M") - set (FLANG_TARGET_ARCH "-mcpu=apple-m1") + set (FLANG_TARGET_ARCH "apple-m1") elseif (${proc_description} MATCHES "EPYC") - set (FLANG_TARGET_ARCH "-mcpu=znver2") + set (FLANG_TARGET_ARCH "znver2") elseif (${proc_description} MATCHES "Intel|INTEL") - set (FLANG_TARGET_ARCH "-mcpu=haswell") + set (FLANG_TARGET_ARCH "haswell") elseif ( ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64" ) message(WARNING "Unknown processor type. Defaulting to a generic x86_64 processor. Performance may be suboptimal.") set (FLANG_TARGET_ARCH "x86-64") @@ -56,9 +65,6 @@ else () message(FATAL_ERROR "Unknown processor. Please file an issue at https://github.com/GEOS-ESM/ESMA_cmake") endif () -# ...SO WE JUST TURN OFF FLANG_TARGET_ARCH FOR NOW -set (FLANG_TARGET_ARCH "") - #################################################### # Common Fortran Flags @@ -68,12 +74,12 @@ set (common_Fortran_fpe_flags "${TRACEBACK}") # GEOS Debug # ---------- -set (GEOS_Fortran_Debug_Flags "${FOPT0} ${DEBINFO} -fno-omit-frame-pointer") +set (GEOS_Fortran_Debug_Flags "${FOPT0} ${DEBINFO} ${SAVE_TEMPS} ${NO_FMA}") set (GEOS_Fortran_Debug_FPE_Flags "${common_Fortran_fpe_flags}") # GEOS Release # ------------ -set (GEOS_Fortran_Release_Flags "${FOPT3} ${FLANG_TARGET_ARCH} ${DEBINFO}") +set (GEOS_Fortran_Release_Flags "${FOPT3} -march=${FLANG_TARGET_ARCH} -funroll-loops ${STACK_ARRAYS} ${DEBINFO}") set (GEOS_Fortran_Release_FPE_Flags "${common_Fortran_fpe_flags}") # Create a NoVectorize version for consistency. No difference from Release for Flang diff --git a/operating_system/osx_extras.cmake b/operating_system/osx_extras.cmake index d3b9f03..38adbe0 100644 --- a/operating_system/osx_extras.cmake +++ b/operating_system/osx_extras.cmake @@ -59,7 +59,7 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-headerpad_max_i # 5) Flang compiler workarounds for macOS shared libraries # CMake natively uses Apple's '-dynamiclib' and '-install_name' for shared libraries, -# but the LLVM flang frontend strictly rejects them. +# but the LLVM flang frontend strictly rejects them. # We force flang to use '-shared' (which it correctly translates down to the linker) # and use -Xlinker to safely pass the soname without space-parsing errors. if(CMAKE_Fortran_COMPILER_ID MATCHES "Flang" OR CMAKE_Fortran_COMPILER_ID MATCHES "LLVMFlang")