FindImageMagick: Define targets for specific components

- With this change we can use e.g. ImageMagick::Magick++ directly
  in targt_link_libraries.
- This change also adds CFLAGS which was missing before.
- Also adds example on how to use the targets.
This commit is contained in:
hstejas 2023-01-20 16:04:32 +05:30 committed by Brad King
parent 7ac338be98
commit 1bba218214
9 changed files with 129 additions and 47 deletions

View File

@ -27,6 +27,7 @@ set(CMake_TEST_FindGTest "ON" CACHE BOOL "")
set(CMake_TEST_FindGTK2 "ON" CACHE BOOL "")
set(CMake_TEST_FindIconv "ON" CACHE BOOL "")
set(CMake_TEST_FindICU "ON" CACHE BOOL "")
set(CMake_TEST_FindImageMagick "ON" CACHE BOOL "")
set(CMake_TEST_FindIntl "ON" CACHE BOOL "")
set(CMake_TEST_FindJNI "ON" CACHE BOOL "")
set(CMake_TEST_FindJPEG "ON" CACHE BOOL "")

View File

@ -31,6 +31,7 @@ set(CMake_TEST_FindGTest "ON" CACHE BOOL "")
set(CMake_TEST_FindGTK2 "ON" CACHE BOOL "")
set(CMake_TEST_FindIconv "ON" CACHE BOOL "")
set(CMake_TEST_FindICU "ON" CACHE BOOL "")
set(CMake_TEST_FindImageMagick "ON" CACHE BOOL "")
set(CMake_TEST_FindIntl "ON" CACHE BOOL "")
set(CMake_TEST_FindJNI "ON" CACHE BOOL "")
set(CMake_TEST_FindJPEG "ON" CACHE BOOL "")

View File

@ -30,6 +30,7 @@ set(CMake_TEST_FindGTest "ON" CACHE BOOL "")
set(CMake_TEST_FindGTK2 "ON" CACHE BOOL "")
set(CMake_TEST_FindIconv "ON" CACHE BOOL "")
set(CMake_TEST_FindICU "ON" CACHE BOOL "")
set(CMake_TEST_FindImageMagick "ON" CACHE BOOL "")
set(CMake_TEST_FindIntl "ON" CACHE BOOL "")
set(CMake_TEST_FindJNI "ON" CACHE BOOL "")
set(CMake_TEST_FindJPEG "ON" CACHE BOOL "")

View File

@ -5,7 +5,9 @@
FindImageMagick
---------------
Find ImageMagick binary suite.
Find ImageMagick, software suite for displaying, converting and
manipulating raster images.
.. versionadded:: 3.9
Added support for ImageMagick 7.
@ -15,65 +17,87 @@ components in the :command:`find_package` call. Typical components include,
but are not limited to (future versions of ImageMagick might have
additional components not listed here):
::
animate
compare
composite
conjure
convert
display
identify
import
mogrify
montage
stream
* ``animate``
* ``compare``
* ``composite``
* ``conjure``
* ``convert``
* ``display``
* ``identify``
* ``import``
* ``mogrify``
* ``montage``
* ``stream``
If no component is specified in the :command:`find_package` call, then it only
searches for the ImageMagick executable directory. This code defines
the following variables:
::
ImageMagick_FOUND - TRUE if all components are found.
ImageMagick_EXECUTABLE_DIR - Full path to executables directory.
ImageMagick_<component>_FOUND - TRUE if <component> is found.
ImageMagick_<component>_EXECUTABLE - Full path to <component> executable.
ImageMagick_VERSION_STRING - the version of ImageMagick found
(since CMake 2.8.8)
``ImageMagick_VERSION_STRING`` will not work for old versions like 5.2.3.
searches for the ImageMagick executable directory.
There are also components for the following ImageMagick APIs:
::
Magick++
MagickWand
MagickCore
* ``Magick++``: ImageMagick C++ API, if found.
* ``MagickWand``: ImageMagick MagickWand C API, if found.
* ``MagickCore``: ImageMagick MagickCore low-level C API, if found.
Imported targets
^^^^^^^^^^^^^^^^
For these components the following variables are set:
.. versionadded:: 3.26
::
This module defines the following :prop_tgt:`IMPORTED` targets:
ImageMagick_FOUND - TRUE if all components are found.
ImageMagick_INCLUDE_DIRS - Full paths to all include dirs.
ImageMagick_LIBRARIES - Full paths to all libraries.
ImageMagick_<component>_FOUND - TRUE if <component> is found.
ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
ImageMagick_<component>_LIBRARIES - Full path to <component> libraries.
``ImageMagick::Magick++``
ImageMagick C++ API, if found.
``ImageMagick::MagickWand``
ImageMagick MagickWand C API, if found.
``ImageMagick::MagickCore``
ImageMagick MagickCore low-level C API, if found.
Result Variables
^^^^^^^^^^^^^^^^
``ImageMagick_FOUND``
TRUE if all components are found.
``ImageMagick_EXECUTABLE_DIR``
Full path to executables directory.
``ImageMagick_INCLUDE_DIRS``
Full paths to all include dirs.
``ImageMagick_LIBRARIES``
Full paths to all libraries.
``ImageMagick_COMPILE_OPTIONS``
Compile options of all libraries.
``ImageMagick_VERSION_STRING``
The version of ImageMagick found (since CMake 2.8.8).
Will not work for old versions like 5.2.3.
``ImageMagick_<component>_FOUND``
TRUE if <component> is found.
``ImageMagick_<component>_EXECUTABLE``
Full path to <component> executable.
``ImageMagick_<component>_INCLUDE_DIRS``
Full path to <component> include dirs.
``ImageMagick_<component>_COMPILE_OPTIONS``
.. versionadded:: 3.26
Compile options of <component>.
``ImageMagick_<component>_LIBRARIES``
Full path to <component> libraries.
Example Usages:
::
^^^^^^^^^^^^^^^
find_package(ImageMagick)
find_package(ImageMagick COMPONENTS convert)
@ -81,7 +105,7 @@ Example Usages:
find_package(ImageMagick COMPONENTS Magick++)
find_package(ImageMagick COMPONENTS Magick++ convert)
target_link_libraries(example PRIVATE ImageMagick::Magick++)
Note that the standard :command:`find_package` features are supported (i.e.,
``QUIET``, ``REQUIRED``, etc.).
@ -150,6 +174,8 @@ function(FIND_IMAGEMAGICK_API component header)
set(ImageMagick_${component}_INCLUDE_DIRS
${ImageMagick_${component}_INCLUDE_DIRS} PARENT_SCOPE)
set(ImageMagick_${component}_COMPILE_OPTIONS ${PC_${component}_CFLAGS_OTHER})
# Add the per-component include directories to the full include dirs.
list(APPEND ImageMagick_INCLUDE_DIRS ${ImageMagick_${component}_INCLUDE_DIRS})
list(REMOVE_DUPLICATES ImageMagick_INCLUDE_DIRS)
@ -159,6 +185,17 @@ function(FIND_IMAGEMAGICK_API component header)
${ImageMagick_${component}_LIBRARY}
)
set(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES} PARENT_SCOPE)
list(APPEND ImageMagick_COMPILE_OPTIONS
${ImageMagick_${component}_COMPILE_OPTIONS}
)
set(ImageMagick_COMPILE_OPTIONS ${ImageMagick_COMPILE_OPTIONS} PARENT_SCOPE)
add_library(ImageMagick::${component} UNKNOWN IMPORTED)
set_target_properties(ImageMagick::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ImageMagick_${component}_INCLUDE_DIRS}"
INTERFACE_COMPILE_OPTIONS "${ImageMagick_${component}_COMPILE_OPTIONS}"
IMPORTED_LOCATION "${ImageMagick_${component}_LIBRARY}")
endif()
endfunction()

View File

@ -1480,6 +1480,7 @@ if(BUILD_TESTING)
GTK2
Iconv
ICU
ImageMagick
Intl
Jasper
JNI

View File

@ -0,0 +1,10 @@
add_test(NAME FindImageMagick.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindImageMagick/Test"
"${CMake_BINARY_DIR}/Tests/FindImageMagick/Test"
${build_generator_args}
--build-project TestFindImageMagick
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)

View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.4)
project(FindImageMagick C CXX)
include(CTest)
find_package(ImageMagick REQUIRED COMPONENTS Magick++ MagickWand)
add_executable(test_magick++ main_magick++.cxx)
target_link_libraries(test_magick++ PRIVATE ImageMagick::Magick++)
add_test(NAME test_magick++ COMMAND test_magick++)
add_executable(test_magick_wand main_magick_wand.c)
target_link_libraries(test_magick_wand ImageMagick::MagickWand)
add_test(NAME test_magick_wand COMMAND test_magick_wand)

View File

@ -0,0 +1,10 @@
#include <iostream>
#include <string>
#include <Magick++.h>
int main()
{
Magick::InitializeMagick("");
return 0;
}

View File

@ -0,0 +1,8 @@
#include <wand/MagickWand.h>
int main()
{
MagickWand* wand = NewMagickWand();
wand = DestroyMagickWand(wand);
return 0;
}