The current git HEAD seems to force HDF5_THREADS_ENABLED=ON if Threads_FOUND=true after find_package (Threads) even if one doesn’t want to use it.
I think this is the cause of the failure in configuring my FORTRAN project using HDF5(dev):
CMake Error at /usr/share/cmake/Modules/FindThreads.cmake:66 (message):
FindThreads only works if either C or CXX language is enabled
The library was built with the following configuration: FC=gfortran-14 CC=gcc-14 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTING:BOOL=ON -DHDF5_BUILD_TOOLS:BOOL=ON -DHDF5_BUILD_FORTRAN=ON -DHDF5_THREADS_ENABLED=OFF ../hdf5.git/
How can I fix this issue?
How can I turn off the use of Threads?
I must confess that I’m not sure we need to do so. I’m not an expert and therefore I don’t know the intention of the modification #5523.
I just want to use the HDF5 library as I do now for my FORTRAN project. If the threading is a must-have and I can easily enable (p?)threading with fortran on ordinary linux boxes (w/ e.g. gfortran), I’ll do it (but I’d like to know how to do it)
Well… Googling and only adding " C CXX" after “Fortran” in the project() in the CMakeLists.txt file of our FORTRAN-only project, I managed to do cmake.
Therefore, at this moment, I don’t need to revert the PR (I don’t know what it is for).
This isn’t strictly necessary for your use case and should probably be fixed in the current HDF5 development branch. A temporary workaround would be to edit the CMake configuration file installed by HDF5 (under cmake/hdf5-config.cmake on Linux) and change the value of the line
set (${HDF5_PACKAGE_NAME}_THREADS_ENABLED ON)
to
set (${HDF5_PACKAGE_NAME}_THREADS_ENABLED OFF)
Note that HDF5_THREADS_ENABLED is not something that is user-controlled at the moment, so passing this as an option likely doesn’t have an effect.
The long answer:
Threading support should only be enabled and required when actually required by HDF5 due to some feature being built in. But the logic in the CMake configuration file installed by HDF5 currently looks for threading functionality just based on whether threading functionality was initially found when HDF5 was configured. In your case, threading functionality is (presumably) not needed, and so the eventual find_package(Threads ...) call in that configuration file shouldn’t be needed. But if the HDF5 you were building against had any feature enabled which does require threading functionality, you’d have the same issue. Based on Policy: ban `enable_language()` from within `find_package()` (#26751) · Issues · CMake / CMake · GitLab, it seems it would be best if we just check for the C language being enabled when required and failing the configure step if it’s not.
You can exclude C++, but not C. The C component is the core library which handles all basic HDF5 functionality. It can never be disabled.
The C++ and Fortran API’s are wrappers around the core C library. C++ is disabled with the CMake option HDF5_BUILD_CPP_LIB=OFF. Actually, it should already be off by default. Please see “CMake Option Defaults for HDF5” in the HDF5 CMake install documentation. Current location:
Well, it’s true that the HDF5 library is written in C and that in order to build it C is essential.
But I think it’s burdensome to require C for a pure-FORTRAN project which uses HDF5 library even after the library with FORTRAN wrapper was built. (I agree that in that case there should be a C compiler and I CAN add C to the project(), but…)
I can use HDF5-1.14.6 with just project(... LANGUAGES Fortran).
I am not sure what you mean here by “require C”. If you want to assemble a package with minimal parts, then I THINK you can pre-build the C and fortran libraries, then discard the C compiler and all the HDF5 source code. You are left with HDF5 C and fortran runtime libraries and installed headers, and also certain other lower level support libraries such as zlib; C and fortran system runtimes; and maybe filter plugins. At the API level, the HDF5 C library should be invisible to any application programs that are using only the pure fortran interface.
I never thought of the HDF5-C library lurking in the background, as “burdensome”.
What I mean is that once the HDF5-C library with FORTRAN wrapper was built, we don’t need TO REQUIRE C toolkit (compilers etc.) by doing project(something LANGUAGES C Fortran) to build a pure-FORTRAN project depending on the library.
Since my goal is to provide a portable CMakeLists.txt for a FORTRAN project which partly depends on the HDF5 library, and I don’t want our user to ask to tweak the library itself (would rather let them use pristine precompiled/ready-made binary), I’d be happy if the default value of HDF5_THREADS_ENABLED be changed in the future releases.
Although the project you mentioned is very interesting to me, as I wrote in another reply as the following, I would rather (let our users) use the ready-made library (either as provided by the HDF group (thanks! ありがとうございます) or packaged by e.g. linux distributions): at present, there seems to be a bug in allocatable character arrays in gfortran ver.15, and I have to compile HDF5 library with other FORTRAN compilers (gfortran-14 or ifx) by myself…