From 26916beb553010003611d74ae229540ccedbea09 Mon Sep 17 00:00:00 2001 From: Evgeniy Patlan Date: Wed, 19 Aug 2026 12:54:48 +0300 Subject: [PATCH] Make bundled binary copy targets unique and name-safe install_bundled_binaries derived its custom target name directly from the binary's basename. Two problems follow from that: - CMake target names may not contain characters such as dots, so bundling a versioned library like libssl.so.3 produces an invalid target name - bundling two files that share a basename produces a duplicate target and the configure step fails Sanitise the basename and append a numeric suffix if the target already exists. --- cmake/exeutils.cmake | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmake/exeutils.cmake b/cmake/exeutils.cmake index dcf6e54af..ab31ef99d 100644 --- a/cmake/exeutils.cmake +++ b/cmake/exeutils.cmake @@ -196,7 +196,15 @@ function(install_bundled_binaries) foreach(SOURCE_BINARY ${ARG_BINARIES}) get_filename_component(SOURCE_BINARY_NAME "${SOURCE_BINARY}" NAME) set(COPIED_BINARY "${DESTINATION_BINARY_DIR}/${SOURCE_BINARY_NAME}") - set(COPY_TARGET "copy_${SOURCE_BINARY_NAME}") + # Target names may not contain characters such as dots, and two bundled + # files may share a basename, so sanitise and de-duplicate + string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" SAFE_BINARY_NAME "${SOURCE_BINARY_NAME}") + set(COPY_TARGET "copy_${SAFE_BINARY_NAME}") + set(_copy_target_suffix 0) + while(TARGET "${COPY_TARGET}") + math(EXPR _copy_target_suffix "${_copy_target_suffix} + 1") + set(COPY_TARGET "copy_${SAFE_BINARY_NAME}_${_copy_target_suffix}") + endwhile() SET(COPY_COMMAND "") if(NOT IS_SYMLINK "${SOURCE_BINARY}")