GEOS-ESM / ESMA_cmake

Custom CMake macros for the GEOS Earth System Model
Apache License 2.0
4 stars 9 forks source link

Updates to use Python2 and Python3 at same time #159

Closed mathomp4 closed 3 years ago

mathomp4 commented 3 years ago

This PR essentially adds Python2 and Python3 versions of all the f2py and other Python bits in ESMA_cmake.

Note that this will require changes for anything that uses the macros. For example, before with, say, GFIO we had:

if (F2PY_FOUND)
   if (precision STREQUAL "r4")
   add_f2py_module(GFIO_ SOURCES GFIO_py.F90
      DESTINATION lib/Python
      ONLY gfioopen gfiocreate gfiodiminquire gfioinquire
      gfiogetvar gfiogetvart gfioputvar gfiogetbegdatetime
      gfiointerpxy gfiointerpnn gfiocoordnn gfioclose
      )
   add_dependencies(GFIO_ ${this})
   endif ()
endif ()

Now one would do:

if (USE_F2PY)
   if (precision STREQUAL "r4")
   find_package(F2PY2)
      if (F2PY2_FOUND)
         esma_add_f2py2_module(GFIO_ SOURCES GFIO_py.F90
            DESTINATION lib/Python2
            ONLY gfioopen gfiocreate gfiodiminquire gfioinquire
            gfiogetvar gfiogetvart gfioputvar gfiogetbegdatetime
            gfiointerpxy gfiointerpnn gfiocoordnn gfioclose
            )
         add_dependencies(GFIO_ ${this})
      endif ()
   endif()
endif ()

This moves the USE_F2PY up to each call for f2py as well as the need for a find_package call as well.

Also note that in the PR, esma_add_f2pyX_module() was updated so that it will actually run python -c 'import module' after building the module. This will only work for "simple" f2py modules that don't need other bits of GEOS (aka MAPL)