CMake: Protects against double find_package

Boost iostream uses `find_package` in quiet mode and then again uses
`find_package` with required. This second call triggers a
`add_library cannot create imported target "LibLZMA::LibLZMA"
because another target with the same name already exists.`

This can simply be fixed by skipping the alias part on secondary
`find_package` runs.

(cherry picked from commit d04eb78ab3)
This commit is contained in:
Benjamin Buch 2023-06-06 15:32:45 +02:00 committed by Lasse Collin
parent 774145adfd
commit b276ef1f49
1 changed files with 9 additions and 7 deletions

View File

@ -523,13 +523,15 @@ find_dependency(Threads)
include(\"\${CMAKE_CURRENT_LIST_DIR}/liblzma-targets.cmake\") include(\"\${CMAKE_CURRENT_LIST_DIR}/liblzma-targets.cmake\")
# Be compatible with the spelling used by the FindLibLZMA module. This if(NOT TARGET LibLZMA::LibLZMA)
# doesn't use ALIAS because it would make CMake resolve LibLZMA::LibLZMA # Be compatible with the spelling used by the FindLibLZMA module. This
# to liblzma::liblzma instead of keeping the original spelling. Keeping # doesn't use ALIAS because it would make CMake resolve LibLZMA::LibLZMA
# the original spelling is important for good FindLibLZMA compatibility. # to liblzma::liblzma instead of keeping the original spelling. Keeping
add_library(LibLZMA::LibLZMA INTERFACE IMPORTED) # the original spelling is important for good FindLibLZMA compatibility.
set_target_properties(LibLZMA::LibLZMA PROPERTIES add_library(LibLZMA::LibLZMA INTERFACE IMPORTED)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
INTERFACE_LINK_LIBRARIES liblzma::liblzma) INTERFACE_LINK_LIBRARIES liblzma::liblzma)
endif()
") ")
# Set CMAKE_INSTALL_LIBDIR and friends. # Set CMAKE_INSTALL_LIBDIR and friends.