Fix threads and variables in Cmake. (#5523)

* Rework threading options

* Use link variables for Threads and MPI
This commit is contained in:
Allen Byrne
2025-06-03 11:04:39 -05:00
committed by GitHub
parent ab3bb3de39
commit 029bca0540
7 changed files with 23 additions and 16 deletions
+7 -2
View File
@@ -791,14 +791,13 @@ endif ()
# Parallel IO usage requires MPI to be Linked and Included
if (H5_HAVE_PARALLEL)
set (LINK_LIBS ${LINK_LIBS} ${MPI_C_LIBRARIES})
list (APPEND LINK_PUB_LIBS MPI::MPI_C)
if (MPI_C_LINK_FLAGS)
set (CMAKE_EXE_LINKER_FLAGS "${MPI_C_LINK_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
endif ()
endif ()
# Determine if a threading package is available on this system
option (HDF5_ENABLE_THREADS "Enable thread support" ON)
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads)
if (Threads_FOUND)
@@ -821,12 +820,16 @@ if (Threads_FOUND)
else ()
message (FATAL_ERROR " **** thread support requires C11 threads, Win32 threads or Pthreads **** ")
endif ()
set (HDF5_THREADS_ENABLED ON) # Used to init hdf5-config.cmake
list (APPEND LINK_LIBS Threads::Threads)
# Check for compiler support for atomic variables
CHECK_INCLUDE_FILE("stdatomic.h" HAVE_STDATOMIC_H)
if (HAVE_STDATOMIC_H)
set (H5_HAVE_STDATOMIC_H 1)
endif()
else ()
set (HDF5_THREADS_ENABLED OFF) # Used to init hdf5-config.cmake
endif ()
# Determine whether to build the HDF5 Subfiling VFD
@@ -863,6 +866,8 @@ if (HDF5_ENABLE_SUBFILING_VFD)
endif()
endif()
message (VERBOSE "LINK_LIBS=${LINK_LIBS}")
message (VERBOSE "LINK_PUB_LIBS=${LINK_PUB_LIBS}")
set (HDF5_DEFAULT_API_VERSION "v200" CACHE STRING "Enable v2.0 API (v16, v18, v110, v112, v114, v200)")
set_property (CACHE HDF5_DEFAULT_API_VERSION PROPERTY STRINGS v16 v18 v110 v112 v114 v200)
+1
View File
@@ -23,6 +23,7 @@ if (NOT DEFINED H5PL_ALLOW_EXTERNAL_SUPPORT)
endif ()
if (H5PL_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT")
set (ENABLE_BITGROOM OFF CACHE BOOL "" FORCE)
set (ENABLE_JPEG OFF CACHE BOOL "" FORCE)
set (ENABLE_LZF OFF CACHE BOOL "" FORCE)
endif ()
+2 -2
View File
@@ -46,7 +46,7 @@ set (${HDF5_PACKAGE_NAME}_INSTALL_MOD_FORTRAN "@HDF5_INSTALL_MOD_FORTRAN@")
set (${HDF5_PACKAGE_NAME}_BUILD_HL_LIB @HDF5_BUILD_HL_LIB@)
set (${HDF5_PACKAGE_NAME}_BUILD_SHARED_LIBS @H5_ENABLE_SHARED_LIB@)
set (${HDF5_PACKAGE_NAME}_BUILD_STATIC_LIBS @H5_ENABLE_STATIC_LIB@)
set (${HDF5_PACKAGE_NAME}_ENABLE_THREADS @HDF5_ENABLE_THREADS@)
set (${HDF5_PACKAGE_NAME}_THREADS_ENABLED @HDF5_THREADS_ENABLED@)
set (${HDF5_PACKAGE_NAME}_ENABLE_THREADSAFE @HDF5_ENABLE_THREADSAFE@)
set (${HDF5_PACKAGE_NAME}_ENABLE_PARALLEL @HDF5_ENABLE_PARALLEL@)
set (${HDF5_PACKAGE_NAME}_DEFAULT_API_VERSION "@HDF5_DEFAULT_API_VERSION@")
@@ -92,7 +92,7 @@ if (${HDF5_PACKAGE_NAME}_ENABLE_PARALLEL)
find_package(MPI QUIET REQUIRED)
endif ()
if (${HDF5_PACKAGE_NAME}_ENABLE_THREADS)
if (${HDF5_PACKAGE_NAME}_THREADS_ENABLED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads QUIET REQUIRED)
endif ()
+2 -2
View File
@@ -28,7 +28,7 @@ release_docs/INSTALL_CMake.txt file for more information on the CMake build syst
| mirror-vfd[Build the socket-based Mirror virtual file driver (VFD). [default=no]] | HDF5_ENABLE_MIRROR_VFD "Build the Mirror Virtual File Driver" [OFF] | if (HDF5_BUILD_UTILS) |
| ros3-vfd[Build the Read-Only S3 virtual file driver (VFD). [default=no]] | HDF5_ENABLE_ROS3_VFD "Build the ROS3 Virtual File Driver" [OFF] | |
| libhdfs[Provide libhdfs library to enable HDFS virtual file driver (VFD) [default=no]] | HDF5_ENABLE_HDFS "Enable HDFS" [OFF] | |
| threads[Enable threads capability. A prerequisite for enabling threadsafe API calls. [default=yes] | HDF5_ENABLE_THREADS "Enable thread support" [ON] | |
| threads[Enable threads capability. A prerequisite for enabling threadsafe API calls. [default=yes] | HDF5_THREADS_ENABLED "Enable thread support" [ON] | |
| threadsafe[Enable thread-safe capability. Not compatible with the high-level library, Fortran, or C++ wrappers. [default=no]] | HDF5_ENABLE_THREADSAFE "Enable Threadsafety" [OFF] | |
| file-locking[Sets the default for whether or not to use file locking when opening files. [default=best-effort]] | HDF5_USE_FILE_LOCKING "Use file locking by default (mainly for SWMR)" [ON] | HDF5_IGNORE_DISABLED_FILE_LOCKS "Ignore file locks when disabled on file system" [ON] |
@@ -78,5 +78,5 @@ release_docs/INSTALL_CMake.txt file for more information on the CMake build syst
| ------- | ------- | ------------ |
| examplesdir[--with-examplesdir=location], [Specify path for examples [default="DATAROOTDIR/hdf5_examples"]] | | |
| libmfu[--with-libmfu=DIR], [Use the libmfu library [default=no]] | | |
| pthread[--with-pthread=DIR][Specify alternative path to Pthreads library] | Handled by HDF5_ENABLE_THREADS | |
| pthread[--with-pthread=DIR][Specify alternative path to Pthreads library] | Handled by HDF5_THREADS_ENABLED | |
+8
View File
@@ -47,6 +47,14 @@ New Features
Configuration:
-------------
- Removed HDF5_ENABLE_THREADS option
The HDF5_ENABLE_THREADS option has been removed, as it no longer functions
as a proper build option. The library will always check for thread support
and set the internal status variable, HDF5_THREADS_ENABLED.
The HDF5_ENABLE_THREADSAFE option is still available to build with
thread-safe API calls.
- Reorganized the files in the config/cmake folder into the config folder structure
The config folder CMake files have been reorganized to make it easier to
+2 -9
View File
@@ -1109,13 +1109,8 @@ if (BUILD_STATIC_LIBS)
TARGET_C_PROPERTIES (${HDF5_LIB_TARGET} STATIC)
target_link_libraries (${HDF5_LIB_TARGET}
PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS}
PUBLIC "$<$<PLATFORM_ID:Windows>:${LINK_PUB_LIBS}>" "$<$<NOT:$<PLATFORM_ID:Windows>>:${CMAKE_DL_LIBS}>" "$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:MPI::MPI_C>"
PUBLIC ${LINK_PUB_LIBS}
)
if (NOT WIN32)
target_link_libraries (${HDF5_LIB_TARGET}
PRIVATE "$<$<OR:$<BOOL:${HDF5_ENABLE_THREADS}>,$<BOOL:${HDF5_ENABLE_SUBFILING_VFD}>>:Threads::Threads>"
)
endif ()
set_global_variable (HDF5_LIBRARIES_TO_EXPORT ${HDF5_LIB_TARGET})
H5_SET_LIB_OPTIONS (${HDF5_LIB_TARGET} ${HDF5_LIB_NAME} STATIC 0)
set_target_properties (${HDF5_LIB_TARGET} PROPERTIES FOLDER libraries)
@@ -1136,8 +1131,6 @@ if (BUILD_SHARED_LIBS)
"H5_BUILT_AS_DYNAMIC_LIB"
${HDF_EXTRA_C_FLAGS}
PRIVATE
"$<$<BOOL:${HDF5_ENABLE_THREADS}>:H5_HAVE_THREADS>"
"$<$<BOOL:${HDF5_ENABLE_THREADSAFE}>:H5_HAVE_THREADSAFE>"
"$<$<BOOL:${HDF5_ENABLE_TRACE}>:H5_DEBUG_API>" # Enable tracing of the API
"$<$<BOOL:${HDF5_ENABLE_DEBUG_APIS}>:${HDF5_DEBUG_APIS}>"
"$<$<CONFIG:Developer>:${HDF5_DEVELOPER_DEFS}>"
@@ -1145,7 +1138,7 @@ if (BUILD_SHARED_LIBS)
TARGET_C_PROPERTIES (${HDF5_LIBSH_TARGET} SHARED)
target_link_libraries (${HDF5_LIBSH_TARGET}
PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS}
PUBLIC "$<$<PLATFORM_ID:Windows>:${LINK_PUB_LIBS}>" "$<$<NOT:$<PLATFORM_ID:Windows>>:${CMAKE_DL_LIBS}>" "$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:MPI::MPI_C>" "$<$<OR:$<BOOL:${HDF5_ENABLE_THREADS}>,$<BOOL:${HDF5_ENABLE_SUBFILING_VFD}>>:Threads::Threads>"
PUBLIC ${LINK_PUB_LIBS}
)
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_LIBSH_TARGET} ${HDF5_LIB_NAME} SHARED "LIB")
+1 -1
View File
@@ -73,7 +73,7 @@ Features:
Dimension scales w/ new references: @DIMENSION_SCALES_WITH_NEW_REF@
Build HDF5 Tests: @BUILD_TESTING@
Build HDF5 Tools: @HDF5_BUILD_TOOLS@
Threads: @HDF5_ENABLE_THREADS@
Threads: @HDF5_THREADS_ENABLED@
Threadsafety: @HDF5_ENABLE_THREADSAFE@
Concurrency: @HDF5_ENABLE_CONCURRENCY@
Default API mapping: @HDF5_DEFAULT_API_VERSION@