Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find libraries by name instead of using the imported location #1142

Open
wants to merge 2 commits into
base: noetic-devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions cmake/catkin_libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,40 @@ function(catkin_unpack_libraries_with_build_configuration VAR)
set(${VAR} "${result}" PARENT_SCOPE)
endfunction()

#
# Find libraries by imported location or soname with location dir as hint
#
# :param VAR: the output variable name
# :type VAR: string
# :param LIB: the imported target to find the library for
# :type LIB: string
# :type ARGN: selected config to query in the target's properties
# :type ARGN: string
#
# @public
#
function(catkin_find_library_imported_location_library VAR LIB)
set(lib ${LIB})
if(ARGN)
set(cfg _${ARGN})
endif()
set(imported_location_libnames)
get_target_property(imported_soname ${lib} IMPORTED_SONAME${cfg})
if(imported_soname)
list(APPEND imported_location_libnames ${imported_soname})
endif()
get_target_property(imported_location ${lib} IMPORTED_LOCATION${cfg})
if(imported_location)
get_filename_component(imported_location_name ${imported_location} NAME)
get_filename_component(imported_location_dir ${imported_location} DIRECTORY)
list(APPEND imported_location_libnames ${imported_location_name})
endif()
if(imported_location_libnames)
find_library(imported_location_library NAMES ${imported_location_libnames} HINTS ${imported_location_dir} NO_CACHE)
endif()
set(${VAR} "${imported_location_library}" PARENT_SCOPE)
endfunction()

#
# Replace imported library target names with the library name.
#
Expand Down Expand Up @@ -142,10 +176,9 @@ function(catkin_replace_imported_library_targets VAR)
list(APPEND result ${${lib}_resolved_libs})
endif()
elseif(${${lib}_imported})
set(imported_libraries) # empty list
get_target_property(${lib}_imported_location ${lib} IMPORTED_LOCATION)
if(${lib}_imported_location)
list(APPEND imported_libraries ${${lib}_imported_location})
catkin_find_library_imported_location_library(${lib}_imported_location_library ${lib})
if(${lib}_imported_location_library)
list(APPEND imported_libraries ${${lib}_imported_location_library})
else()
get_target_property(${lib}_imported_configurations ${lib} IMPORTED_CONFIGURATIONS)
foreach(cfg ${${lib}_imported_configurations})
Expand All @@ -156,11 +189,14 @@ function(catkin_replace_imported_library_targets VAR)
if(NOT ${lib}_imported_location_${cfg})
get_target_property(${lib}_imported_location_${cfg} ${lib} IMPORTED_LOCATION_${cfg})
endif()
if(${lib}_imported_location_${cfg})
list(APPEND imported_libraries ${${lib}_imported_location_${cfg}})
endif()
else()
get_target_property(${lib}_imported_location_${cfg} ${lib} IMPORTED_LOCATION_${cfg})
endif()
if(${lib}_imported_location_${cfg})
list(APPEND imported_libraries ${${lib}_imported_location_${cfg}})
catkin_find_library_imported_location_library(${lib}_imported_location_library_${cfg} ${lib} ${cfg})
if(${lib}_imported_location_library_${cfg})
list(APPEND imported_libraries ${${lib}_imported_location_library_${cfg}})
endif()
endif()
endforeach()
endif()
Expand Down