Skip to content

Commit

Permalink
Merge pull request #374 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mathomp4 authored Apr 25, 2024
2 parents a07748d + 571476f commit ed3a043
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 26 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deprecated

## [3.45.0] - 2024-04-25

### Fixed

- Edit `FindESMF.cmake` to use `ESMF::ESMF` as the primary target and make `ESMF` an alias for `ESMF::ESMF` if it doesn't exist
- Updates for building with Clang on macOS
- Add `-Wl,-ld_classic` to linker flags for all macOS
- Add `-Wno-implicit-int` for Clang on macOS
- Fix for using f2py and Python 3.12

### Added

- Add suppression of remark 10488 for Intel Fortran Classic which is a warning about ifort deprecation in late 2024

## [3.44.0] - 2024-03-29

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions compiler/flags/GNU_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ else ()
message(FATAL_ERROR "Unknown processor. Please file an issue at https://github.com/GEOS-ESM/ESMA_cmake")
endif ()

if (APPLE)
# We seem to now require (sometimes?) the use of ld_classic if on Apple
add_link_options(-Wl,-ld_classic)

# Also, if our C compiler is Apple Clang, we need to pass -Wno-implicit-int to our C flags
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-implicit-int")
endif ()
endif ()

####################################################

add_definitions(-D__GFORTRAN__)
Expand Down
5 changes: 4 additions & 1 deletion compiler/flags/Intel_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ set (DISABLE_10337 "-diag-disable 10337")
## Turn off ifort: command line warning #10121: overriding '-fp-model precise' with '-fp-model fast'
set (DISABLE_10121 "-diag-disable 10121")

## Turn off remark #10448 warning about ifort deprecation in late 2024
set (DISABLE_10448 "-diag-disable=10448")

set (NO_RANGE_CHECK "")

cmake_host_system_information(RESULT proc_description QUERY PROCESSOR_DESCRIPTION)
Expand Down Expand Up @@ -112,7 +115,7 @@ endif ()
# Common Fortran Flags
# --------------------
set (common_Fortran_flags "${TRACEBACK} ${REALLOC_LHS} ${OPTREPORT0} ${ALIGN_ALL} ${NO_ALIAS}")
set (common_Fortran_fpe_flags "${FTZ} ${NOOLD_MAXMINLOC} ${DISABLE_10121}")
set (common_Fortran_fpe_flags "${FTZ} ${NOOLD_MAXMINLOC} ${DISABLE_10121} ${DISABLE_10448}")

# GEOS Debug
# ----------
Expand Down
26 changes: 14 additions & 12 deletions external_libraries/FindBaselibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif ()
# In CMake this is CMAKE_HOST_SYSTEM_NAME

if (BASEDIR)

# First, what if we have a BASEDIR/lib, let's make sure it's like we want
# That is, it has ARCH and it's the *right* ARCH!
if (IS_DIRECTORY ${BASEDIR}/lib)
Expand Down Expand Up @@ -153,22 +153,24 @@ if (Baselibs_FOUND)
set (ESMFMKFILE "${BASEDIR}/lib/esmf.mk" CACHE PATH "Path to esmf.mk file" FORCE)
message(STATUS "ESMFMKFILE: ${ESMFMKFILE}")

# Now, let us use the FindESMF.cmake that ESMF itself includes and installs
list (APPEND CMAKE_MODULE_PATH "${BASEDIR}/include/esmf")
# Now we can use FindESMF.cmake to find ESMF. This uses the one in the current
# directory, not the one in the ESMF installation. The one here uses
# ESMF::ESMF as the main target
find_package(ESMF MODULE REQUIRED)

# Also, we know ESMF from Baselibs requires MPI (note that this isn't always true, but
# for ESMF built in Baselibs for use in GEOS, it currently is)
target_link_libraries(ESMF INTERFACE MPI::MPI_Fortran)

# Finally, we add an alias since GEOS (at the moment) uses esmf not ESMF for the target
add_library(esmf ALIAS ESMF)
target_link_libraries(ESMF::ESMF INTERFACE MPI::MPI_Fortran)

# We also add an alias for the target ESMF::ESMF. This will eventually be
# added to `FindESMF.cmake` in ESMF, but for now we do it here. To be safe,
# we only add the alias if it doesn't already exist.
if (NOT TARGET ESMF::ESMF)
add_library(ESMF::ESMF ALIAS ESMF)
# Finally, we add aliases since GEOS (at the moment) uses esmf and ESMF for the target
# instead of ESMF::ESMF (MAPL uses ESMF::ESMF)
if (NOT TARGET ESMF)
message(STATUS "ESMF alias not found, creating ESMF alias")
add_library(ESMF ALIAS ESMF::ESMF)
endif ()
if (NOT TARGET esmf)
message(STATUS "esmf alias not found, creating esmf alias")
add_library(esmf ALIAS ESMF::ESMF)
endif ()
endif ()

Expand Down
16 changes: 8 additions & 8 deletions external_libraries/FindESMF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ if(EXISTS ${ESMFMKFILE})
message(WARNING "Static ESMF library (libesmf.a) not found in \
${ESMF_LIBSDIR}. Try setting USE_ESMF_STATIC_LIBS=OFF")
endif()
if(NOT TARGET ESMF)
add_library(ESMF STATIC IMPORTED)
if(NOT TARGET ESMF::ESMF)
add_library(ESMF::ESMF STATIC IMPORTED)
endif()
else()
find_library(ESMF_LIBRARY_LOCATION NAMES esmf PATHS ${ESMF_LIBSDIR} NO_DEFAULT_PATH)
if(ESMF_LIBRARY_LOCATION MATCHES "ESMF_LIBRARY_LOCATION-NOTFOUND")
message(WARNING "ESMF library not found in ${ESMF_LIBSDIR}.")
endif()
if(NOT TARGET ESMF)
add_library(ESMF UNKNOWN IMPORTED)
if(NOT TARGET ESMF::ESMF)
add_library(ESMF::ESMF UNKNOWN IMPORTED)
endif()
endif()

# Add target alias to facilitate unambiguous linking
if(NOT TARGET ESMF::ESMF)
add_library(ESMF::ESMF ALIAS ESMF)
# Add ESMF as an alias to ESMF::ESMF for backward compatibility
if(NOT TARGET ESMF)
add_library(ESMF ALIAS ESMF::ESMF)
endif()

# Add ESMF include directories
Expand All @@ -135,7 +135,7 @@ if(EXISTS ${ESMFMKFILE})
ESMF_F90COMPILEPATHS
VERSION_VAR ESMF_VERSION)

set_target_properties(ESMF PROPERTIES
set_target_properties(ESMF::ESMF PROPERTIES
IMPORTED_LOCATION "${ESMF_LIBRARY_LOCATION}"
INTERFACE_INCLUDE_DIRECTORIES "${ESMF_INCLUDE_DIRECTORIES}"
INTERFACE_LINK_LIBRARIES "${ESMF_INTERFACE_LINK_LIBRARIES}")
Expand Down
57 changes: 52 additions & 5 deletions python/f2py3/UseF2Py3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,32 @@ macro (add_f2py3_module _name)

#message(STATUS "${_name} F2PY3_Fortran_FLAGS ${F2PY3_Fortran_FLAGS}")

set(_fcompiler_opts "--fcompiler=${F2PY3_FCOMPILER}")
list(APPEND _fcompiler_opts "--f77exec=${CMAKE_Fortran_COMPILER}" "--f77flags='${F2PY3_Fortran_FLAGS}'")
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
list(APPEND _fcompiler_opts "--f90exec=${CMAKE_Fortran_COMPILER}" "--f90flags='${F2PY3_Fortran_FLAGS}'")
endif(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
# NOTE: This style of calling f2py is only for distutils. If you are using
# Python 3.12, the backend is now meson and this will not work
# so we need to test the Python version and then call the correct
# f2py

if (Python3_VERSION VERSION_GREATER 3.11)
set(F2PY3_BACKEND "meson")
else ()
set(F2PY3_BACKEND "distutils")
endif ()

message(STATUS "Using F2PY3_BACKEND: ${F2PY3_BACKEND}")

if (F2PY3_BACKEND STREQUAL "distutils")
set(_fcompiler_opts "--fcompiler=${F2PY3_FCOMPILER}")
list(APPEND _fcompiler_opts "--f77exec=${CMAKE_Fortran_COMPILER}" "--f77flags='${F2PY3_Fortran_FLAGS}'")
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
list(APPEND _fcompiler_opts "--f90exec=${CMAKE_Fortran_COMPILER}" "--f90flags='${F2PY3_Fortran_FLAGS}'")
endif(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
else ()
set(_fcompiler_opts "")
list(APPEND _fcompiler_opts "--f77flags='${F2PY3_Fortran_FLAGS}'")
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
list(APPEND _fcompiler_opts "--f90flags='${F2PY3_Fortran_FLAGS}'")
endif(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
endif ()

# Make the source filenames absolute.
set(_abs_srcs)
Expand All @@ -87,6 +108,13 @@ macro (add_f2py3_module _name)
list(APPEND _abs_srcs ${_abs_src})
endforeach(_src ${add_f2py3_module_SOURCES})

# Let's also get all directories that the sources are in
set(_src_inc_dirs)
foreach(_src ${_abs_srcs})
get_filename_component(_dir ${_src} DIRECTORY)
list(APPEND _src_inc_dirs ${_dir})
endforeach(_src ${_abs_srcs})

# Get a list of the include directories.
# The f2py3 --include_paths option, used when generating a signature file,
# needs a colon-separated list. The f2py3 -I option, used when compiling
Expand All @@ -103,6 +131,12 @@ macro (add_f2py3_module _name)
endforeach(_dir)
string(REPLACE ";" ":" _inc_paths "${_inc_dirs}")

# We also want to include the directory where the
# sources are located as well into _inc_opts
foreach(_dir ${_src_inc_dirs})
list(APPEND _inc_opts "-I${_dir}")
endforeach(_dir)

set(_libs_opts)
foreach(_lib ${add_f2py3_module_LIBRARIES})
# MAT This is hacky, but so is this whole code
Expand Down Expand Up @@ -227,6 +261,18 @@ macro (add_f2py3_module _name)

# Define the command to generate the Fortran to Python3 interface module. The
# output will be a shared library that can be imported by python.
# We also need to set FC in the environment to the fortran compiler
#message(STATUS "add_f2py3_module_SOURCES: ${add_f2py3_module_SOURCES}")
#message(STATUS "_inc_opts: ${_inc_opts}")
if ( F2PY3_BACKEND STREQUAL "meson")
add_custom_command(OUTPUT "${_name}${F2PY3_SUFFIX}"
COMMAND ${CMAKE_COMMAND} -E env "FC=${CMAKE_Fortran_COMPILER}"
${F2PY3_EXECUTABLE} ${F2PY_QUIET} -m ${_name}
--build-dir "${CMAKE_CURRENT_BINARY_DIR}/f2py3-${_name}"
${_fcompiler_opts} ${_inc_opts} -c ${_abs_srcs} ${REDIRECT_TO_DEV_NULL}
DEPENDS ${add_f2py3_module_SOURCES}
COMMENT "[F2PY3] Building Fortran to Python3 interface module ${_name}")
else ()
if ( "${add_f2py3_module_SOURCES}" MATCHES "^[^;]*\\.pyf;" )
add_custom_command(OUTPUT "${_name}${F2PY3_SUFFIX}"
COMMAND ${F2PY3_EXECUTABLE} ${F2PY_QUIET} -m ${_name}
Expand All @@ -246,6 +292,7 @@ macro (add_f2py3_module _name)
DEPENDS ${add_f2py3_module_SOURCES}
COMMENT "[F2PY3] Building Fortran to Python3 interface module ${_name}")
endif ( "${add_f2py3_module_SOURCES}" MATCHES "^[^;]*\\.pyf;" )
endif ()



Expand Down

0 comments on commit ed3a043

Please sign in to comment.