|
| 1 | +# |
| 2 | +# FindGraphicsMagick.cmake |
| 3 | +# |
| 4 | +# When done, if GraphicsMagick is found, the following will be defined: |
| 5 | +# |
| 6 | +# Library Targets: |
| 7 | +# - GraphicsMagick::GraphicsMagick |
| 8 | +# |
| 9 | +# Global Variables: |
| 10 | +# - GRAPHICSMAGICK_FOUND |
| 11 | +# |
| 12 | + |
| 13 | +# Use pkg-config, if available, to help find the library |
| 14 | +find_package(PkgConfig) |
| 15 | +pkg_check_modules(PC_GRAPHICSMAGICK GraphicsMagick) |
| 16 | + |
| 17 | +# Find the header(s) |
| 18 | +find_path(GRAPHICSMAGICK_INCLUDE_DIRS |
| 19 | + NAMES magick/api.h |
| 20 | + HINTS ${PC_GRAPHICSMAGICK_INCLUDE_DIRS} |
| 21 | +) |
| 22 | + |
| 23 | +# Find the pre-compiled binary. For Windows + MSVC, this will be its .lib file. |
| 24 | +find_library(GRAPHICSMAGICK_LIBRARIES |
| 25 | + GraphicsMagick |
| 26 | + HINTS ${PC_GRAPHICSMAGICK_LIBRARY_DIRS} |
| 27 | +) |
| 28 | + |
| 29 | +# Search for base path of installation |
| 30 | +if (GRAPHICSMAGICK_INCLUDE_DIRS) |
| 31 | + set(_TMP_PATH ${GRAPHICSMAGICK_INCLUDE_DIRS}) |
| 32 | + while(TRUE) |
| 33 | + get_filename_component(_TMP_PATH_PART ${_TMP_PATH} NAME) |
| 34 | + string(TOLOWER ${_TMP_PATH_PART} _TMP_PATH_PART) |
| 35 | + if (${_TMP_PATH_PART} STREQUAL "graphicsmagick" OR ${_TMP_PATH_PART} STREQUAL "include") |
| 36 | + get_filename_component(_TMP_PATH ${_TMP_PATH} DIRECTORY) |
| 37 | + continue() |
| 38 | + endif() |
| 39 | + if (NOT (${_TMP_PATH} STREQUAL "")) |
| 40 | + set(GRAPHICSMAGICK_PATH ${_TMP_PATH}) |
| 41 | + endif() |
| 42 | + break() |
| 43 | + endwhile() |
| 44 | +endif() |
| 45 | + |
| 46 | +# Look for a pre-compiled .dll file |
| 47 | +find_path(GRAPHICSMAGICK_DLL |
| 48 | + NAMES graphicsmagick.dll |
| 49 | + HINTS ${GRAPHICSMAGICK_PATH} |
| 50 | + PATH_SUFFIXES bin |
| 51 | +) |
| 52 | + |
| 53 | +# Perform CMake Find-module stuff |
| 54 | +include(FindPackageHandleStandardArgs) |
| 55 | +find_package_handle_standard_args(GraphicsMagick |
| 56 | + REQUIRED_VARS GRAPHICSMAGICK_INCLUDE_DIRS GRAPHICSMAGICK_LIBRARIES |
| 57 | +) |
| 58 | + |
| 59 | +# Create a library target |
| 60 | +if (GRAPHICSMAGICK_FOUND AND NOT TARGET GraphicsMagick::GraphicsMagick) |
| 61 | + if (GRAPHICSMAGICK_DLL) |
| 62 | + # Not using 'SHARED' when Cairo is available through a .dll can |
| 63 | + # cause build issues with MSVC, at least when trying to link against |
| 64 | + # a vcpkg-provided copy of "cairod". |
| 65 | + add_library(GraphicsMagick::GraphicsMagick SHARED IMPORTED) |
| 66 | + else() |
| 67 | + add_library(GraphicsMagick::GraphicsMagick UNKNOWN IMPORTED) |
| 68 | + endif() |
| 69 | + |
| 70 | + set_target_properties(GraphicsMagick::GraphicsMagick PROPERTIES |
| 71 | + IMPORTED_LINK_INTERFACE_LANGUAGES "C" |
| 72 | + INTERFACE_INCLUDE_DIRECTORIES ${GRAPHICSMAGICK_INCLUDE_DIRS} |
| 73 | + ) |
| 74 | + |
| 75 | + if (GRAPHICSMAGICK_DLL) |
| 76 | + # When using a .dll, the location of *both* the .dll file, and its |
| 77 | + # .lib, needs to be specified to CMake. The path to the .dll goes |
| 78 | + # into IMPORTED_LOCATION(_*), whereas the path to the .lib goes |
| 79 | + # into IMPORTED_IMPLIB(_*). |
| 80 | + set_target_properties(GraphicsMagick::GraphicsMagick PROPERTIES |
| 81 | + IMPORTED_LOCATION ${GRAPHICSMAGICK_DLL} |
| 82 | + IMPORTED_IMPLIB ${GRAPHICSMAGICK_LIBRARIES} |
| 83 | + ) |
| 84 | + else() |
| 85 | + set_target_properties(GraphicsMagick::GraphicsMagick PROPERTIES |
| 86 | + IMPORTED_LOCATION ${GRAPHICSMAGICK_LIBRARIES} |
| 87 | + ) |
| 88 | + endif() |
| 89 | +endif() |
0 commit comments