Skip to content

Commit 32222fa

Browse files
committed
test: export of targets into build directories.
Check that build directories can be the source of HighFive.
1 parent ed24136 commit 32222fa

File tree

2 files changed

+100
-32
lines changed

2 files changed

+100
-32
lines changed

tests/cmake_integration/dependent_library/CMakeLists.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,28 @@ if(${INTEGRATION_STRATEGY} STREQUAL "bailout")
3434
set(HIGHFIVE_FIND_HDF5 Off)
3535
endif()
3636

37-
# Since any project depending on 'Hi5Dependent' also needs HighFive, it doesn't
38-
# make sense to vendor HighFive. Therefore, use
39-
find_package(HighFive REQUIRED)
37+
if(${VENDOR_STRATEGY} STREQUAL "submodule_excl")
38+
# When vendoring via a Git submodule, this will not install HighFive
39+
# alongside this library. It it likely the preferred option.
40+
add_subdirectory("deps/HighFive" EXCLUDE_FROM_ALL)
41+
elseif(${VENDOR_STRATEGY} STREQUAL "submodule_incl")
42+
# When vendoring via a Git submodule, this will install HighFive
43+
# alongside this library.
44+
add_subdirectory("deps/HighFive")
45+
elseif(${VENDOR_STRATEGY} STREQUAL "fetch_content")
46+
# By default FetchContent will include HighFive in the targets to be
47+
# installed.
48+
include(FetchContent)
49+
FetchContent_Declare(HighFive
50+
GIT_REPOSITORY $ENV{HIGHFIVE_GIT_REPOSITORY}
51+
GIT_TAG $ENV{HIGHFIVE_GIT_TAG}
52+
)
53+
FetchContent_MakeAvailable(HighFive)
54+
elseif(${VENDOR_STRATEGY} STREQUAL "external")
55+
# When HighFive is installed like regular software and then "found", do the
56+
# following:
57+
find_package(HighFive REQUIRED)
58+
endif()
4059

4160
# For demonstration purposes it consists of a shared and static library
4261
add_library(${PROJECT_NAME}Write SHARED "src/hi5_dependent/write_vector.cpp")
@@ -124,6 +143,11 @@ install(FILES
124143
DESTINATION cmake
125144
)
126145

146+
export(EXPORT ${PROJECT_NAME}Targets
147+
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Targets.cmake"
148+
NAMESPACE Hi5Dependent::
149+
)
150+
127151
if(USE_BOOST)
128152
install(TARGETS ${PROJECT_NAME}Boost EXPORT ${PROJECT_NAME}BoostTargets)
129153
install(EXPORT ${PROJECT_NAME}BoostTargets

tests/cmake_integration/test_cmake_integration.sh

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,91 @@ make_submodule() {
2323
rm "${dep_dir}" || true
2424
mkdir -p "$(dirname "${dep_dir}")"
2525
ln -sf "${HIGHFIVE_DIR}" "${dep_dir}"
26+
27+
tar -C ${project_dir}/deps -cf ${project_dir}/deps/HighFive.tar HighFive
2628
}
2729

2830
test_dependent_library() {
2931
local project="dependent_library"
3032
local project_dir="${TEST_DIR}/${project}"
3133

34+
make_submodule ${project_dir}
35+
3236
for use_boost in On Off
3337
do
3438
local build_dir="${TMP_DIR}/build"
3539
local install_dir="${TMP_DIR}/build/install"
3640

37-
rm -rf ${build_dir} || true
38-
39-
cmake "$@" \
40-
-DUSE_BOOST=${use_boost} \
41-
-DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR}" \
42-
-DCMAKE_INSTALL_PREFIX="${install_dir}" \
43-
-B "${build_dir}" "${project_dir}"
44-
45-
cmake --build "${build_dir}" --verbose --target install
46-
47-
48-
for vendor in submodule fetch_content external none
41+
for lib_vendor in external_build submodule_excl submodule_incl fetch_content external_install
4942
do
50-
local test_project="test_dependent_library"
51-
local test_build_dir="${TMP_DIR}/test_build"
52-
local test_install_dir="${TMP_DIR}/test_build/install"
53-
54-
make_submodule ${test_project}
55-
43+
rm -rf ${build_dir} || true
5644

57-
rm -rf ${test_build_dir} || true
45+
if [[ ${lib_vendor} == external_install ]]
46+
then
47+
cmake_extra_args=(
48+
-DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR}"
49+
-DVENDOR_STRATEGY=external
50+
)
51+
elif [[ ${lib_vendor} == external_build ]]
52+
then
53+
cmake_extra_args=(
54+
-DCMAKE_PREFIX_PATH="${HIGHFIVE_BUILD_DIR}"
55+
-DVENDOR_STRATEGY=external
56+
)
57+
elif [[ ${lib_vendor} == submodule_excl ]]
58+
then
59+
cmake_extra_args=(
60+
-DCMAKE_PREFIX_PATH="${HIGHFIVE_BUILD_DIR}"
61+
-DVENDOR_STRATEGY=${lib_vendor}
62+
)
63+
else
64+
cmake_extra_args=(
65+
-DVENDOR_STRATEGY=${lib_vendor}
66+
)
67+
fi
5868

59-
cmake -DUSE_BOOST=${use_boost} \
60-
-DVENDOR_STRATEGY=${vendor} \
61-
-DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR};${install_dir}" \
62-
-DCMAKE_INSTALL_PREFIX="${test_install_dir}" \
63-
-B "${test_build_dir}" "${test_project}"
69+
cmake "$@" \
70+
-DUSE_BOOST=${use_boost} \
71+
-DCMAKE_INSTALL_PREFIX="${install_dir}" \
72+
${cmake_extra_args[@]} \
73+
-B "${build_dir}" "${project_dir}"
6474

65-
cmake --build "${test_build_dir}" --verbose
66-
ctest --test-dir "${test_build_dir}" --verbose
75+
cmake --build "${build_dir}" --parallel --verbose --target install
76+
77+
dep_vendor_strats=(none fetch_content external submodule)
78+
for dep_vendor in ${dep_vendor_strats[@]}
79+
do
80+
local test_project="test_dependent_library"
81+
local test_build_dir="${TMP_DIR}/test_build"
82+
local test_install_dir="${TMP_DIR}/test_build/install"
83+
84+
make_submodule ${test_project}
85+
86+
rm -rf ${test_build_dir} || true
87+
88+
if [[ ${lib_vendor} == external*
89+
|| ${lib_vendor} == "submodule_excl"
90+
|| ${dep_vendor} == "external"
91+
|| ${dep_vendor} == "none" ]]
92+
then
93+
cmake_extra_args=(
94+
-DCMAKE_PREFIX_PATH="${HIGHFIVE_INSTALL_DIR};${install_dir}"
95+
)
96+
else
97+
cmake_extra_args=(
98+
-DCMAKE_PREFIX_PATH="${install_dir}"
99+
)
100+
fi
101+
102+
cmake -DUSE_BOOST=${use_boost} \
103+
-DVENDOR_STRATEGY=${dep_vendor} \
104+
-DCMAKE_INSTALL_PREFIX="${test_install_dir}" \
105+
${cmake_extra_args[@]} \
106+
-B "${test_build_dir}" "${test_project}"
107+
108+
cmake --build "${test_build_dir}" --parallel --verbose
109+
ctest --test-dir "${test_build_dir}" --verbose
110+
done
67111
done
68112
done
69113
}
@@ -90,7 +134,7 @@ test_application() {
90134
-DCMAKE_INSTALL_PREFIX="${install_dir}" \
91135
-B "${build_dir}" "${project_dir}"
92136

93-
cmake --build "${build_dir}" --verbose --target install
137+
cmake --build "${build_dir}" --verbose --parallel --target install
94138
ctest --test-dir "${build_dir}"
95139
"${install_dir}"/bin/Hi5Application
96140
done
@@ -103,9 +147,9 @@ cmake -DHIGHFIVE_EXAMPLES=OFF \
103147
-B "${HIGHFIVE_BUILD_DIR}" \
104148
"${HIGHFIVE_DIR}"
105149

106-
cmake --build "${HIGHFIVE_BUILD_DIR}" --target install
150+
cmake --build "${HIGHFIVE_BUILD_DIR}" --parallel --target install
107151

108-
for integration in Include full short bailout
152+
for integration in full Include short bailout
109153
do
110154
test_dependent_library \
111155
-DINTEGRATION_STRATEGY=${integration}

0 commit comments

Comments
 (0)