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

Guard targets in HighFiveConfig.cmake. #1053

Merged
merged 3 commits into from
Nov 5, 2024
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
16 changes: 10 additions & 6 deletions cmake/HighFiveConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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}"
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/cmake_integration/test_dependent_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading