diff options
author | mattjala <124107509+mattjala@users.noreply.github.com> | 2023-09-01 21:01:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-01 21:01:37 (GMT) |
commit | 68c48159e7cb17e0f33ae28acff77291dfcd5b3c (patch) | |
tree | d2bd4e348414ec88b4f8aa2938d806a92114f72a /CMakeVOL.cmake | |
parent | 80fe48f2d370987a4d8e6f9789df735cc6963ef8 (diff) | |
download | hdf5-68c48159e7cb17e0f33ae28acff77291dfcd5b3c.zip hdf5-68c48159e7cb17e0f33ae28acff77291dfcd5b3c.tar.gz hdf5-68c48159e7cb17e0f33ae28acff77291dfcd5b3c.tar.bz2 |
Support CMake VOL builds with FetchContent from local directory (#3455)
* Update VOL CMake for REST VOL
* Prevent linking static libs to VOLs
* index on fetch_local: 5c5c3f1505 Prevent linking static libs to VOLs
* index on (no branch): 9a36d3e7b1 On fetch_local: WIP:add source dir fetch option for vols
* Allow building of VOL from local source
* Move LOCAL_DIR option to HDF5_VOL_ALLOW_EXTERNAL
Diffstat (limited to 'CMakeVOL.cmake')
-rw-r--r-- | CMakeVOL.cmake | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/CMakeVOL.cmake b/CMakeVOL.cmake index 8562106..79afa59 100644 --- a/CMakeVOL.cmake +++ b/CMakeVOL.cmake @@ -27,12 +27,12 @@ function (get_generated_cmake_targets out_var dir) endfunction () # For now, only support building of external VOL connectors with FetchContent -option (HDF5_VOL_ALLOW_EXTERNAL "Allow building of external HDF5 VOL connectors with FetchContent" OFF) +option (HDF5_VOL_ALLOW_EXTERNAL "Allow building of external HDF5 VOL connectors with FetchContent" "NO") mark_as_advanced (HDF5_VOL_ALLOW_EXTERNAL) if (HDF5_VOL_ALLOW_EXTERNAL) - if (HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "NO" OR NOT HDF5_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT") - message (FATAL_ERROR "HDF5_ALLOW_EXTERNAL_SUPPORT must be set to 'GIT' to allow building of external HDF5 VOL connectors") - endif () + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "NO" OR (NOT HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT" AND NOT HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR")) + message (FATAL_ERROR "HDF5_VOL_ALLOW_EXTERNAL must be set to 'GIT' or 'LOCAL_DIR' to allow building of external HDF5 VOL connectors") + endif() # For compatibility, set some variables that projects would # typically look for after calling find_package(HDF5) @@ -51,7 +51,7 @@ if (HDF5_VOL_ALLOW_EXTERNAL) foreach (vol_idx RANGE 1 ${HDF5_MAX_EXTERNAL_VOLS}) # Generate fixed-width index number prepended with 0s - # so URLs come in order from 1 - HDF5_MAX_EXTERNAL_VOLS + # so VOL sources come in order from 1 - HDF5_MAX_EXTERNAL_VOLS set (vol_idx_num_digits 2) # Based on HDF5_MAX_EXTERNAL_VOLS set (vol_idx_fixed "${vol_idx}") string (LENGTH "${vol_idx_fixed}" vol_idx_len) @@ -60,33 +60,53 @@ if (HDF5_VOL_ALLOW_EXTERNAL) math (EXPR vol_idx_len "${vol_idx_len}+1") endwhile () - set (HDF5_VOL_URL${vol_idx_fixed} "" CACHE STRING "Git repository URL of an external HDF5 VOL connector to build") - mark_as_advanced (HDF5_VOL_URL${vol_idx_fixed}) + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") + set (HDF5_VOL_URL${vol_idx_fixed} "" CACHE STRING "Git repository URL of an external HDF5 VOL connector to build") + mark_as_advanced (HDF5_VOL_URL${vol_idx_fixed}) + set (HDF5_VOL_SOURCE "${HDF5_VOL_URL${vol_idx_fixed}}") + elseif(HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") + set (HDF5_VOL_PATH${vol_idx_fixed} "" CACHE STRING "Path to the source directory of an external HDF5 VOL connector to build") + mark_as_advanced (HDF5_VOL_PATH${vol_idx_fixed}) + set (HDF5_VOL_SOURCE "${HDF5_VOL_PATH${vol_idx_fixed}}") + endif() + + if (NOT "${HDF5_VOL_SOURCE}" STREQUAL "") + # Deal with trailing slash in path for LOCAL_DIR case + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") + # Erase trailing slash + string (REGEX REPLACE "/$" "" HDF5_VOL_SOURCE ${HDF5_VOL_SOURCE}) + endif() - if (NOT "${HDF5_VOL_URL${vol_idx_fixed}}" STREQUAL "") # Extract the name of the VOL connector - string (FIND "${HDF5_VOL_URL${vol_idx_fixed}}" "/" hdf5_vol_name_pos REVERSE) + string (FIND "${HDF5_VOL_SOURCE}" "/" hdf5_vol_name_pos REVERSE) if (hdf5_vol_name_pos EQUAL -1) - message (SEND_ERROR "Invalid URL '${HDF5_VOL_URL${vol_idx_fixed}}' specified for HDF5_VOL_URL${vol_idx_fixed}") + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") + message (SEND_ERROR "Invalid URL '${HDF5_VOL_SOURCE}' specified for HDF5_VOL_URL${vol_idx_fixed}") + elseif (HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") + message (SEND_ERROR "Invalid source path '${HDF5_VOL_SOURCE}' specified for HDF5_VOL_PATH${vol_idx_fixed}") + endif() endif () math (EXPR hdf5_vol_name_pos "${hdf5_vol_name_pos}+1") - string (SUBSTRING "${HDF5_VOL_URL${vol_idx_fixed}}" ${hdf5_vol_name_pos} -1 hdf5_vol_name) + string (SUBSTRING "${HDF5_VOL_SOURCE}" ${hdf5_vol_name_pos} -1 hdf5_vol_name) string (REPLACE ".git" "" hdf5_vol_name "${hdf5_vol_name}") string (STRIP "${hdf5_vol_name}" hdf5_vol_name) string (TOUPPER "${hdf5_vol_name}" hdf5_vol_name_upper) string (TOLOWER "${hdf5_vol_name}" hdf5_vol_name_lower) - message (VERBOSE "Building VOL connector '${hdf5_vol_name}' with FetchContent") + message (VERBOSE "Building VOL connector '${hdf5_vol_name}' with FetchContent from source ${HDF5_VOL_SOURCE}") # Set some cache variables that can be set by users when building + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") + set ("HDF5_VOL_${hdf5_vol_name_upper}_BRANCH" "main" CACHE STRING "Git branch (or tag) to use when building VOL connector '${hdf5_vol_name}'") + mark_as_advanced ("HDF5_VOL_${hdf5_vol_name_upper}_BRANCH") + endif() + set ("HDF5_VOL_${hdf5_vol_name_upper}_NAME" "" CACHE STRING "Name of VOL connector to set for the HDF5_VOL_CONNECTOR environment variable") - set ("HDF5_VOL_${hdf5_vol_name_upper}_BRANCH" "main" CACHE STRING "Git branch (or tag) to use when building VOL connector '${hdf5_vol_name}'") option ("HDF5_VOL_${hdf5_vol_name_upper}_TEST_PARALLEL" "Whether to test VOL connector '${hdf5_vol_name}' against the parallel API tests" OFF) mark_as_advanced ("HDF5_VOL_${hdf5_vol_name_upper}_NAME") - mark_as_advanced ("HDF5_VOL_${hdf5_vol_name_upper}_BRANCH") mark_as_advanced ("HDF5_VOL_${hdf5_vol_name_upper}_TEST_PARALLEL") if (HDF5_TEST_API) @@ -95,21 +115,36 @@ if (HDF5_VOL_ALLOW_EXTERNAL) endif () endif () - if ("${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}" STREQUAL "") + if ((HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") AND ("${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}" STREQUAL "")) message (SEND_ERROR "HDF5_VOL_${hdf5_vol_name_upper}_BRANCH must be set to a valid git branch name (or git tag) to build VOL connector '${hdf5_vol_name}'") endif () - FetchContent_Declare (HDF5_VOL_${hdf5_vol_name_lower} - GIT_REPOSITORY "${HDF5_VOL_URL${vol_idx_fixed}}" + if ((HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") + AND NOT (EXISTS ${HDF5_VOL_SOURCE} AND IS_DIRECTORY ${HDF5_VOL_SOURCE})) + message (FATAL_ERROR "HDF5_VOL_PATH${vol_idx_fixed} must be an absolute path to a valid directory") + endif () + + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") + FetchContent_Declare (HDF5_VOL_${hdf5_vol_name_lower} + GIT_REPOSITORY "${HDF5_VOL_SOURCE}" GIT_TAG "${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}" - ) + ) + elseif(HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") + FetchContent_Declare (HDF5_VOL_${hdf5_vol_name_lower} + SOURCE_DIR "${HDF5_VOL_SOURCE}" + ) + endif() FetchContent_GetProperties(HDF5_VOL_${hdf5_vol_name_lower}) if (NOT hdf5_vol_${hdf5_vol_name_lower}_POPULATED) FetchContent_Populate(HDF5_VOL_${hdf5_vol_name_lower}) if (NOT EXISTS "${hdf5_vol_${hdf5_vol_name_lower}_SOURCE_DIR}/CMakeLists.txt") - message (SEND_ERROR "The git repository branch '${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}' for VOL connector '${hdf5_vol_name}' does not appear to contain a CMakeLists.txt file") + if (HDF5_VOL_ALLOW_EXTERNAL MATCHES "GIT") + message (SEND_ERROR "The git repository branch '${HDF5_VOL_${hdf5_vol_name_upper}_BRANCH}' for VOL connector '${hdf5_vol_name}' does not appear to contain a CMakeLists.txt file") + elseif (HDF5_VOL_ALLOW_EXTERNAL MATCHES "LOCAL_DIR") + message(SEND_ERROR "The local directory '${HDF5_VOL_SOURCE}' for VOL connector '${hdf5_vol_name}' does not appear to contain a CMakeLists.txt file") + endif() endif () # If there are any calls to find_package(HDF5) in the connector's |