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 8 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
102 changes: 35 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,23 @@ 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)
Expand Down Expand Up @@ -288,7 +283,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 +454,25 @@ 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}
${HDF5_BINARY_DIR}/src
${HDF5_SOURCE_DIR}/${HDF5_HL_DIR_NAME}/src
mattjala marked this conversation as resolved.
Show resolved Hide resolved
)

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 +569,13 @@ 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}
${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 ()
include_directories(${HDF5_INCLUDE_DIRS})

list (APPEND HDF5_LIBRARIES_TO_EXPORT
${HDF5_C_HL_LIBRARIES}
mattjala marked this conversation as resolved.
Show resolved Hide resolved
)

#-----------------------------------------------------------------------------
# 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
34 changes: 12 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 @@ -70,6 +65,8 @@ usage()
echo " library should be built with position independent"
echo " code option enabled."
echo
echo " -x Enable building of the REST VOL examples."
mattjala marked this conversation as resolved.
Show resolved Hide resolved
echo
echo " -G Specify the CMake Generator to use for the build"
echo " files created. Default is 'Unix Makefiles'."
echo
Expand All @@ -78,7 +75,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 +93,7 @@ usage()
echo
}

optspec=":hctdmstG:H:C:Y:B:P:-"
optspec=":hctdmstxlG:H:C:Y:B:P:-"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
Expand Down Expand Up @@ -143,8 +140,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 +177,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 +197,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 +206,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 +216,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
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ 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 " " " ")
RV_TARGET_C_PROPERTIES (${example} STATIC " " " ")
target_link_libraries (${example} PUBLIC ${HDF5_VOL_REST_LIB_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
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 " " " ")
RV_TARGET_C_PROPERTIES (${example}-shared SHARED " " " ")
target_link_libraries (${example}-shared PUBLIC ${HDF5_VOL_REST_LIBSH_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
set_target_properties (${example}-shared PROPERTIES FOLDER examples)
endif ()
Expand Down
12 changes: 4 additions & 8 deletions examples/hl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@ set (examples
foreach (example ${examples})
if (BUILD_STATIC_LIBS)
add_executable (${example} ${HDF5_VOL_REST_HL_EXAMPLES_SOURCE_DIR}/${example}.c)
TARGET_C_PROPERTIES (${example} STATIC " " " ")
RV_TARGET_C_PROPERTIES (${example} STATIC " " " ")
target_link_libraries (${example} PUBLIC ${HDF5_VOL_REST_LIB_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
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} ${HDF5_LIBRARIES_TO_EXPORT})
endif ()

if (BUILD_SHARED_LIBS)
add_executable (${example}-shared ${HDF5_VOL_REST_HL_EXAMPLES_SOURCE_DIR}/${example}.c)
TARGET_C_PROPERTIES (${example}-shared SHARED " " " ")
RV_TARGET_C_PROPERTIES (${example}-shared SHARED " " " ")
target_link_libraries (${example}-shared PUBLIC ${HDF5_VOL_REST_LIBSH_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
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} ${HDF5_LIBRARIES_TO_EXPORT})
endif (BUILD_SHARED_LIBS)

#-----------------------------------------------------------------------------
Expand Down
34 changes: 4 additions & 30 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ set (HDF5_VOL_REST_PUBLIC_HEADERS

if (BUILD_STATIC_LIBS)
add_library (${HDF5_VOL_REST_LIB_TARGET} STATIC ${HDF5_VOL_REST_SRCS} ${HDF5_VOL_REST_HDRS})
TARGET_C_PROPERTIES (${HDF5_VOL_REST_LIB_TARGET} STATIC " " " ")
RV_TARGET_C_PROPERTIES (${HDF5_VOL_REST_LIB_TARGET} STATIC " " " ")
target_link_libraries (${HDF5_VOL_REST_LIB_TARGET} PUBLIC ${HDF5_LIBRARIES_TO_EXPORT} ${LINK_LIBS})

if (NOT WIN32)
target_link_libraries (${HDF5_VOL_REST_LIB_TARGET} PRIVATE dl)
endif ()
Expand All @@ -90,8 +91,8 @@ endif ()
if (BUILD_SHARED_LIBS)
file (MAKE_DIRECTORY "${HDF5_VOL_REST_BINARY_DIR}/shared")
add_library (${HDF5_VOL_REST_LIBSH_TARGET} SHARED ${HDF5_VOL_REST_SRCS} ${HDF5_VOL_REST_HDRS})
TARGET_C_PROPERTIES (${HDF5_VOL_REST_LIBSH_TARGET} SHARED " " " ")
target_link_libraries (${HDF5_VOL_REST_LIBSH_TARGET} PUBLIC ${HDF5_LIBRARIES_TO_EXPORT} ${LINK_SHARED_LIBS})
RV_TARGET_C_PROPERTIES (${HDF5_VOL_REST_LIBSH_TARGET} SHARED " " " ")
target_link_libraries (${HDF5_VOL_REST_LIBSH_TARGET} PUBLIC ${HDF5_LIBRARIES_TO_EXPORT} ${LINK_SHARED_LIBS} ${HDF5_LIBRARIES})
mattjala marked this conversation as resolved.
Show resolved Hide resolved
mattjala marked this conversation as resolved.
Show resolved Hide resolved
if (NOT WIN32)
target_link_libraries (${HDF5_VOL_REST_LIBSH_TARGET} PRIVATE dl)
endif ()
Expand All @@ -106,33 +107,6 @@ if (BUILD_SHARED_LIBS)
#add_dependencies(${HDF5_VOL_REST_LIBSH_TARGET} ${HDF5_LIBRARIES_TO_EXPORT})
endif ()

#-----------------------------------------------------------------------------
# Make the REST VOL build depend on H5pubconf.h existing
#-----------------------------------------------------------------------------
if (PREBUILT_HDF5_DIR)
add_custom_target(
rest_vol_pubconf_depend
DEPENDS ${PREBUILT_HDF5_DIR}/include/H5pubconf.h
)
elseif (NOT PREBUILT_HDF5_DIR AND HDF5_FOUND)
add_custom_target(
rest_vol_pubconf_depend
DEPENDS ${HDF5_INCLUDE_DIRS}/H5pubconf.h
)
else ()
add_custom_target(
rest_vol_pubconf_depend
DEPENDS ${CMAKE_BINARY_DIR}/${HDF5_DIR_NAME}/src/H5pubconf.h
)
endif ()

if (BUILD_STATIC_LIBS)
add_dependencies(${HDF5_VOL_REST_LIB_TARGET} rest_vol_pubconf_depend)
endif ()
if (BUILD_SHARED_LIBS)
add_dependencies(${HDF5_VOL_REST_LIBSH_TARGET} rest_vol_pubconf_depend)
endif ()

#-----------------------------------------------------------------------------
# Add file(s) to CMake Install
#-----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/hdf5
Submodule hdf5 deleted from 0553fb
Loading