Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMake to build under library #56

Merged
merged 9 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
485 changes: 369 additions & 116 deletions .github/workflows/main.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid any of the steps in this workflow file using valgrind to run tests since for the most part that will just make them take significantly longer. We can setup another workflow in the future that uses sanitizers to check for this stuff without affecting the runtime much.

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "src/hdf5"]
path = src/hdf5
url = https://github.com/HDFGroup/hdf5.git
[submodule "test/vol-tests"]
path = test/vol-tests
url = https://github.com/HDFGroup/vol-tests.git
url = https://github.com/HDFGroup/vol-tests
110 changes: 42 additions & 68 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ mark_as_advanced (HDF5_VOL_REST_NO_PACKAGES)
set (HDF5_VOL_REST_LIB_CORENAME "hdf5_vol_rest")
set (HDF5_VOL_REST_TEST_LIB_CORENAME "hdf5_vol_rest_test")


#-----------------------------------------------------------------------------
# Set the target names of all the libraries
#-----------------------------------------------------------------------------
Expand All @@ -100,34 +99,29 @@ set (HDF5_VOL_REST_UTIL_DIR ${HDF5_VOL_REST_SOURCE_DIR}/src/util)
set (HDF5_VOL_REST_TEST_SRC_DIR ${HDF5_VOL_REST_SOURCE_DIR}/test)
set (HDF5_VOL_REST_EXAMPLES_DIR ${HDF5_VOL_REST_SOURCE_DIR}/examples)
set (HDF5_DIR_NAME "hdf5")
set (HDF5_DIR ${HDF5_VOL_REST_SRC_DIR}/${HDF5_DIR_NAME})
set (HDF5_BINARY_DIR ${HDF5_VOL_REST_BINARY_DIR}/${HDF5_DIR_NAME})


#-----------------------------------------------------------------------------
# Define a CMake variable which the user can override to use
# a pre-built HDF5 distribution for building the REST VOL connector
#-----------------------------------------------------------------------------
set (PREBUILT_HDF5_DIR CACHE STRING "Directory of pre-built HDF5 distribution")
set (HDF5_HL_DIR_NAME "hl")

#-----------------------------------------------------------------------------
# Find HDF5, cURL and YAJL before building
#-----------------------------------------------------------------------------
set (HDF5_FOUND FALSE)
if (NOT PREBUILT_HDF5_DIR)
find_package(HDF5 MODULE COMPONENTS C HL)
if (HDF5_ENABLE_THREADSAFE AND NOT Threads_FOUND)
find_package(Threads)
endif ()
if (NOT HDF5_FOUND)
set (HDF5_DIR ${HDF5_VOL_REST_SRC_DIR}/${HDF5_DIR_NAME})
endif ()
if (HDF5_FOUND STREQUAL "")
set (HDF5_FOUND FALSE)
endif()

find_package(HDF5 MODULE COMPONENTS C HL)

if (NOT HDF5_FOUND)
message(SEND_ERROR "HDF5 not found!")
endif()

if (HDF5_ENABLE_THREADSAFE AND NOT Threads_FOUND)
find_package(Threads)
endif ()

find_package (CURL REQUIRED)
if (CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
set (LINK_LIBS ${LINK_LIBS} ${CURL_LIBRARIES})
set (LINK_LIBS ${LINK_LIBS} CURL::libcurl)
else ()
message (FATAL_ERROR "cURL not found; please check CURL_INCLUDE_DIR")
endif ()
Expand Down Expand Up @@ -288,7 +282,7 @@ macro (HDF5_VOL_REST_SET_LIB_OPTIONS libtarget libname libtype)
endmacro (HDF5_VOL_REST_SET_LIB_OPTIONS)

#-------------------------------------------------------------------------------
macro (TARGET_C_PROPERTIES wintarget libtype addcompileflags addlinkflags)
macro (RV_TARGET_C_PROPERTIES wintarget libtype addcompileflags addlinkflags)
if (MSVC)
TARGET_MSVC_PROPERTIES (${wintarget} ${libtype} "${addcompileflags} ${WIN_COMPILE_FLAGS}" "${addlinkflags} ${WIN_LINK_FLAGS}")
else ()
Expand Down Expand Up @@ -459,38 +453,23 @@ configure_file (${HDF5_VOL_REST_RESOURCES_DIR}/rv_cmake_config.h.in ${HDF5_VOL_R
#-----------------------------------------------------------------------------
# Include the main src directory and HDF5 distribution directory
#-----------------------------------------------------------------------------
if (PREBUILT_HDF5_DIR)
set (HDF5_VOL_REST_INCLUDE_DIRECTORIES
${HDF5_VOL_REST_SRC_DIR}
${HDF5_VOL_REST_BINARY_DIR}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
${PREBUILT_HDF5_DIR}/include
CACHE
INTERNAL
"Include directories for HDF5 REST VOL connector"
)
elseif (HDF5_FOUND)
set (HDF5_VOL_REST_INCLUDE_DIRECTORIES
${HDF5_VOL_REST_SRC_DIR}
${HDF5_VOL_REST_BINARY_DIR}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
${HDF5_INCLUDE_DIRS}
CACHE
INTERNAL
"Include directories for HDF5 REST VOL connector"
)
else ()
set (HDF5_VOL_REST_INCLUDE_DIRECTORIES

set (HDF5_VOL_REST_INCLUDE_DIRECTORIES
${HDF5_VOL_REST_SRC_DIR}
${HDF5_VOL_REST_BINARY_DIR}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
${HDF5_DIR}
${HDF5_BINARY_DIR}
CACHE
INTERNAL
)

list(APPEND HDF5_VOL_REST_INCLUDE_DIRECTORIES
${HDF5_INCLUDE_DIRS}
)

set(HDF5_VOL_REST_INCLUDE_DIRECTORIES
${HDF5_VOL_REST_INCLUDE_DIRECTORIES}
CACHE
INTERNAL
"Include directories for HDF5 REST VOL connector"
)
endif ()
)

INCLUDE_DIRECTORIES (${HDF5_VOL_REST_INCLUDE_DIRECTORIES})

Expand Down Expand Up @@ -587,27 +566,22 @@ include (${HDF5_VOL_REST_RESOURCES_DIR}/HDFCompilerFlags.cmake)
#endif ()

#-----------------------------------------------------------------------------
# Build HDF5, unless the user has specified to use
# a pre-built HDF5 distribution
# Include HDF5 Directories
#-----------------------------------------------------------------------------
if (NOT PREBUILT_HDF5_DIR AND NOT HDF5_FOUND)
include_directories(${HDF5_VOL_REST_SRC_DIR}/${HDF5_DIR_NAME}/src)
include_directories(${HDF5_VOL_REST_SRC_DIR}/${HDF5_DIR_NAME}/src/H5FDsubfiling)
add_subdirectory(${HDF5_DIR} ${PROJECT_BINARY_DIR}/${HDF5_DIR_NAME})
elseif (NOT PREBUILT_HDF5_DIR AND HDF5_FOUND)
set (HDF5_LIBRARIES_TO_EXPORT
${HDF5_C_HL_LIBRARIES}
include_directories(${HDF5_INCLUDE_DIRS})

if (BUILD_SHARED_LIBS)
list (APPEND LINK_SHARED_LIBS
${HDF5_C_LIBRARIES}
)
else ()
link_directories(${PREBUILT_HDF5_DIR}/lib)
set (HDF5_LIBRARIES_TO_EXPORT
libhdf5.so
libhdf5_hl.so
libhdf5.a
libhdf5_hl.a
)
endif ()
${HDF5_C_HL_LIBRARIES})
endif()

if (BUILD_STATIC_LIBS)
list (APPEND LINK_LIBS
${HDF5_C_LIBRARIES}
${HDF5_C_HL_LIBRARIES})
endif()


#-----------------------------------------------------------------------------
# Build the REST VOL
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ HDF5 REST VOL connector - currently under development
- [CMake](#cmake)
- [II.B.iii.a. Options for `configure`](#iibiiia-options-for-configure)
- [II.B.iii.b. Options for CMake](#iibiiib-options-for-cmake)
- [II.B.iv. Build Results](#iibiv-build-results)
- [II.B.iv. Building at HDF5 Build Time](#iibiv-building-at-hdf5-build-time)
- [II.B.v. Build Results](#iibv-build-results)
- [III. Using/Testing the REST VOL connector](#iii-usingtesting-the-rest-vol-connector)
- [IV. More Information](#iv-more-information)

Expand Down Expand Up @@ -314,8 +315,11 @@ REST VOL Connector-specific options:
Note, when setting BUILD_SHARED_LIBS=ON and YAJL_USE_STATIC_LIBRARIES=ON, the static YAJL libraries have be build with the position independent code (PIC) option enabled. In the static YAJL build,
this PIC option has been turned off by default.

### II.B.iv. Building at HDF5 Build Time

### II.B.iv. Build Results
It is also possible to build the REST VOL as part of the build process for the HDF5 library, using CMake's FetchContent module. This can be done using a local copy of the REST VOL's source code, or by providing the information for the repository to be automatically cloned from a branch of a Github repository. For full instructions on this process, see [Building and testing HDF5 VOL connectors with CMake FetchContent](https://github.com/HDFGroup/hdf5/blob/develop/doc/cmake-vols-fetchcontent.md).

### II.B.v. Build Results

If the build is successful, the following files will be written into the installation directory:

Expand Down
32 changes: 10 additions & 22 deletions build_vol_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ INSTALL_DIR="${SCRIPT_DIR}/rest_vol_build"
# Set the default build directory
BUILD_DIR="${SCRIPT_DIR}/rest_vol_cmake_build_files"

# Default name of the directory for the included HDF5 source distribution,
# as well as the default directory where it gets installed
HDF5_DIR="src/hdf5"

# By default, tell CMake to generate Unix Makefiles
CMAKE_GENERATOR="Unix Makefiles"

Expand All @@ -40,8 +36,7 @@ CONNECTOR_DEBUG_OPT=
CURL_DEBUG_OPT=
MEM_TRACK_OPT=
THREAD_SAFE_OPT=
PREBUILT_HDF5_OPT=
PREBUILT_HDF5_DIR=
HDF5_INSTALL_DIR=
CURL_OPT=
YAJL_OPT=
YAJL_LIB_OPT=
Expand Down Expand Up @@ -78,7 +73,7 @@ usage()
echo " is 'source directory/rest_vol_build'."
echo
echo " -H DIR To specify a directory where HDF5 has already"
echo " been built."
echo " been installed."
echo
echo " -B DIR Specifies the directory that CMake should use as"
echo " the build tree location. Default is"
Expand All @@ -96,7 +91,7 @@ usage()
echo
}

optspec=":hctdmstG:H:C:Y:B:P:-"
optspec=":hctdmstlG:H:C:Y:B:P:-"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
Expand Down Expand Up @@ -143,8 +138,7 @@ while getopts "$optspec" optchar; do
echo
;;
H)
PREBUILT_HDF5_OPT="-DPREBUILT_HDF5_DIR=$OPTARG"
PREBUILT_HDF5_DIR="$OPTARG"
HDF5_INSTALL_DIR="$OPTARG"
echo "Set HDF5 install directory to: $OPTARG"
echo
;;
Expand Down Expand Up @@ -181,13 +175,13 @@ if [ "$NPROCS" -eq "0" ]; then
fi
fi

# Ensure that the HDF5 submodule gets checked out
if [ -z "$(ls -A ${SCRIPT_DIR}/${HDF5_DIR})" ]; then
# Ensure that the vol-tests submodule gets checked out
if [ -z "$(ls -A ${SCRIPT_DIR}/test/vol-tests)" ]; then
git submodule init
git submodule update
fi

# Once HDF5 has been built, build the REST VOL connector against HDF5.
# Build the REST VOL connector against HDF5.
echo "*******************************************"
echo "* Building REST VOL connector and test suite *"
echo "*******************************************"
Expand All @@ -201,7 +195,7 @@ rm -f "${BUILD_DIR}/CMakeCache.txt"

cd "${BUILD_DIR}"

CFLAGS="-D_POSIX_C_SOURCE=200809L" cmake -G "${CMAKE_GENERATOR}" -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" "${PREBUILT_HDF5_OPT}" "${CURL_OPT}" "${YAJL_OPT}" "${YAJL_LIB_OPT}" "${CONNECTOR_DEBUG_OPT}" "${CURL_DEBUG_OPT}" "${MEM_TRACK_OPT}" "${THREAD_SAFE_OPT}" "${SCRIPT_DIR}"
CFLAGS="-D_POSIX_C_SOURCE=200809L" cmake -G "${CMAKE_GENERATOR}" "-DHDF5_ROOT=${HDF5_INSTALL_DIR}" -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" "${CURL_OPT}" "${YAJL_OPT}" "${YAJL_LIB_OPT}" "${CONNECTOR_DEBUG_OPT}" "${CURL_DEBUG_OPT}" "${MEM_TRACK_OPT}" "${THREAD_SAFE_OPT}" "${SCRIPT_DIR}"

echo "Build files have been generated for CMake generator '${CMAKE_GENERATOR}'"

Expand All @@ -210,7 +204,7 @@ if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" ]; then
make -j${NPROCS} && make install || exit 1
fi

echo "REST VOL (and HDF5) built"
echo "REST VOL built"

# Clean out the old CMake cache
rm -f "${BUILD_DIR}/CMakeCache.txt"
Expand All @@ -220,13 +214,7 @@ rm -f "${BUILD_DIR}/CMakeCache.txt"
mkdir -p "${BUILD_DIR}/tests/vol-tests"
cd "${BUILD_DIR}/tests/vol-tests"

if [ -z "$PREBUILT_HDF5_DIR" ]; then
HDF5_INSTALL_DIR=$HDF5_DIR
else
HDF5_INSTALL_DIR=$PREBUILT_HDF5_DIR
fi

CFLAGS="-D_POSIX_C_SOURCE=200809L" cmake -G "${CMAKE_GENERATOR}" -DHDF5_DIR=${HDF5_INSTALL_DIR} -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" "${CONNECTOR_DEBUG_OPT}" "${CURL_DEBUG_OPT}" "${MEM_TRACK_OPT}" "${THREAD_SAFE_OPT}" "${SCRIPT_DIR}/test/vol-tests"
CFLAGS="-D_POSIX_C_SOURCE=200809L" cmake -G "${CMAKE_GENERATOR}" "-DHDF5_DIR=${HDF5_INSTALL_DIR}" -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" "${CONNECTOR_DEBUG_OPT}" "${CURL_DEBUG_OPT}" "${MEM_TRACK_OPT}" "${THREAD_SAFE_OPT}" "${SCRIPT_DIR}/test/vol-tests"

echo "Build files generated for vol-tests"

Expand Down
8 changes: 4 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ set (examples
foreach (example ${examples})
if (BUILD_STATIC_LIBS)
add_executable (${example} ${HDF5_VOL_REST_EXAMPLES_SOURCE_DIR}/${example}.c)
TARGET_C_PROPERTIES (${example} STATIC " " " ")
target_link_libraries (${example} PUBLIC ${HDF5_VOL_REST_LIB_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
RV_TARGET_C_PROPERTIES (${example} STATIC " " " ")
target_link_libraries (${example} PUBLIC ${HDF5_VOL_REST_LIB_TARGET} ${LINK_LIBS})
set_target_properties (${example} PROPERTIES FOLDER examples)
endif ()

if (BUILD_SHARED_LIBS)
add_executable (${example}-shared ${HDF5_VOL_REST_EXAMPLES_SOURCE_DIR}/${example}.c)
TARGET_C_PROPERTIES (${example}-shared SHARED " " " ")
target_link_libraries (${example}-shared PUBLIC ${HDF5_VOL_REST_LIBSH_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
RV_TARGET_C_PROPERTIES (${example}-shared SHARED " " " ")
target_link_libraries (${example}-shared PUBLIC ${HDF5_VOL_REST_LIBSH_TARGET} ${LINK_SHARED_LIBS})
set_target_properties (${example}-shared PROPERTIES FOLDER examples)
endif ()

Expand Down
17 changes: 7 additions & 10 deletions examples/hl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@ set (examples
rv_ds1
)


foreach (example ${examples})
if (BUILD_STATIC_LIBS)
add_executable (${example} ${HDF5_VOL_REST_HL_EXAMPLES_SOURCE_DIR}/${example}.c)
TARGET_C_PROPERTIES (${example} STATIC " " " ")
target_link_libraries (${example} PUBLIC ${HDF5_VOL_REST_LIB_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
RV_TARGET_C_PROPERTIES (${example} STATIC " " " ")
target_link_libraries (${example} PUBLIC ${HDF5_VOL_REST_LIB_TARGET} ${LINK_LIBS})
set_target_properties (${example} PROPERTIES FOLDER examples)
if (NOT PREBUILT_HDF5_DIR)
add_dependencies(${example} ${HDF5_VOL_REST_LIB_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
endif ()
add_dependencies(${example} ${HDF5_VOL_REST_LIB_TARGET})
endif ()

if (BUILD_SHARED_LIBS)
add_executable (${example}-shared ${HDF5_VOL_REST_HL_EXAMPLES_SOURCE_DIR}/${example}.c)
TARGET_C_PROPERTIES (${example}-shared SHARED " " " ")
target_link_libraries (${example}-shared PUBLIC ${HDF5_VOL_REST_LIBSH_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
RV_TARGET_C_PROPERTIES (${example}-shared SHARED " " " ")
target_link_libraries (${example}-shared PUBLIC ${HDF5_VOL_REST_LIBSH_TARGET} ${LINK_SHARED_LIBS})
set_target_properties (${example}-shared PROPERTIES FOLDER examples)
if (NOT PREBUILT_HDF5_DIR)
add_dependencies(${example}-shared ${HDF5_VOL_REST_LIBSH_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
endif ()
add_dependencies(${example}-shared ${HDF5_VOL_REST_LIBSH_TARGET})
endif (BUILD_SHARED_LIBS)

#-----------------------------------------------------------------------------
Expand Down
Loading