From 32222fae95d6cfb7207a9aa23dbe01e4b3a4a669 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Wed, 26 Mar 2025 15:17:54 +0100 Subject: [PATCH] test: export of targets into build directories. Check that build directories can be the source of HighFive. --- .../dependent_library/CMakeLists.txt | 30 +++++- .../test_cmake_integration.sh | 102 +++++++++++++----- 2 files changed, 100 insertions(+), 32 deletions(-) diff --git a/tests/cmake_integration/dependent_library/CMakeLists.txt b/tests/cmake_integration/dependent_library/CMakeLists.txt index ad76d99b..bda7f580 100644 --- a/tests/cmake_integration/dependent_library/CMakeLists.txt +++ b/tests/cmake_integration/dependent_library/CMakeLists.txt @@ -34,9 +34,28 @@ if(${INTEGRATION_STRATEGY} STREQUAL "bailout") set(HIGHFIVE_FIND_HDF5 Off) endif() -# Since any project depending on 'Hi5Dependent' also needs HighFive, it doesn't -# make sense to vendor HighFive. Therefore, use -find_package(HighFive REQUIRED) +if(${VENDOR_STRATEGY} STREQUAL "submodule_excl") + # When vendoring via a Git submodule, this will not install HighFive + # alongside this library. It it likely the preferred option. + add_subdirectory("deps/HighFive" EXCLUDE_FROM_ALL) +elseif(${VENDOR_STRATEGY} STREQUAL "submodule_incl") + # When vendoring via a Git submodule, this will install HighFive + # alongside this library. + add_subdirectory("deps/HighFive") +elseif(${VENDOR_STRATEGY} STREQUAL "fetch_content") + # By default FetchContent will include HighFive in the targets to be + # installed. + 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() # For demonstration purposes it consists of a shared and static library add_library(${PROJECT_NAME}Write SHARED "src/hi5_dependent/write_vector.cpp") @@ -124,6 +143,11 @@ install(FILES DESTINATION cmake ) +export(EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake" + NAMESPACE Hi5Dependent:: +) + if(USE_BOOST) install(TARGETS ${PROJECT_NAME}Boost EXPORT ${PROJECT_NAME}BoostTargets) install(EXPORT ${PROJECT_NAME}BoostTargets diff --git a/tests/cmake_integration/test_cmake_integration.sh b/tests/cmake_integration/test_cmake_integration.sh index 74fd743c..cb67da13 100644 --- a/tests/cmake_integration/test_cmake_integration.sh +++ b/tests/cmake_integration/test_cmake_integration.sh @@ -23,47 +23,91 @@ make_submodule() { rm "${dep_dir}" || true mkdir -p "$(dirname "${dep_dir}")" ln -sf "${HIGHFIVE_DIR}" "${dep_dir}" + + tar -C ${project_dir}/deps -cf ${project_dir}/deps/HighFive.tar HighFive } 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" local install_dir="${TMP_DIR}/build/install" - rm -rf ${build_dir} || true - - cmake "$@" \ - -DUSE_BOOST=${use_boost} \ - -DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR}" \ - -DCMAKE_INSTALL_PREFIX="${install_dir}" \ - -B "${build_dir}" "${project_dir}" - - cmake --build "${build_dir}" --verbose --target install - - - for vendor in submodule fetch_content external none + for lib_vendor in external_build submodule_excl submodule_incl fetch_content external_install 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} - + rm -rf ${build_dir} || true - rm -rf ${test_build_dir} || true + if [[ ${lib_vendor} == external_install ]] + then + cmake_extra_args=( + -DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR}" + -DVENDOR_STRATEGY=external + ) + elif [[ ${lib_vendor} == external_build ]] + then + cmake_extra_args=( + -DCMAKE_PREFIX_PATH="${HIGHFIVE_BUILD_DIR}" + -DVENDOR_STRATEGY=external + ) + elif [[ ${lib_vendor} == submodule_excl ]] + then + cmake_extra_args=( + -DCMAKE_PREFIX_PATH="${HIGHFIVE_BUILD_DIR}" + -DVENDOR_STRATEGY=${lib_vendor} + ) + else + cmake_extra_args=( + -DVENDOR_STRATEGY=${lib_vendor} + ) + fi - 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 "$@" \ + -DUSE_BOOST=${use_boost} \ + -DCMAKE_INSTALL_PREFIX="${install_dir}" \ + ${cmake_extra_args[@]} \ + -B "${build_dir}" "${project_dir}" - cmake --build "${test_build_dir}" --verbose - ctest --test-dir "${test_build_dir}" --verbose + cmake --build "${build_dir}" --parallel --verbose --target install + + dep_vendor_strats=(none fetch_content external submodule) + for dep_vendor in ${dep_vendor_strats[@]} + 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} + + rm -rf ${test_build_dir} || true + + if [[ ${lib_vendor} == external* + || ${lib_vendor} == "submodule_excl" + || ${dep_vendor} == "external" + || ${dep_vendor} == "none" ]] + then + cmake_extra_args=( + -DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR};${install_dir}" + ) + else + cmake_extra_args=( + -DCMAKE_PREFIX_PATH="${install_dir}" + ) + fi + + cmake -DUSE_BOOST=${use_boost} \ + -DVENDOR_STRATEGY=${dep_vendor} \ + -DCMAKE_INSTALL_PREFIX="${test_install_dir}" \ + ${cmake_extra_args[@]} \ + -B "${test_build_dir}" "${test_project}" + + cmake --build "${test_build_dir}" --parallel --verbose + ctest --test-dir "${test_build_dir}" --verbose + done done done } @@ -90,7 +134,7 @@ test_application() { -DCMAKE_INSTALL_PREFIX="${install_dir}" \ -B "${build_dir}" "${project_dir}" - cmake --build "${build_dir}" --verbose --target install + cmake --build "${build_dir}" --verbose --parallel --target install ctest --test-dir "${build_dir}" "${install_dir}"/bin/Hi5Application done @@ -103,9 +147,9 @@ cmake -DHIGHFIVE_EXAMPLES=OFF \ -B "${HIGHFIVE_BUILD_DIR}" \ "${HIGHFIVE_DIR}" -cmake --build "${HIGHFIVE_BUILD_DIR}" --target install +cmake --build "${HIGHFIVE_BUILD_DIR}" --parallel --target install -for integration in Include full short bailout +for integration in full Include short bailout do test_dependent_library \ -DINTEGRATION_STRATEGY=${integration}