]> 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)
committerGitHub <noreply@github.com>
Tue, 6 Jun 2023 13:32:45 +0000 (21:32 +0800)
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 "ZLIB::ZLIB" because another
target with the same name already exists.`

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

CMakeLists.txt

index 55cd358cab9ad9ebcfc6387c136aabff37825f73..458ad49de1d8287dab862e51cb002fca36eaea7e 100644 (file)
@@ -889,13 +889,15 @@ write_basic_package_version_file(
 set(LZMA_CONFIG_CONTENTS
 "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()
 ")
 
 if(ENABLE_THREADS STREQUAL "posix")