]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Protects against double find_package
authorBenjamin Buch <bebuch@users.noreply.github.com>
Tue, 6 Jun 2023 13:32:45 +0000 (15:32 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 7 May 2024 12:23:21 +0000 (15:23 +0300)
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 d04eb78ab3892d3678c180437dd66379efa051fd)

CMakeLists.txt

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