Merge pull request #10631 from yiwu0b11/destdir_install_env_support

Support DESTDIR for install and add build-system test
This commit is contained in:
Gilles Peskine
2026-04-29 14:37:29 +00:00
committed by GitHub
3 changed files with 58 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
Features
* Restore DESTDIR support for CMake installs of compatibility
libmbedcrypto symlinks. Fixes #10627.

View File

@@ -361,7 +361,7 @@ foreach(target IN LISTS tf_psa_crypto_library_targets)
RENAME "libmbedcrypto.so.${MBEDTLS_VERSION}"
)
install(CODE "
set(_libdir \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\")
set(_libdir \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\")
execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink
\"libmbedcrypto.so.${MBEDTLS_VERSION}\"

View File

@@ -155,6 +155,60 @@ support_test_cmake_as_package_install () {
support_test_cmake_out_of_source
}
component_test_cmake_install_with_destdir () {
# Remove existing generated files so that we use the ones CMake
# generates
$MAKE_COMMAND neat
msg "install: cmake with DESTDIR staging"
MBEDTLS_ROOT_DIR="$PWD"
mkdir "$OUT_OF_SOURCE_DIR"
cd "$OUT_OF_SOURCE_DIR"
cmake -DGEN_FILES=ON -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr "$MBEDTLS_ROOT_DIR"
make
DESTDIR="$OUT_OF_SOURCE_DIR/stage" make install
install_lib_subdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)"
[ -n "$install_lib_subdir" ] # Failed to read CMAKE_INSTALL_LIBDIR from CMakeCache.txt
install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}"
if [[ "$OSTYPE" == darwin* ]]; then
# On macOS the custom install logic installs libmbedcrypto.dylib
# directly without a versioned symlink chain.
for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do
[ -f "$install_lib_path/lib${lib}.a" ]
[ -e "$install_lib_path/lib${lib}.dylib" ]
done
else
# library/CMakeLists.txt installs libmbedcrypto.so with a versioned
# symlink chain on Linux.
for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do
if [ "$QUIET" -eq 0 ]; then
echo "Checking lib=$lib"
fi
[ -f "$install_lib_path/lib${lib}.a" ]
[ -L "$install_lib_path/lib${lib}.so" ]
[ -e "$install_lib_path/lib${lib}.so" ]
# Match ABI-version names such as libxxx.so.17
# and check that symlink.
versioned=( "$install_lib_path/lib${lib}.so".+([0-9]) )
if [ "$QUIET" -eq 0 ]; then
declare -p versioned
fi
[ "${#versioned[@]}" -eq 1 ]
[ -L "${versioned[0]}" ]
[ -e "${versioned[0]}" ]
done
fi
}
support_test_cmake_install_with_destdir () {
support_test_cmake_out_of_source
}
component_build_cmake_custom_config_file () {
# Make a copy of config file to use for the in-tree test
cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h