Skip to content

Commit

Permalink
Add THREADS check to configuration file (HDFGroup#4746)
Browse files Browse the repository at this point in the history
* Cleanup threads package checks

* Check first if package was found

* Remove unnecessary dependent checks

* Remove Unused options and fix names of option prefix
  • Loading branch information
byrnHDF authored Sep 8, 2024
1 parent 66cfc80 commit 5e94301
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 163 deletions.
2 changes: 1 addition & 1 deletion HDF5Examples/C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_subdirectory (${PROJECT_SOURCE_DIR}/H5T)

if (${H5_LIBVER_DIR} GREATER 16)
# add_subdirectory (${PROJECT_SOURCE_DIR}/Perf)
if (USE_SHARED_LIBS AND HDF_BUILD_FILTERS AND HDF5_ENABLE_PLUGIN_SUPPORT)
if (USE_SHARED_LIBS AND H5EX_BUILD_FILTERS AND HDF5_ENABLE_PLUGIN_SUPPORT)
add_subdirectory (${PROJECT_SOURCE_DIR}/H5FLT)
endif ()
endif ()
Expand Down
99 changes: 25 additions & 74 deletions HDF5Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ message (STATUS "HDF5 H5_LIBVER_DIR: ${H5_LIBVER_DIR} HDF5_VERSION_MAJOR: ${HDF5
#-----------------------------------------------------------------------------
# Option to build JAVA examples
#-----------------------------------------------------------------------------
option (HDF_BUILD_JAVA "Build JAVA support" OFF)
if (HDF_BUILD_JAVA)
option (H5EX_BUILD_JAVA "Build JAVA support" OFF)
if (H5EX_BUILD_JAVA)
find_package (Java)

include (${H5EX_RESOURCES_DIR}/UseJava.cmake)
Expand Down Expand Up @@ -73,8 +73,8 @@ endif ()
# Option to Enable MPI Parallel
#-----------------------------------------------------------------------------
set (CMAKE_MODULE_PATH ${H5EX_RESOURCES_DIR} ${CMAKE_MODULE_PATH})
option (HDF_ENABLE_PARALLEL "Enable parallel build (requires MPI)" OFF)
if (HDF_ENABLE_PARALLEL)
option (H5EX_ENABLE_PARALLEL "Enable parallel build (requires MPI)" OFF)
if (H5EX_ENABLE_PARALLEL)
find_package(MPI REQUIRED)
if (MPI_C_FOUND)
set (H5_HAVE_PARALLEL 1)
Expand All @@ -99,55 +99,6 @@ if (H5_HAVE_PARALLEL)
INCLUDE_DIRECTORIES (${MPI_C_INCLUDE_DIRS})
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)
set (H5_HAVE_THREADS 1)
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})

# Determine which threading package to use
# Comment out check for C11 threads for now, since it conflicts with the
# current --std=c99 compile flags at configuration time. When we switch to
# --std=c11, this can be uncommented.
#CHECK_INCLUDE_FILE("threads.h" HAVE_THREADS_H)
if (WIN32)
# When Win32 is available, we use those threads
set (H5_HAVE_WIN_THREADS 1)
elseif (HAVE_THREADS_H)
# When C11 threads are available, those are the top choice
set (H5_HAVE_C11_THREADS 1)
elseif (CMAKE_USE_PTHREADS_INIT)
set (H5_HAVE_PTHREAD_H 1)
else ()
message (FATAL_ERROR " **** thread support requires C11 threads, Win32 threads or Pthreads **** ")
endif ()

# 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()
endif ()

#-----------------------------------------------------------------------------
# Option to use threadsafe
#-----------------------------------------------------------------------------
option (HDF_ENABLE_THREADSAFE "Enable Threadsafety" OFF)
# Note that HDF_ENABLE_THREADSAFE is the CMake option for determining
# whether to enable thread-safety in the examples. HDF5_ENABLE_THREADSAFE
# is the CMake option determining whether HDF5 was configured with
# thread-safety enabled.
if (HDF_ENABLE_THREADSAFE AND HDF5_ENABLE_THREADSAFE)
# Check for threading package
if (NOT Threads_FOUND)
message (FATAL_ERROR " **** thread-safety option requires a threading package and none was found **** ")
endif ()

set (H5_HAVE_THREADSAFE 1)
endif ()

set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
"${H5EX_HDF5_INCLUDE_DIRS}"
)
Expand Down Expand Up @@ -176,8 +127,8 @@ if (${H5_LIBVER_DIR} GREATER 16)
set (H5_FC_FUNC "H5_FC_FUNC(name,NAME) name ## _")
set (H5_FC_FUNC_ "H5_FC_FUNC_(name,NAME) name ## _")
if (EXISTS "${H5EXAMPLES_SOURCE_DIR}/FORTRAN" AND IS_DIRECTORY "${H5EXAMPLES_SOURCE_DIR}/FORTRAN")
option (HDF_BUILD_FORTRAN "Build examples FORTRAN support" OFF)
if (HDF_BUILD_FORTRAN AND HDF5_BUILD_FORTRAN)
option (H5EX_BUILD_FORTRAN "Build examples FORTRAN support" OFF)
if (H5EX_BUILD_FORTRAN AND HDF5_BUILD_FORTRAN)
set (H5EX_LINK_Fortran_LIBS ${H5EX_HDF5_LINK_LIBS})

# Parallel IO usage requires MPI to be Linked and Included
Expand All @@ -191,40 +142,40 @@ if (${H5_LIBVER_DIR} GREATER 16)
configure_file (${H5EX_F90_SRC_DIR}/H5D/h5_version.h.in ${PROJECT_BINARY_DIR}/FORTRAN/H5D/h5_version.h @ONLY)
configure_file (${H5EX_F90_SRC_DIR}/H5D/h5_version.h.in ${PROJECT_BINARY_DIR}/FORTRAN/H5G/h5_version.h @ONLY)
else ()
set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build examples FORTRAN support" FORCE)
set (H5EX_BUILD_FORTRAN OFF CACHE BOOL "Build examples FORTRAN support" FORCE)
endif ()
else ()
set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build examples FORTRAN support" FORCE)
set (H5EX_BUILD_FORTRAN OFF CACHE BOOL "Build examples FORTRAN support" FORCE)
endif ()

if (${H5_LIBVER_DIR} GREATER 18)
#-----------------------------------------------------------------------------
# Option to build JAVA examples
#-----------------------------------------------------------------------------
if (EXISTS "${H5EXAMPLES_SOURCE_DIR}/JAVA" AND IS_DIRECTORY "${H5EXAMPLES_SOURCE_DIR}/JAVA")
option (HDF_BUILD_JAVA "Build examples JAVA support" OFF)
option (H5EX_BUILD_JAVA "Build examples JAVA support" OFF)
else ()
set (HDF_BUILD_JAVA OFF CACHE BOOL "Build examples JAVA support" FORCE)
set (H5EX_BUILD_JAVA OFF CACHE BOOL "Build examples JAVA support" FORCE)
endif ()
else ()
set (HDF_BUILD_JAVA OFF CACHE BOOL "Build examples JAVA support" FORCE)
set (H5EX_BUILD_JAVA OFF CACHE BOOL "Build examples JAVA support" FORCE)
endif ()

#-----------------------------------------------------------------------------
# Build the CPP Examples
#-----------------------------------------------------------------------------
if (EXISTS "${H5EXAMPLES_SOURCE_DIR}/CXX" AND IS_DIRECTORY "${H5EXAMPLES_SOURCE_DIR}/CXX")
option (HDF_BUILD_CPP_LIB "Build examples C++ support" OFF)
option (H5EX_BUILD_CPP_LIB "Build examples C++ support" OFF)
else ()
set (HDF_BUILD_CPP_LIB OFF CACHE BOOL "Build examples C++ support" FORCE)
set (H5EX_BUILD_CPP_LIB OFF CACHE BOOL "Build examples C++ support" FORCE)
endif ()

#-----------------------------------------------------------------------------
# Option to build filter examples
#-----------------------------------------------------------------------------
if (EXISTS "${H5EXAMPLES_SOURCE_DIR}/C/H5FLT" AND IS_DIRECTORY "${H5EXAMPLES_SOURCE_DIR}/C/H5FLT")
option (HDF_BUILD_FILTERS "Build examples PLUGIN filter support" OFF)
if (HDF_BUILD_FILTERS AND HDF5_ENABLE_PLUGIN_SUPPORT)
option (H5EX_BUILD_FILTERS "Build examples PLUGIN filter support" OFF)
if (H5EX_BUILD_FILTERS AND HDF5_ENABLE_PLUGIN_SUPPORT)
if(DEFINED ENV{HDF5_PLUGIN_PATH})
message (STATUS "ENV PATH=$ENV{HDF5_PLUGIN_PATH}")
set (H5EX_HDF5_PLUGIN_PATH $ENV{HDF5_PLUGIN_PATH})
Expand All @@ -236,32 +187,32 @@ if (${H5_LIBVER_DIR} GREATER 16)
endif ()
message (STATUS "H5EX_HDF5_PLUGIN_PATH=${H5EX_HDF5_PLUGIN_PATH}")
else ()
set (HDF_BUILD_FILTERS OFF CACHE BOOL "Build examples PLUGIN filter support" FORCE)
set (H5EX_BUILD_FILTERS OFF CACHE BOOL "Build examples PLUGIN filter support" FORCE)
endif ()
else ()
set (HDF_BUILD_FILTERS OFF CACHE BOOL "Build examples PLUGIN filter support" FORCE)
set (H5EX_BUILD_FILTERS OFF CACHE BOOL "Build examples PLUGIN filter support" FORCE)
endif ()
else ()
set (HDF_BUILD_FORTRAN OFF} CACHE BOOL "Build examples FORTRAN support" FORCE)
set (HDF_BUILD_JAVA OFF CACHE BOOL "Build examples JAVA support" FORCE)
set (HDF_BUILD_CPP_LIB OFF CACHE BOOL "Build examples C++ support" FORCE)
set (HDF_BUILD_FILTERS OFF CACHE BOOL "Build examples PLUGIN filter support" FORCE)
set (H5EX_BUILD_FORTRAN OFF} CACHE BOOL "Build examples FORTRAN support" FORCE)
set (H5EX_BUILD_JAVA OFF CACHE BOOL "Build examples JAVA support" FORCE)
set (H5EX_BUILD_CPP_LIB OFF CACHE BOOL "Build examples C++ support" FORCE)
set (H5EX_BUILD_FILTERS OFF CACHE BOOL "Build examples PLUGIN filter support" FORCE)
endif ()

#-----------------------------------------------------------------------------
# Build examples
#-----------------------------------------------------------------------------
add_subdirectory (C)
if (HDF_BUILD_FORTRAN AND HDF5_BUILD_FORTRAN)
if (H5EX_BUILD_FORTRAN AND HDF5_BUILD_FORTRAN)
add_subdirectory (FORTRAN)
endif ()
if (HDF_BUILD_JAVA AND HDF5_BUILD_JAVA)
if (H5EX_BUILD_JAVA AND HDF5_BUILD_JAVA)
add_subdirectory (JAVA)
endif ()
if (HDF_BUILD_CPP_LIB AND HDF5_BUILD_CPP_LIB)
if (H5EX_BUILD_CPP_LIB AND HDF5_BUILD_CPP_LIB)
add_subdirectory (CXX)
endif ()
if (HDF_BUILD_PYTHON)
if (H5EX_BUILD_PYTHON)
add_subdirectory (PYTHON)
endif ()

6 changes: 3 additions & 3 deletions HDF5Examples/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
"name": "ci-StdJava",
"hidden": true,
"cacheVariables": {
"HDF_BUILD_JAVA": "ON"
"H5EX_BUILD_JAVA": "ON"
}
},
{
"name": "ci-StdFortran",
"hidden": true,
"cacheVariables": {
"HDF_BUILD_FORTRAN": "ON"
"H5EX_BUILD_FORTRAN": "ON"
}
},
{
"name": "ci-StdPlugins",
"hidden": true,
"cacheVariables": {
"HDF_BUILD_FILTERS": "ON"
"H5EX_BUILD_FILTERS": "ON"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion HDF5Examples/FORTRAN/H5D/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ project (HDF5Examples_FORTRAN_H5D Fortran)
# Setup include Directories
#-----------------------------------------------------------------------------
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_Fortran_MODULE_DIRECTORY}${HDF_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
"${CMAKE_Fortran_MODULE_DIRECTORY}${H5EX_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
)

#-----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions HDF5Examples/FORTRAN/H5G/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ project (HDF5Examples_FORTRAN_H5G Fortran)
# Setup include Directories
#-----------------------------------------------------------------------------
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_Fortran_MODULE_DIRECTORY}${HDF_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
"${CMAKE_Fortran_MODULE_DIRECTORY}${H5EX_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
)

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -47,7 +47,7 @@ foreach (example_name ${common_examples})
endif ()
endforeach ()

#if (HDF_ENABLE_F2003)
#if (H5EX_ENABLE_F2003)
# foreach (example_name ${f03examples})
# add_executable (${EXAMPLE_VARNAME}_f90_${example_name} ${PROJECT_SOURCE_DIR}/${example_name}.c)
# target_compile_options(${EXAMPLE_VARNAME}_f90_${example_name}
Expand Down Expand Up @@ -149,7 +149,7 @@ if (HDF5_BUILD_TOOLS)
)
endif ()

#if (HDF_ENABLE_F2003)
#if (H5EX_ENABLE_F2003)
# foreach (example_name ${f03examples})
# add_custom_command (
# TARGET ${EXAMPLE_VARNAME}_f90_${example_name}
Expand Down Expand Up @@ -432,7 +432,7 @@ if (H5EX_BUILD_TESTING)
#ADD_H5_CMP_TEST (h5ex_g_traverse)
#endif()
else ()
if (HDF_ENABLE_F2003)
if (H5EX_ENABLE_F2003)
ADD_H5_CMP_TEST (h5ex_g_intermediate)
ADD_H5_CMP_TEST (h5ex_g_iterate)
# ADD_H5_CMP_TEST (h5ex_g_traverse)
Expand Down
2 changes: 1 addition & 1 deletion HDF5Examples/FORTRAN/H5G/Fortran_sourcefiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (HDF5_VERSION_STRING VERSION_GREATER_EQUAL "1.10.0")
)
endif()
else ()
if (HDF_ENABLE_F2003)
if (H5EX_ENABLE_F2003)
set (common_examples
${common_examples}
h5ex_g_intermediate
Expand Down
2 changes: 1 addition & 1 deletion HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ project (HDF5Examples_FORTRAN_H5PAR Fortran)
# Setup include Directories
#-----------------------------------------------------------------------------
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_Fortran_MODULE_DIRECTORY}${HDF_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
"${CMAKE_Fortran_MODULE_DIRECTORY}${H5EX_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
)

#-----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions HDF5Examples/FORTRAN/H5T/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ project (HDF5Examples_FORTRAN_H5T Fortran)
# Setup include Directories
#-----------------------------------------------------------------------------
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_Fortran_MODULE_DIRECTORY}${HDF_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
"${CMAKE_Fortran_MODULE_DIRECTORY}${H5EX_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
)

#-----------------------------------------------------------------------------
# Define Sources
#-----------------------------------------------------------------------------
include (Fortran_sourcefiles.cmake)

#if (HDF_ENABLE_F2003)
#if (H5EX_ENABLE_F2003)
foreach (example_name ${f03_examples})
add_executable (${EXAMPLE_VARNAME}_f90_${example_name} ${PROJECT_SOURCE_DIR}/${example_name}.F90)
target_compile_options(${EXAMPLE_VARNAME}_f90_${example_name}
Expand Down Expand Up @@ -126,7 +126,7 @@ if (HDF5_BUILD_TOOLS)
)
endforeach ()

#if (HDF_ENABLE_F2003)
#if (H5EX_ENABLE_F2003)
foreach (example_name ${f03_examples})
if (NOT ${example_name} STREQUAL "h5ex_t_convert_F03")
if (${example_name} STREQUAL "h5ex_t_vlen_F03" OR ${example_name} STREQUAL "h5ex_t_vlenatt_F03")
Expand Down Expand Up @@ -404,7 +404,7 @@ if (H5EX_BUILD_TESTING)
endif ()
endmacro ()

#if (HDF_ENABLE_F2003)
#if (H5EX_ENABLE_F2003)
foreach (example_name ${f03_examples} ${common_examples})
TEST_EXAMPLE (${example_name})
endforeach ()
Expand Down
6 changes: 3 additions & 3 deletions HDF5Examples/FORTRAN/TUTR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ project (HDF5Examples_FORTRAN_TUTR Fortran)
# Setup include Directories
#-----------------------------------------------------------------------------
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
"${CMAKE_Fortran_MODULE_DIRECTORY}${HDF_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
"${CMAKE_Fortran_MODULE_DIRECTORY}${H5EX_MOD_EXT};${HDF5_F90_BINARY_DIR};${PROJECT_BINARY_DIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
)

#-----------------------------------------------------------------------------
# Define Sources
#-----------------------------------------------------------------------------
include (Fortran_sourcefiles.cmake)

#if (HDF_ENABLE_F2003)
#if (H5EX_ENABLE_F2003)
foreach (example_name ${f03_examples})
add_executable (${EXAMPLE_VARNAME}_f90_tutr_${example_name} ${PROJECT_SOURCE_DIR}/${example_name}.f90)
target_compile_options(${EXAMPLE_VARNAME}_f90_tutr_${example_name}
Expand Down Expand Up @@ -112,7 +112,7 @@ if (H5EX_BUILD_TESTING)
set (last_test "${EXAMPLE_VARNAME}_f90_tutr_${testname}")
endmacro ()

#if (HDF_ENABLE_F2003)
#if (H5EX_ENABLE_F2003)
foreach (example_name ${f03_examples} ${common_examples})
ADD_H5_TEST (${example_name})
endforeach ()
Expand Down
4 changes: 2 additions & 2 deletions HDF5Examples/Using_CMake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ These steps are described in more detail below.
<options> is:
* H5EX_BUILD_TESTING:BOOL=ON
* BUILD_SHARED_LIBS:BOOL=[ON | OFF]
* HDF_BUILD_FORTRAN:BOOL=[ON | OFF]
* HDF_BUILD_JAVA:BOOL=[ON | OFF]
* H5EX_BUILD_FORTRAN:BOOL=[ON | OFF]
* H5EX_BUILD_JAVA:BOOL=[ON | OFF]

if the hdf5 library was built with a namespace (i.e. "hdf5::") add:
-D HDF5_NAMESPACE:STRING=hdf5::
Expand Down
Loading

0 comments on commit 5e94301

Please sign in to comment.