From 81e355c8467666fe6b534d2aec72f4539b00436f Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 13 Jul 2022 17:33:27 +0200
Subject: [PATCH] cmake: compare 'final' symlink target of file
---
cmake/PrivateSdlFunctions.cmake | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/cmake/PrivateSdlFunctions.cmake b/cmake/PrivateSdlFunctions.cmake
index 398770b9..cf087f79 100644
--- a/cmake/PrivateSdlFunctions.cmake
+++ b/cmake/PrivateSdlFunctions.cmake
@@ -169,38 +169,37 @@ function(target_get_dynamic_library DEST TARGET)
# 1. find the target library a file might be symbolic linking to
# 2. find all other files in the same folder that symolic link to it
# 3. sort all these files, and select the 2nd item
- set(props_to_check IMPORTED_LOCATION)
+ set(location_properties IMPORTED_LOCATION)
if (CMAKE_BUILD_TYPE)
- list(APPEND props_to_check IMPORTED_LOCATION_${CMAKE_BUILD_TYPE})
+ list(APPEND location_properties IMPORTED_LOCATION_${CMAKE_BUILD_TYPE})
endif()
foreach (config_type ${CMAKE_CONFIGURATION_TYPES} RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
- list(APPEND props_to_check IMPORTED_LOCATION_${config_type})
+ list(APPEND location_properties IMPORTED_LOCATION_${config_type})
endforeach()
- foreach(prop_to_check ${props_to_check})
+ foreach(location_property ${location_properties})
if (NOT result)
- get_target_property(propvalue "${TARGET}" ${prop_to_check})
- if (EXISTS "${propvalue}")
- while (IS_SYMLINK "${propvalue}")
- read_absolute_symlink(propvalue "${propvalue}")
+ get_target_property(library_path "${TARGET}" ${location_property})
+ if (EXISTS "${library_path}")
+ while (IS_SYMLINK "${library_path}")
+ read_absolute_symlink(library_path "${library_path}")
endwhile()
- get_filename_component(libdir "${propvalue}" DIRECTORY)
+ get_filename_component(libdir "${library_path}" DIRECTORY)
file(GLOB subfiles "${libdir}/*")
- set(similar_files "${propvalue}")
+ set(similar_files "${library_path}")
foreach(subfile ${subfiles})
if (IS_SYMLINK "${subfile}")
read_absolute_symlink(subfile_target "${subfile}")
- if (subfile_target STREQUAL propvalue)
+ while (IS_SYMLINK "${subfile_target}")
+ read_absolute_symlink(subfile_target "${subfile_target}")
+ endwhile()
+ if (subfile_target STREQUAL library_path AND NOT "${subfile}" MATCHES ".*(dylib|so)$")
list(APPEND similar_files "${subfile}")
endif()
endif()
endforeach()
list(SORT similar_files)
list(LENGTH similar_files eq_length)
- if (eq_length GREATER 1)
- list(GET similar_files 1 item)
- else()
- list(GET similar_files 0 item)
- endif()
+ list(GET similar_files 0 item)
get_filename_component(result "${item}" NAME)
endif()
endif()