From 9663147bae0ea87248df8e4b401404c5c93f47b4 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Tue, 29 Oct 2024 16:32:39 +0100 Subject: [PATCH 1/3] Test mixing vendoring with dependent libraries. --- .../test_cmake_integration.sh | 42 ++++++++++++------- .../test_dependent_library/CMakeLists.txt | 23 ++++++++++ 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/tests/cmake_integration/test_cmake_integration.sh b/tests/cmake_integration/test_cmake_integration.sh index cf80fbfdd..05996adb7 100644 --- a/tests/cmake_integration/test_cmake_integration.sh +++ b/tests/cmake_integration/test_cmake_integration.sh @@ -16,10 +16,21 @@ 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}" + make_submodule ${project_dir} + for use_boost in On Off do local build_dir="${TMP_DIR}/build" @@ -35,33 +46,32 @@ 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" - 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}" + rm -rf ${test_build_dir} || true - cmake --build "${test_build_dir}" --verbose - ctest --test-dir "${test_build_dir}" --verbose + 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 diff --git a/tests/cmake_integration/test_dependent_library/CMakeLists.txt b/tests/cmake_integration/test_dependent_library/CMakeLists.txt index c9023f98a..15851c3c6 100644 --- a/tests/cmake_integration/test_dependent_library/CMakeLists.txt +++ b/tests/cmake_integration/test_dependent_library/CMakeLists.txt @@ -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) From 5eea4e52ec131c06760910fbe837d669223fe313 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Tue, 29 Oct 2024 19:32:04 +0100 Subject: [PATCH 2/3] Guard targets in `HighFiveConfig.cmake`. --- cmake/HighFiveConfig.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmake/HighFiveConfig.cmake b/cmake/HighFiveConfig.cmake index 33ce7b7b0..a263264cf 100644 --- a/cmake/HighFiveConfig.cmake +++ b/cmake/HighFiveConfig.cmake @@ -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) + From 06bcbef66461bf0c2240b40b6c23bd767ec93821 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Wed, 30 Oct 2024 20:28:09 +0100 Subject: [PATCH 3/3] fixup --- tests/cmake_integration/test_cmake_integration.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cmake_integration/test_cmake_integration.sh b/tests/cmake_integration/test_cmake_integration.sh index 05996adb7..74fd743c1 100644 --- a/tests/cmake_integration/test_cmake_integration.sh +++ b/tests/cmake_integration/test_cmake_integration.sh @@ -29,8 +29,6 @@ test_dependent_library() { local project="dependent_library" local project_dir="${TEST_DIR}/${project}" - make_submodule ${project_dir} - for use_boost in On Off do local build_dir="${TMP_DIR}/build" @@ -53,6 +51,9 @@ test_dependent_library() { local test_build_dir="${TMP_DIR}/test_build" local test_install_dir="${TMP_DIR}/test_build/install" + make_submodule ${test_project} + + rm -rf ${test_build_dir} || true cmake -DUSE_BOOST=${use_boost} \