CMake: Improve finding library name or path of imported targets

Checking LOCATION{_CONFIG} property on interfaces is only supported
since CMake 3.19. Also check the LOCATION and IMPORTED_LIBNAME
properties for possible library locations.

See #23632.

(cherry picked from commit 0f1f61a9c8c9fc8c4cb81a380df157e8171b0712)
This commit is contained in:
Maarten Bent 2023-06-13 21:19:49 +02:00 committed by Vadim Zeitlin
parent 61c28b300c
commit 0a2502cfab

View File

@ -40,14 +40,25 @@ macro(wx_get_dependencies var lib)
else() else()
get_target_property(dep_name ${dep} OUTPUT_NAME) get_target_property(dep_name ${dep} OUTPUT_NAME)
endif() endif()
if(NOT dep_name)
# imported target # imported target
if(CMAKE_VERSION VERSION_GREATER "3.18")
# CMake <= 3.18 only allows a few properties to be checked, not LOCATION, see
# https://cmake.org/cmake/help/v3.18/manual/cmake-buildsystem.7.html#interface-libraries
set(prop_suffix) set(prop_suffix)
if (CMAKE_BUILD_TYPE) if (CMAKE_BUILD_TYPE)
string(TOUPPER "${CMAKE_BUILD_TYPE}" prop_suffix) string(TOUPPER "${CMAKE_BUILD_TYPE}" prop_suffix)
set(prop_suffix "_${prop_suffix}") set(prop_suffix "_${prop_suffix}")
endif() endif()
get_target_property(dep_name ${dep} LOCATION${prop_suffix}) if(NOT dep_name AND prop_suffix)
get_target_property(dep_name ${dep} LOCATION${prop_suffix})
endif()
if(NOT dep_name)
get_target_property(dep_name ${dep} LOCATION)
endif()
endif()
if(NOT dep_name)
get_target_property(dep_name ${dep} IMPORTED_LIBNAME)
endif() endif()
else() else()
# For the value like $<$<CONFIG:DEBUG>:LIB_PATH> # For the value like $<$<CONFIG:DEBUG>:LIB_PATH>