FindImageMagick: Allow including multiple times
This prevents attempting to create a duplicate target by adding an
if(NOT TARGET ...)
check as in other modules. The condition was
missed in !8098 (merged).
I tested the change by placing the following CMakeLists.txt in Modules/ and running cmake -B build
.
cmake_minimum_required(VERSION 3.20)
project(CheckCodeChanges
DESCRIPTION "Confirm that FindImageMagick won't try to duplicate targets."
LANGUAGES NONE
VERSION 0.0.1.0
)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_package(ImageMagick COMPONENTS Magick++)
find_package(ImageMagick COMPONENTS Magick++)
Before fix (b83fabd0):
-- Found ImageMagick: /opt/homebrew/Cellar/imagemagick/7.1.1-33/lib/libMagick++-7.Q16HDRI.dylib (found version "7.1.1-33")
CMake Error at FindImageMagick.cmake:188 (add_library):
add_library cannot create imported target "ImageMagick::Magick++" because
another target with the same name already exists.
Call Stack (most recent call first):
FindImageMagick.cmake:235 (FIND_IMAGEMAGICK_API)
CMakeLists.txt:12 (find_package)
-- Configuring incomplete, errors occurred!
After fix (1f54fa48):
jvanderzee@V22MYH9793 Modules % cmake -B temp
-- Found ImageMagick: /opt/homebrew/Cellar/imagemagick/7.1.1-33/lib/libMagick++-7.Q16HDRI.dylib (found version "7.1.1-33")
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/jvanderzee/cmake/Modules/temp
Fixes: #25970 (closed)
Topic-rename: FindImageMagick-repeat
Edited by Brad King