In tests/general/util/pio_tutil.F90, several macros, namely _NETCDF4,
_NETCDF, _PNETCDF, _ADIOS2, and _HDF5, are utilized.
In the case of NetCDF/PnetCDF libraries, the macros _NETCDF4,
_NETCDF, and _PNETCDF are directly defined for lib piof in
src/flib/CMakeLists.txt:
#===== NetCDF-Fortran =====
if (WITH_NETCDF)
find_package (NetCDF ${NETCDF_FORTRAN_MIN_VER_REQD} COMPONENTS Fortran)
if (NetCDF_Fortran_FOUND)
message(STATUS "NetCDF Fortran library dependencies: ${NetCDF_Fortran_LIBRARIES}")
...
target_compile_definitions (piof
PUBLIC _NETCDF)
...
if (EXISTS ${NetCDF_Fortran_INCLUDE_DIR}/netcdf_par.h)
target_compile_definitions (piof
PUBLIC _NETCDF4)
...
#===== PnetCDF =====
if (WITH_PNETCDF)
find_package (PnetCDF ${PNETCDF_MIN_VER_REQD} COMPONENTS Fortran)
if (PnetCDF_FOUND)
message(STATUS "PnetCDF Fortran library dependencies: ${PnetCDF_Fortran_LIBRARIES}")
...
target_compile_definitions (piof
PUBLIC _PNETCDF)
However, for ADIOS2/HDF5 libraries, where no Fortran components
are available, the direct definition of _ADIOS2 and _HDF5 for lib
piof in src/flib/CMakeLists.txt is not feasible.
To overcome this limitation, a workaround is to define these macros
for lib pioc in src/clib/CMakeLists.txt. Consequently, they are indirectly
defined for lib piof.
For _HDF5, it will be something like:
#===== HDF5-C =====
if (WITH_HDF5)
find_package (HDF5 COMPONENTS HL C)
if (HDF5_C_FOUND)
...
target_compile_definitions (pioc
PUBLIC _HDF5)
The current definition of _ADIOS2 for lib adios2pio-nm-lib in
tools/adios2pio-nm/CMakeLists.txt may need to be relocated to
src/clib/CMakeLists.txt to ensure consistency for lib pioc:
if (ADIOS2_FOUND)
target_compile_definitions (adios2pio-nm-lib
PUBLIC _ADIOS2)
It is worth noting that this workaround introduces a minor issue
related to duplicate macro definitions. On one hand, _ADIOS2 and
_HDF5 are defined using CMake's target_compile_definitions() for
lib pioc. On the other hand, they are also explicitly defined in
pio.h of lib pioc:
In tests/general/util/pio_tutil.F90, several macros, namely _NETCDF4, _NETCDF, _PNETCDF, _ADIOS2, and _HDF5, are utilized.
In the case of NetCDF/PnetCDF libraries, the macros _NETCDF4, _NETCDF, and _PNETCDF are directly defined for lib piof in src/flib/CMakeLists.txt:
However, for ADIOS2/HDF5 libraries, where no Fortran components are available, the direct definition of _ADIOS2 and _HDF5 for lib piof in src/flib/CMakeLists.txt is not feasible.
To overcome this limitation, a workaround is to define these macros for lib pioc in src/clib/CMakeLists.txt. Consequently, they are indirectly defined for lib piof.
For _HDF5, it will be something like:
The current definition of _ADIOS2 for lib adios2pio-nm-lib in tools/adios2pio-nm/CMakeLists.txt may need to be relocated to src/clib/CMakeLists.txt to ensure consistency for lib pioc:
It is worth noting that this workaround introduces a minor issue related to duplicate macro definitions. On one hand, _ADIOS2 and _HDF5 are defined using CMake's target_compile_definitions() for lib pioc. On the other hand, they are also explicitly defined in pio.h of lib pioc: