diff --git a/CMakeLists.txt b/CMakeLists.txt index c40cd402892d24ccd1a94803e9f8c167037e7781..2f32fcf844ada9c971e2515146e047551cdd0705 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ option(BUILD_ICONMATH_HORIZONTAL "Build horizontal library" ON) option(IM_ENABLE_MIXED_PRECISION "Enable mixed precision" OFF) option(IM_ENABLE_LOOP_EXCHANGE "Enable loop exchange" OFF) +option(IM_USE_CPP_BINDINGS "Use C++ bindings" OFF) option(IM_ENABLE_DIM_SWAP "Enable dimension swap" OFF) option(IM_ENABLE_OPENACC "Enable OpenACC support" OFF) option(IM_ENABLE_OPENMP "Enable OpenMP support" OFF) diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt index 6d2fd781ed1e5d744629c2c3b95263f29ed170b3..c0fc287975ce15018de7f060111d8915b75dfdb4 100644 --- a/src/support/CMakeLists.txt +++ b/src/support/CMakeLists.txt @@ -41,6 +41,10 @@ if(IM_ENABLE_DIM_SWAP) target_compile_definitions(iconmath-support PRIVATE __SWAPDIM) endif() +if(IM_USE_CPP_BINDINGS) + target_compile_definitions(iconmath-support PRIVATE __USE_CPP_BINDINGS) +endif() + if(IM_ENABLE_OPENACC) # If _OPENACC is defined, assume that the required compiler flags are already # provided, e.g. in CMAKE_Fortran_FLAGS: diff --git a/src/support/mo_lib_loopindices.F90 b/src/support/mo_lib_loopindices.F90 index fe6c9b978fccb21ef2d607024c2acda4dc0fd034..3ac80dd5dfee89db03ae783bbf067fc4ae3419cf 100644 --- a/src/support/mo_lib_loopindices.F90 +++ b/src/support/mo_lib_loopindices.F90 @@ -16,12 +16,18 @@ MODULE mo_lib_loopindices +#ifdef __USE_CPP_BINDINGS + USE, INTRINSIC :: ISO_C_BINDING +#endif + IMPLICIT NONE PRIVATE PUBLIC :: get_indices_c_lib, get_indices_e_lib, get_indices_v_lib +#ifndef __USE_CPP_BINDINGS + CONTAINS !------------------------------------------------------------------------- @@ -121,5 +127,31 @@ CONTAINS END SUBROUTINE get_indices_v_lib -END MODULE mo_lib_loopindices +#else + + INTERFACE + SUBROUTINE get_indices_c_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, & + i_startidx_out, i_endidx_out) BIND(C, NAME="get_indices_c_lib") + IMPORT :: C_INT + INTEGER(C_INT), VALUE :: i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk + INTEGER(C_INT) :: i_startidx_out, i_endidx_out + END SUBROUTINE get_indices_c_lib + + SUBROUTINE get_indices_e_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, & + i_startidx_out, i_endidx_out) BIND(C, NAME="get_indices_e_lib") + IMPORT :: C_INT + INTEGER(C_INT), VALUE :: i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk + INTEGER(C_INT) :: i_startidx_out, i_endidx_out + END SUBROUTINE get_indices_e_lib + + SUBROUTINE get_indices_v_lib(i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk, & + i_startidx_out, i_endidx_out) BIND(C, NAME="get_indices_v_lib") + IMPORT :: C_INT + INTEGER(C_INT), VALUE :: i_startidx_in, i_endidx_in, nproma, i_blk, i_startblk, i_endblk + INTEGER(C_INT) :: i_startidx_out, i_endidx_out + END SUBROUTINE get_indices_v_lib + END INTERFACE + +#endif +END MODULE mo_lib_loopindices