Meaning of `HDF5_INSTALL_MOD_FORTRAN` value, and the location of fortran `.mod` files

Dear experts.

As the subject says, I’d like to clarify the meaning of HDF5_INSTALL_MOD_FORTRAN.
release_docs/INSTALL_CMake.txt reads:

if (HDF5_BUILD_FORTRAN)
    HDF5_INSTALL_MOD_FORTRAN "Copy FORTRAN mod files to include directory (NO SHARED STATIC)"    SHARED
    if (BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)          default HDF5_INSTALL_MOD_FORTRAN is    SHARED
    if (BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)      default HDF5_INSTALL_MOD_FORTRAN is    SHARED
    if (NOT BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)      default HDF5_INSTALL_MOD_FORTRAN is    STATIC
    if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)  default HDF5_INSTALL_MOD_FORTRAN is    SHARED

What happens if one sets the value to NO?
Inspecting the contents of hdf5-1.14.6-win-vs2022_intel.msi and the accompanying hdf5-config.cmake file in which HDF5_INSTALL_MOD_FORTRAN was set to NO and there’re no *.mod files in the include directory, NO means “no *.mod files are installed in the include directory”.
Is this correct?

But in an installation on of hdf5-1.14.6 my linux PC which was built with Intel OneAPI compiler, HDF5_INSTALL_MOD_FORTRAN=“SHARED” and in this case include, mod/shared,and mod/static all contain *.mod files!
Is this because both shared and static versions of libraries were built?
Then, what is the variable HDF5_INSTALL_MOD_FORTRAN for? Is it better to set the variable to BOTH?

I’ve read a post titled “Unorthodox installation paths for Fortran modules”: what is the status of this issue?

On a Windoze PC on which hdf5-1.14.6-win-vs2022_intel.msi is installed, CMake returns C:/Program Files/HDF_Group/HDF5/1.14.6/include as the value of HDF5_Fortran_INCLUDE_DIRS and therefore the value of the variable cannot be used as is (because there’s NO *.mod files there!).
I’d like to ask the HDF team to at least release the precompiled binary with HDF5_Fortran_INCLUDE_DIRS set to SHARED (but my understanding is that there’s no difference between shared and static versions of *.mod).
Of course, it’s better to install the *.mod files in one place regardless of shared/static libraries when HDF5_BUILD_FORTRAN is ON, and its path is correctly stored/returned in HDF5_Fortran_INCLUDE_DIRS.

Thanks.
Kazuyoshi

HDF5_INSTALL_MOD_FORTRAN was set to NO and there’re no *.mod files in the include directory, NO means “no *.mod files are installed in the include directory”.
Is this correct?

Correct. HDF5_INSTALL_MOD_FORTRAN controls what version of the mod files are installed in the include folder.

include, mod/shared,and mod/static all contain *.mod files!
Is this because both shared and static versions of libraries were built?

Yes, the mod files are first installed in the respective mod folder, then if HDF5_INSTALL_MOD_FORTRAN is set, the appropriate mod files are copied to the include folder.

my understanding is that there’s no difference between shared and static versions of *.mod

That is not exactly true, because mod files are binary files and some compilers/platforms may produce different files, so we leave it up to the user to decide. 1.14.6 release did have a bug in the install files that didn’t set the correct path in the HDF5_INCLUDE_DIR_FORTRAN installation variable (fixed in develop). An easy workaround is to edit the hdf5-config.cmake file in the install location to set the correct path.

my understanding is that there’s no difference between shared and static versions of *.mod

That is not exactly true, because mod files are binary files and some compilers/platforms may produce different files, so we leave it up to the user to decide.

I have to agree with @furutaka.kazuyoshi. There should be no functional difference between MOD files from static vs. shared builds that are otherwise equal in language-specific compiler options. MOD files describe only the characteristics of API’s in the source code, not the binary object code.

This goes to the convenience of carrying only a single copy of MOD files, which will equally serve both static and shared libraries.

Indeed, MOD files are not standardized in general. They differ between different compilers, and sometimes beween different versions of the same compiler. Earlier gfortran version changed their MOD format repeatedly on different major releases. They have gotten more stable recently.

Right there shouldn’t be - and hopefully that is always true - but given that past history has proven otherwise, I’m not inclined to break some applications by forcing a decision.
From my naive view, keeping them separate allows the most options.

@byrn ,thanks for the reply, and thanks for your comment, @dave.allured .

It’s fixed in the Add missing HDF5_INCLUDE_DIR_FORTRAN setting in install (#5613), but the release 1.14.6 and older need some workarounds (in the hdf5-config.cmake itself or in CMakeLists.txt in which find_package(HDF5) is done)… Correct?

Kazuyoshi

release 1.14.6 and older need some workarounds (in the hdf5-config.cmake itself

Right, after install edit thehdf5-config.cmake in the cmake folder that has the config files. Of course those files are used by the CMake findpackage call.