Skip to content

Commit

Permalink
Guard targets in HighFiveConfig.cmake. (#1053)
Browse files Browse the repository at this point in the history
1uc authored Nov 5, 2024
1 parent b55a865 commit 7ec9a53
Showing 3 changed files with 60 additions and 22 deletions.
16 changes: 10 additions & 6 deletions cmake/HighFiveConfig.cmake
Original file line number Diff line number Diff line change
@@ -8,12 +8,16 @@ if(HIGHFIVE_FIND_HDF5)
find_dependency(HDF5)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/HighFiveTargets.cmake")
if(NOT TARGET HighFive)
include("${CMAKE_CURRENT_LIST_DIR}/HighFiveTargets.cmake")

if(HDF5_IS_PARALLEL)
find_dependency(MPI)
target_link_libraries(HighFive::HighFive INTERFACE MPI::MPI_C MPI::MPI_CXX)
if(HDF5_IS_PARALLEL)
find_dependency(MPI)
target_link_libraries(HighFive::HighFive INTERFACE MPI::MPI_C MPI::MPI_CXX)
endif()

add_library(HighFive ALIAS HighFive::HighFive)
add_library(HighFiveInclude ALIAS HighFive::Include)
endif()

add_library(HighFive ALIAS HighFive::HighFive)
add_library(HighFiveInclude ALIAS HighFive::Include)

43 changes: 27 additions & 16 deletions tests/cmake_integration/test_cmake_integration.sh
Original file line number Diff line number Diff line change
@@ -16,6 +16,15 @@ HIGHFIVE_INSTALL_DIR="${HIGHFIVE_BUILD_DIR}/install"
export HIGHFIVE_GIT_REPOSITORY="file://$(realpath "$HIGHFIVE_DIR")"
export HIGHFIVE_GIT_TAG=$(git rev-parse HEAD)

make_submodule() {
local project_dir="$1"
local dep_dir="${project_dir}/deps/HighFive"

rm "${dep_dir}" || true
mkdir -p "$(dirname "${dep_dir}")"
ln -sf "${HIGHFIVE_DIR}" "${dep_dir}"
}

test_dependent_library() {
local project="dependent_library"
local project_dir="${TEST_DIR}/${project}"
@@ -35,33 +44,35 @@ test_dependent_library() {

cmake --build "${build_dir}" --verbose --target install

local test_project="test_dependent_library"
local test_build_dir="${TMP_DIR}/test_build"
local test_install_dir="${TMP_DIR}/test_build/install"

rm -rf ${test_build_dir} || true
for vendor in submodule fetch_content external none
do
local test_project="test_dependent_library"
local test_build_dir="${TMP_DIR}/test_build"
local test_install_dir="${TMP_DIR}/test_build/install"

make_submodule ${test_project}

cmake -DUSE_BOOST=${use_boost} \
-DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR};${install_dir}" \
-DCMAKE_INSTALL_PREFIX="${test_install_dir}" \
-B "${test_build_dir}" "${test_project}"

cmake --build "${test_build_dir}" --verbose
ctest --test-dir "${test_build_dir}" --verbose
rm -rf ${test_build_dir} || true

cmake -DUSE_BOOST=${use_boost} \
-DVENDOR_STRATEGY=${vendor} \
-DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR};${install_dir}" \
-DCMAKE_INSTALL_PREFIX="${test_install_dir}" \
-B "${test_build_dir}" "${test_project}"

cmake --build "${test_build_dir}" --verbose
ctest --test-dir "${test_build_dir}" --verbose
done
done
}

test_application() {
local project="application"
local project_dir="${TEST_DIR}/${project}"
local dep_dir="${TEST_DIR}/${project}/deps/HighFive"

rm "${dep_dir}" || true
ln -sf "${HIGHFIVE_DIR}" "${dep_dir}"

echo ${HIGHFIVE_DIR}
echo ${dep_dir}
make_submodule ${project_dir}

for vendor in submodule fetch_content external
do
23 changes: 23 additions & 0 deletions tests/cmake_integration/test_dependent_library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -7,8 +7,31 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

set(VENDOR_STRATEGY "submodule" CACHE STRING "Use 'submodule' for Git submodules, 'fetch_content' for FetchContent, 'external' for `find_package`, 'none' for making to attempt at finding HighFive.")

add_executable(test_hi5_dependent test_dependent_library.cpp)

if(${VENDOR_STRATEGY} STREQUAL "submodule")
# When vendoring via a Git submodule, this is the correct
# line to include HighFive.
add_subdirectory("deps/HighFive" EXCLUDE_FROM_ALL)
elseif(${VENDOR_STRATEGY} STREQUAL "fetch_content")
include(FetchContent)
FetchContent_Declare(HighFive
GIT_REPOSITORY $ENV{HIGHFIVE_GIT_REPOSITORY}
GIT_TAG $ENV{HIGHFIVE_GIT_TAG}
)
FetchContent_MakeAvailable(HighFive)
elseif(${VENDOR_STRATEGY} STREQUAL "external")
# When HighFive is installed like regular software and then "found", do the
# following:
find_package(HighFive REQUIRED)
endif()

if(NOT ${VENDOR_STRATEGY} STREQUAL "none")
target_link_libraries(test_hi5_dependent PUBLIC HighFive::HighFive)
endif()

if(NOT USE_BOOST)
find_package(Hi5Dependent REQUIRED)
target_link_libraries(test_hi5_dependent PUBLIC Hi5Dependent::Read Hi5Dependent::Write)

0 comments on commit 7ec9a53

Please sign in to comment.