| 1 |
#[=======================================================================[.rst: |
| 2 |
FindSDL2_image |
| 3 |
------- |
| 4 |
|
| 5 |
Finds the SDL2_image library. |
| 6 |
|
| 7 |
Imported Targets |
| 8 |
^^^^^^^^^^^^^^^^ |
| 9 |
|
| 10 |
This module provides either of the following imported targets, if found: |
| 11 |
|
| 12 |
``SDL2_image::SDL2_image`` |
| 13 |
The shared SDL2_image library |
| 14 |
``SDL2_image::SDL2_image-static`` |
| 15 |
The static SDL2_image library |
| 16 |
|
| 17 |
Result Variables |
| 18 |
^^^^^^^^^^^^^^^^ |
| 19 |
|
| 20 |
This will define the following variables: |
| 21 |
|
| 22 |
``SDL2_image_FOUND`` |
| 23 |
True if the system has the SDL2_image library. |
| 24 |
``SDL2_image_INCLUDE_DIRS`` |
| 25 |
Include directories needed to use SDL2_image. |
| 26 |
``SDL2_image_LIBRARIES`` |
| 27 |
Libraries needed to link to SDL2_image. |
| 28 |
``SDL2_image_DLL`` |
| 29 |
The path to the SDL2_image Windows runtime (any config). |
| 30 |
``SDL2_image_LIBRARY`` |
| 31 |
The path to the SDL2_image library (any config). |
| 32 |
|
| 33 |
Cache Variables |
| 34 |
^^^^^^^^^^^^^^^ |
| 35 |
|
| 36 |
The following cache variables may also be set: |
| 37 |
|
| 38 |
``SDL2_image_INCLUDE_DIR`` |
| 39 |
The directory containing ``SDL2_image.h``. |
| 40 |
``SDL2_image_DLL_RELEASE`` |
| 41 |
The path to the SDL2_image Windows runtime (release config). |
| 42 |
``SDL2_image_DLL_DEBUG`` |
| 43 |
The path to the SDL2_image Windows runtime (debug config). |
| 44 |
``SDL2_image_LIBRARY_RELEASE`` |
| 45 |
The path to the SDL2_image library (release config). |
| 46 |
``SDL2_image_LIBRARY_DEBUG`` |
| 47 |
The path to the SDL2_image library (debug config). |
| 48 |
|
| 49 |
#]=======================================================================] |
| 50 |
|
| 51 |
find_package(PkgConfig QUIET) |
| 52 |
pkg_check_modules(PC_SDL2_image IMPORTED_TARGET SDL2_image) |
| 53 |
|
| 54 |
if(PC_SDL2_image_FOUND) |
| 55 |
if(NOT TARGET SDL2_image::SDL2_image) |
| 56 |
add_library(SDL2_image::SDL2_image ALIAS PkgConfig::PC_SDL2_image) |
| 57 |
endif() |
| 58 |
set(SDL2_image_FOUND TRUE) |
| 59 |
set(SDL2_image_VERSION ${PC_SDL2_image_VERSION}) |
| 60 |
return() |
| 61 |
endif() |
| 62 |
|
| 63 |
find_path( |
| 64 |
SDL2_image_INCLUDE_DIR |
| 65 |
NAMES SDL_image.h |
| 66 |
PATH_SUFFIXES SDL2 |
| 67 |
) |
| 68 |
|
| 69 |
find_file( |
| 70 |
SDL2_image_DLL_RELEASE |
| 71 |
NAMES SDL2_image.dll |
| 72 |
PATH_SUFFIXES bin |
| 73 |
) |
| 74 |
|
| 75 |
find_file( |
| 76 |
SDL2_image_DLL_DEBUG |
| 77 |
NAMES SDL2_imaged.dll |
| 78 |
PATH_SUFFIXES bin |
| 79 |
) |
| 80 |
|
| 81 |
include(SelectDllConfigurations) |
| 82 |
select_dll_configurations(SDL2_image) |
| 83 |
|
| 84 |
find_library( |
| 85 |
SDL2_image_LIBRARY_RELEASE |
| 86 |
NAMES SDL2_image SDL2_image-static |
| 87 |
) |
| 88 |
|
| 89 |
find_library( |
| 90 |
SDL2_image_LIBRARY_DEBUG |
| 91 |
NAMES SDL2_imaged SDL2_image-staticd |
| 92 |
) |
| 93 |
|
| 94 |
include(SelectLibraryConfigurations) |
| 95 |
select_library_configurations(SDL2_image) |
| 96 |
|
| 97 |
if(SDL2_image_DLL OR SDL2_image_LIBRARY MATCHES ".so|.dylib") |
| 98 |
set(_sdl2_image_library_type SHARED) |
| 99 |
else() |
| 100 |
set(_sdl2_image_library_type STATIC) |
| 101 |
endif() |
| 102 |
|
| 103 |
if(_sdl2_image_library_type STREQUAL "STATIC") |
| 104 |
set(SDL2_image_LINK_LIBRARIES "" CACHE STRING "Additional libraries to link to SDL2_image.") |
| 105 |
set(SDL2_image_LINK_DIRECTORIES "" CACHE PATH "Additional directories to search libraries in for SDL2_image.") |
| 106 |
if(NOT SDL2_image_LINK_LIBRARIES) |
| 107 |
message(WARNING |
| 108 |
"pkg-config is unavailable and SDL2_image seems to be static, link failures are to be expected.\n" |
| 109 |
"Set `SDL2_image_LINK_LIBRARIES` to a list of libraries SDL2_image depends on.\n" |
| 110 |
"Set `SDL2_image_LINK_DIRECTORIES` to a list of directories to search for libraries in." |
| 111 |
) |
| 112 |
endif() |
| 113 |
endif() |
| 114 |
|
| 115 |
include(FindPackageHandleStandardArgs) |
| 116 |
find_package_handle_standard_args( |
| 117 |
SDL2_image |
| 118 |
REQUIRED_VARS "SDL2_image_LIBRARY" "SDL2_image_INCLUDE_DIR") |
| 119 |
|
| 120 |
if(SDL2_image_FOUND) |
| 121 |
if(_sdl2_image_library_type STREQUAL "SHARED") |
| 122 |
set(_sdl2_image_target_name SDL2_image::SDL2_image) |
| 123 |
else() |
| 124 |
set(_sdl2_image_target_name SDL2_image::SDL2_image-static) |
| 125 |
endif() |
| 126 |
if(NOT TARGET ${_sdl2_image_target_name}) |
| 127 |
add_library(${_sdl2_image_target_name} ${_sdl2_image_library_type} IMPORTED) |
| 128 |
set_target_properties( |
| 129 |
${_sdl2_image_target_name} |
| 130 |
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${SDL2_image_INCLUDE_DIR}" |
| 131 |
INTERFACE_LINK_LIBRARIES "${SDL2_image_LINK_LIBRARIES}" |
| 132 |
INTERFACE_LINK_DIRECTORIES "${SDL2_image_LINK_DIRECTORIES}" |
| 133 |
) |
| 134 |
endif() |
| 135 |
|
| 136 |
if(SDL2_image_DLL) |
| 137 |
set_target_properties( |
| 138 |
${_sdl2_image_target_name} |
| 139 |
PROPERTIES IMPORTED_LOCATION "${SDL2_image_DLL}" |
| 140 |
IMPORTED_IMPLIB "${SDL2_image_LIBRARY}" |
| 141 |
) |
| 142 |
else() |
| 143 |
set_target_properties( |
| 144 |
${_sdl2_image_target_name} |
| 145 |
PROPERTIES IMPORTED_LOCATION "${SDL2_image_LIBRARY}" |
| 146 |
) |
| 147 |
endif() |
| 148 |
|
| 149 |
if(SDL2_image_LIBRARY_RELEASE) |
| 150 |
set_property( |
| 151 |
TARGET ${_sdl2_image_target_name} |
| 152 |
APPEND |
| 153 |
PROPERTY IMPORTED_CONFIGURATIONS RELEASE |
| 154 |
) |
| 155 |
if(SDL2_image_DLL_RELEASE) |
| 156 |
set_target_properties( |
| 157 |
${_sdl2_image_target_name} |
| 158 |
PROPERTIES IMPORTED_LOCATION_RELEASE "${SDL2_image_DLL_RELEASE}" |
| 159 |
IMPORTED_IMPLIB_RELEASE "${SDL2_image_LIBRARY_RELEASE}" |
| 160 |
) |
| 161 |
else() |
| 162 |
set_target_properties( |
| 163 |
${_sdl2_image_target_name} |
| 164 |
PROPERTIES IMPORTED_LOCATION_RELEASE "${SDL2_image_LIBRARY_RELEASE}" |
| 165 |
) |
| 166 |
endif() |
| 167 |
endif() |
| 168 |
if(SDL2_image_LIBRARY_DEBUG) |
| 169 |
set_property( |
| 170 |
TARGET ${_sdl2_image_target_name} |
| 171 |
APPEND |
| 172 |
PROPERTY IMPORTED_CONFIGURATIONS DEBUG |
| 173 |
) |
| 174 |
if(SDL2_image_DLL_DEBUG) |
| 175 |
set_target_properties( |
| 176 |
${_sdl2_image_target_name} |
| 177 |
PROPERTIES IMPORTED_LOCATION_DEBUG "${SDL2_image_DLL_DEBUG}" |
| 178 |
IMPORTED_IMPLIB_DEBUG "${SDL2_image_LIBRARY_DEBUG}" |
| 179 |
) |
| 180 |
else() |
| 181 |
set_target_properties( |
| 182 |
${_sdl2_image_target_name} |
| 183 |
PROPERTIES IMPORTED_LOCATION_DEBUG "${SDL2_image_LIBRARY_DEBUG}" |
| 184 |
) |
| 185 |
endif() |
| 186 |
endif() |
| 187 |
|
| 188 |
set(SDL2_image_LIBRARIES ${_sdl2_image_target_name}) |
| 189 |
set(SDL2_image_INCLUDE_DIRS "${SDL2_image_INCLUDE_DIR}") |
| 190 |
endif() |
| 191 |
|
| 192 |
mark_as_advanced( |
| 193 |
SDL2_image_INCLUDE_DIR |
| 194 |
) |