Files
Craig Scott c6a940761c fileapi: Handle unused imported libraries with missing IMPORTED_IMPLIB
CMake 4.1 and earlier did not issue an error if an imported shared library target
was missing an IMPORTED_IMPLIB property and nothing used that imported
library. There was no code path checking for the CMP0111 NEW behavior. Since
b626843d71 (fileAPI: Output all INTERFACE and IMPORTED targets, 2025-09-13),
we now include all imported targets in the file API replies, and that does trigger
that check. We need to tolerate such imported targets to preserve backward
compatibility, and to avoid issuing errors for problems in targets likely to be
coming from outside the project and beyond the developer's control.

Fixes: #27496
2026-01-10 00:26:55 +11:00

52 lines
2.2 KiB
CMake

project(Imported)
add_library(imported_lib UNKNOWN IMPORTED)
set_target_properties(imported_lib PROPERTIES IMPORTED_LOCATION "imported_unk${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_executable(imported_exe IMPORTED)
set_target_properties(imported_exe PROPERTIES
IMPORTED_LOCATION "imported_exe${CMAKE_EXECUTABLE_SUFFIX}"
)
add_executable(link_imported_exe ../empty.c)
target_link_libraries(link_imported_exe PRIVATE imported_lib)
add_library(imported_shared_lib SHARED IMPORTED)
set_target_properties(imported_shared_lib PROPERTIES
IMPORTED_LOCATION "imported_shared${CMAKE_SHARED_LIBRARY_SUFFIX}"
IMPORTED_IMPLIB "imported_shared${CMAKE_IMPORT_LIBRARY_SUFFIX}"
)
add_executable(link_imported_shared_exe ../empty.c)
target_link_libraries(link_imported_shared_exe PRIVATE imported_shared_lib)
add_library(imported_static_lib STATIC IMPORTED)
set_target_properties(imported_static_lib PROPERTIES IMPORTED_LOCATION "imported_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_executable(link_imported_static_exe ../empty.c)
target_link_libraries(link_imported_static_exe PRIVATE imported_static_lib)
if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]")
add_library(imported_object_lib OBJECT IMPORTED)
add_executable(link_imported_object_exe ../empty.c)
target_link_libraries(link_imported_object_exe PRIVATE imported_object_lib)
endif()
add_library(imported_interface_lib INTERFACE IMPORTED)
add_executable(link_imported_interface_exe ../empty.c)
target_link_libraries(link_imported_interface_exe PRIVATE imported_interface_lib)
add_library(imported_interface_symbolic_lib INTERFACE SYMBOLIC IMPORTED)
add_executable(link_imported_interface_symbolic_exe ../empty.c)
target_link_libraries(link_imported_interface_symbolic_exe PRIVATE imported_interface_symbolic_lib)
install(IMPORTED_RUNTIME_ARTIFACTS imported_shared_lib
DESTINATION lib
)
install(IMPORTED_RUNTIME_ARTIFACTS imported_shared_lib
DESTINATION lib2 OPTIONAL
)
# This is deliberately missing the IMPORTED_IMPLIB property.
# The file API needs to tolerate this for unused imported targets.
add_library(unused_imported_shared_lib SHARED IMPORTED)
set_target_properties(unused_imported_shared_lib PROPERTIES
IMPORTED_LOCATION "unused_imported_shared${CMAKE_SHARED_LIBRARY_SUFFIX}"
)