|
| 1 | +# This script locates the SFML library |
| 2 | +# ------------------------------------ |
| 3 | +# |
| 4 | +# Usage |
| 5 | +# ----- |
| 6 | +# |
| 7 | +# When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main). |
| 8 | +# If none is given, the SFML_LIBRARIES variable will be empty and you'll end up linking to nothing. |
| 9 | +# example: |
| 10 | +# find_package(SFML COMPONENTS graphics window system) // find the graphics, window and system modules |
| 11 | +# |
| 12 | +# You can enforce a specific version, either MAJOR.MINOR or only MAJOR. |
| 13 | +# If nothing is specified, the version won't be checked (i.e. any version will be accepted). |
| 14 | +# example: |
| 15 | +# find_package(SFML COMPONENTS ...) // no specific version required |
| 16 | +# find_package(SFML 2 COMPONENTS ...) // any 2.x version |
| 17 | +# find_package(SFML 2.4 COMPONENTS ...) // version 2.4 or greater |
| 18 | +# |
| 19 | +# By default, the dynamic libraries of SFML will be found. To find the static ones instead, |
| 20 | +# you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...). |
| 21 | +# Since you have to link yourself all the SFML dependencies when you link it statically, the following |
| 22 | +# additional variables are defined: SFML_XXX_DEPENDENCIES and SFML_DEPENDENCIES (see their detailed |
| 23 | +# description below). |
| 24 | +# In case of static linking, the SFML_STATIC macro will also be defined by this script. |
| 25 | +# example: |
| 26 | +# set(SFML_STATIC_LIBRARIES TRUE) |
| 27 | +# find_package(SFML 2 COMPONENTS network system) |
| 28 | +# |
| 29 | +# On Mac OS X if SFML_STATIC_LIBRARIES is not set to TRUE then by default CMake will search for frameworks unless |
| 30 | +# CMAKE_FIND_FRAMEWORK is set to "NEVER" for example. Please refer to CMake documentation for more details. |
| 31 | +# Moreover, keep in mind that SFML frameworks are only available as release libraries unlike dylibs which |
| 32 | +# are available for both release and debug modes. |
| 33 | +# |
| 34 | +# If SFML is not installed in a standard path, you can use the SFML_ROOT CMake (or environment) variable |
| 35 | +# to tell CMake where SFML is. |
| 36 | +# |
| 37 | +# Output |
| 38 | +# ------ |
| 39 | +# |
| 40 | +# This script defines the following variables: |
| 41 | +# - For each specified module XXX (system, window, graphics, network, audio, main): |
| 42 | +# - SFML_XXX_LIBRARY_DEBUG: the name of the debug library of the xxx module (set to SFML_XXX_LIBRARY_RELEASE is no debug version is found) |
| 43 | +# - SFML_XXX_LIBRARY_RELEASE: the name of the release library of the xxx module (set to SFML_XXX_LIBRARY_DEBUG is no release version is found) |
| 44 | +# - SFML_XXX_LIBRARY: the name of the library to link to for the xxx module (includes both debug and optimized names if necessary) |
| 45 | +# - SFML_XXX_FOUND: true if either the debug or release library of the xxx module is found |
| 46 | +# - SFML_XXX_DEPENDENCIES: the list of libraries the module depends on, in case of static linking |
| 47 | +# - SFML_LIBRARIES: the list of all libraries corresponding to the required modules |
| 48 | +# - SFML_FOUND: true if all the required modules are found |
| 49 | +# - SFML_INCLUDE_DIR: the path where SFML headers are located (the directory containing the SFML/Config.hpp file) |
| 50 | +# - SFML_DEPENDENCIES: the list of libraries SFML depends on, in case of static linking |
| 51 | +# |
| 52 | +# example: |
| 53 | +# find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED) |
| 54 | +# include_directories(${SFML_INCLUDE_DIR}) |
| 55 | +# add_executable(myapp ...) |
| 56 | +# target_link_libraries(myapp ${SFML_LIBRARIES}) |
| 57 | + |
| 58 | +# define the SFML_STATIC macro if static build was chosen |
| 59 | +if(SFML_STATIC_LIBRARIES) |
| 60 | + add_definitions(-DSFML_STATIC) |
| 61 | +endif() |
| 62 | + |
| 63 | +# define the list of search paths for headers and libraries |
| 64 | +set(FIND_SFML_PATHS |
| 65 | + ${SFML_ROOT} |
| 66 | + $ENV{SFML_ROOT} |
| 67 | + ~/Library/Frameworks |
| 68 | + /Library/Frameworks |
| 69 | + /usr/local |
| 70 | + /usr |
| 71 | + /sw |
| 72 | + /opt/local |
| 73 | + /opt/csw |
| 74 | + /opt) |
| 75 | + |
| 76 | +# find the SFML include directory |
| 77 | +find_path(SFML_INCLUDE_DIR SFML/Config.hpp |
| 78 | + PATH_SUFFIXES include |
| 79 | + PATHS ${FIND_SFML_PATHS}) |
| 80 | + |
| 81 | + |
| 82 | +if (NOT ${SFML_INCLUDE_DIR} STREQUAL "") |
| 83 | + get_filename_component(INCLUDE_PARENT_DIR ${SFML_INCLUDE_DIR} PATH) |
| 84 | + list(APPEND FIND_SFML_PATHS ${INCLUDE_PARENT_DIR}) |
| 85 | +endif() |
| 86 | + |
| 87 | +# check the version number |
| 88 | +set(SFML_VERSION_OK TRUE) |
| 89 | +if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR) |
| 90 | + # extract the major and minor version numbers from SFML/Config.hpp |
| 91 | + # we have to handle framework a little bit differently: |
| 92 | + if("${SFML_INCLUDE_DIR}" MATCHES "SFML.framework") |
| 93 | + set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/Headers/Config.hpp") |
| 94 | + else() |
| 95 | + set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp") |
| 96 | + endif() |
| 97 | + FILE(READ "${SFML_CONFIG_HPP_INPUT}" SFML_CONFIG_HPP_CONTENTS) |
| 98 | + STRING(REGEX MATCH ".*#define SFML_VERSION_MAJOR ([0-9]+).*#define SFML_VERSION_MINOR ([0-9]+).*#define SFML_VERSION_PATCH ([0-9]+).*" SFML_CONFIG_HPP_CONTENTS "${SFML_CONFIG_HPP_CONTENTS}") |
| 99 | + STRING(REGEX REPLACE ".*#define SFML_VERSION_MAJOR ([0-9]+).*" "\\1" SFML_VERSION_MAJOR "${SFML_CONFIG_HPP_CONTENTS}") |
| 100 | + STRING(REGEX REPLACE ".*#define SFML_VERSION_MINOR ([0-9]+).*" "\\1" SFML_VERSION_MINOR "${SFML_CONFIG_HPP_CONTENTS}") |
| 101 | + STRING(REGEX REPLACE ".*#define SFML_VERSION_PATCH ([0-9]+).*" "\\1" SFML_VERSION_PATCH "${SFML_CONFIG_HPP_CONTENTS}") |
| 102 | + math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10000 + ${SFML_FIND_VERSION_MINOR} * 100 + ${SFML_FIND_VERSION_PATCH}") |
| 103 | + |
| 104 | + # if we could extract them, compare with the requested version number |
| 105 | + if (SFML_VERSION_MAJOR) |
| 106 | + # transform version numbers to an integer |
| 107 | + math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10000 + ${SFML_VERSION_MINOR} * 100 + ${SFML_VERSION_PATCH}") |
| 108 | + |
| 109 | + # compare them |
| 110 | + if(SFML_VERSION LESS SFML_REQUESTED_VERSION) |
| 111 | + set(SFML_VERSION_OK FALSE) |
| 112 | + endif() |
| 113 | + else() |
| 114 | + # SFML version is < 2.0 |
| 115 | + if (SFML_REQUESTED_VERSION GREATER 10900) |
| 116 | + set(SFML_VERSION_OK FALSE) |
| 117 | + set(SFML_VERSION_MAJOR 1) |
| 118 | + set(SFML_VERSION_MINOR x) |
| 119 | + set(SFML_VERSION_PATCH x) |
| 120 | + endif() |
| 121 | + endif() |
| 122 | +endif() |
| 123 | + |
| 124 | +# find the requested modules |
| 125 | +set(SFML_FOUND TRUE) # will be set to false if one of the required modules is not found |
| 126 | +foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS}) |
| 127 | + string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER) |
| 128 | + string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER) |
| 129 | + set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER}) |
| 130 | + |
| 131 | + # no suffix for sfml-main, it is always a static library |
| 132 | + if(FIND_SFML_COMPONENT_LOWER STREQUAL "main") |
| 133 | + # release library |
| 134 | + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE |
| 135 | + NAMES ${FIND_SFML_COMPONENT_NAME} |
| 136 | + PATH_SUFFIXES lib64 lib |
| 137 | + PATHS ${FIND_SFML_PATHS}) |
| 138 | + |
| 139 | + # debug library |
| 140 | + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG |
| 141 | + NAMES ${FIND_SFML_COMPONENT_NAME}-d |
| 142 | + PATH_SUFFIXES lib64 lib |
| 143 | + PATHS ${FIND_SFML_PATHS}) |
| 144 | + else() |
| 145 | + # static release library |
| 146 | + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE |
| 147 | + NAMES ${FIND_SFML_COMPONENT_NAME}-s |
| 148 | + PATH_SUFFIXES lib64 lib |
| 149 | + PATHS ${FIND_SFML_PATHS}) |
| 150 | + |
| 151 | + # static debug library |
| 152 | + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG |
| 153 | + NAMES ${FIND_SFML_COMPONENT_NAME}-s-d |
| 154 | + PATH_SUFFIXES lib64 lib |
| 155 | + PATHS ${FIND_SFML_PATHS}) |
| 156 | + |
| 157 | + # dynamic release library |
| 158 | + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE |
| 159 | + NAMES ${FIND_SFML_COMPONENT_NAME} |
| 160 | + PATH_SUFFIXES lib64 lib |
| 161 | + PATHS ${FIND_SFML_PATHS}) |
| 162 | + |
| 163 | + # dynamic debug library |
| 164 | + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG |
| 165 | + NAMES ${FIND_SFML_COMPONENT_NAME}-d |
| 166 | + PATH_SUFFIXES lib64 lib |
| 167 | + PATHS ${FIND_SFML_PATHS}) |
| 168 | + |
| 169 | + # choose the entries that fit the requested link type |
| 170 | + if(SFML_STATIC_LIBRARIES) |
| 171 | + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE) |
| 172 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE}) |
| 173 | + endif() |
| 174 | + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG) |
| 175 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG}) |
| 176 | + endif() |
| 177 | + else() |
| 178 | + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE) |
| 179 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE}) |
| 180 | + endif() |
| 181 | + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG) |
| 182 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG}) |
| 183 | + endif() |
| 184 | + endif() |
| 185 | + endif() |
| 186 | + |
| 187 | + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG OR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE) |
| 188 | + # library found |
| 189 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND TRUE) |
| 190 | + |
| 191 | + # if both are found, set SFML_XXX_LIBRARY to contain both |
| 192 | + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE) |
| 193 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY debug ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG} |
| 194 | + optimized ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) |
| 195 | + endif() |
| 196 | + |
| 197 | + # if only one debug/release variant is found, set the other to be equal to the found one |
| 198 | + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE) |
| 199 | + # debug and not release |
| 200 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}) |
| 201 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}) |
| 202 | + endif() |
| 203 | + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG) |
| 204 | + # release and not debug |
| 205 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) |
| 206 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) |
| 207 | + endif() |
| 208 | + else() |
| 209 | + # library not found |
| 210 | + set(SFML_FOUND FALSE) |
| 211 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND FALSE) |
| 212 | + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY "") |
| 213 | + set(FIND_SFML_MISSING "${FIND_SFML_MISSING} SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY") |
| 214 | + endif() |
| 215 | + |
| 216 | + # mark as advanced |
| 217 | + MARK_AS_ADVANCED(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY |
| 218 | + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE |
| 219 | + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG |
| 220 | + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE |
| 221 | + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG |
| 222 | + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE |
| 223 | + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG) |
| 224 | + |
| 225 | + # add to the global list of libraries |
| 226 | + set(SFML_LIBRARIES ${SFML_LIBRARIES} "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}") |
| 227 | +endforeach() |
| 228 | + |
| 229 | +# in case of static linking, we must also define the list of all the dependencies of SFML libraries |
| 230 | +if(SFML_STATIC_LIBRARIES) |
| 231 | + |
| 232 | + # detect the OS |
| 233 | + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") |
| 234 | + set(FIND_SFML_OS_WINDOWS 1) |
| 235 | + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 236 | + set(FIND_SFML_OS_LINUX 1) |
| 237 | + elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 238 | + set(FIND_SFML_OS_FREEBSD 1) |
| 239 | + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 240 | + set(FIND_SFML_OS_MACOSX 1) |
| 241 | + endif() |
| 242 | + |
| 243 | + # start with an empty list |
| 244 | + set(SFML_DEPENDENCIES) |
| 245 | + set(FIND_SFML_DEPENDENCIES_NOTFOUND) |
| 246 | + |
| 247 | + # macro that searches for a 3rd-party library |
| 248 | + macro(find_sfml_dependency output friendlyname) |
| 249 | + # No lookup in environment variables (PATH on Windows), as they may contain wrong library versions |
| 250 | + find_library(${output} NAMES ${ARGN} PATHS ${FIND_SFML_PATHS} PATH_SUFFIXES lib NO_SYSTEM_ENVIRONMENT_PATH) |
| 251 | + if(${${output}} STREQUAL "${output}-NOTFOUND") |
| 252 | + unset(output) |
| 253 | + set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${friendlyname}") |
| 254 | + endif() |
| 255 | + endmacro() |
| 256 | + |
| 257 | + # sfml-system |
| 258 | + list(FIND SFML_FIND_COMPONENTS "system" FIND_SFML_SYSTEM_COMPONENT) |
| 259 | + if(NOT ${FIND_SFML_SYSTEM_COMPONENT} EQUAL -1) |
| 260 | + |
| 261 | + # update the list -- these are only system libraries, no need to find them |
| 262 | + if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD OR FIND_SFML_OS_MACOSX) |
| 263 | + set(SFML_SYSTEM_DEPENDENCIES "pthread") |
| 264 | + endif() |
| 265 | + if(FIND_SFML_OS_LINUX) |
| 266 | + set(SFML_SYSTEM_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} "rt") |
| 267 | + endif() |
| 268 | + if(FIND_SFML_OS_WINDOWS) |
| 269 | + set(SFML_SYSTEM_DEPENDENCIES "winmm") |
| 270 | + endif() |
| 271 | + set(SFML_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} ${SFML_DEPENDENCIES}) |
| 272 | + endif() |
| 273 | + |
| 274 | + # sfml-network |
| 275 | + list(FIND SFML_FIND_COMPONENTS "network" FIND_SFML_NETWORK_COMPONENT) |
| 276 | + if(NOT ${FIND_SFML_NETWORK_COMPONENT} EQUAL -1) |
| 277 | + |
| 278 | + # update the list -- these are only system libraries, no need to find them |
| 279 | + if(FIND_SFML_OS_WINDOWS) |
| 280 | + set(SFML_NETWORK_DEPENDENCIES "ws2_32") |
| 281 | + endif() |
| 282 | + set(SFML_DEPENDENCIES ${SFML_NETWORK_DEPENDENCIES} ${SFML_DEPENDENCIES}) |
| 283 | + endif() |
| 284 | + |
| 285 | + # sfml-window |
| 286 | + list(FIND SFML_FIND_COMPONENTS "window" FIND_SFML_WINDOW_COMPONENT) |
| 287 | + if(NOT ${FIND_SFML_WINDOW_COMPONENT} EQUAL -1) |
| 288 | + |
| 289 | + # find libraries |
| 290 | + if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD) |
| 291 | + find_sfml_dependency(X11_LIBRARY "X11" X11) |
| 292 | + find_sfml_dependency(LIBXCB_LIBRARIES "XCB" xcb libxcb) |
| 293 | + find_sfml_dependency(X11_XCB_LIBRARY "X11-xcb" X11-xcb libX11-xcb) |
| 294 | + find_sfml_dependency(XCB_RANDR_LIBRARY "xcb-randr" xcb-randr libxcb-randr) |
| 295 | + find_sfml_dependency(XCB_IMAGE_LIBRARY "xcb-image" xcb-image libxcb-image) |
| 296 | + endif() |
| 297 | + |
| 298 | + if(FIND_SFML_OS_LINUX) |
| 299 | + find_sfml_dependency(UDEV_LIBRARIES "UDev" udev libudev) |
| 300 | + endif() |
| 301 | + |
| 302 | + # update the list |
| 303 | + if(FIND_SFML_OS_WINDOWS) |
| 304 | + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32") |
| 305 | + elseif(FIND_SFML_OS_LINUX) |
| 306 | + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} ${UDEV_LIBRARIES}) |
| 307 | + elseif(FIND_SFML_OS_FREEBSD) |
| 308 | + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} "usbhid") |
| 309 | + elseif(FIND_SFML_OS_MACOSX) |
| 310 | + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon") |
| 311 | + endif() |
| 312 | + set(SFML_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} ${SFML_DEPENDENCIES}) |
| 313 | + endif() |
| 314 | + |
| 315 | + # sfml-graphics |
| 316 | + list(FIND SFML_FIND_COMPONENTS "graphics" FIND_SFML_GRAPHICS_COMPONENT) |
| 317 | + if(NOT ${FIND_SFML_GRAPHICS_COMPONENT} EQUAL -1) |
| 318 | + |
| 319 | + # find libraries |
| 320 | + find_sfml_dependency(FREETYPE_LIBRARY "FreeType" freetype) |
| 321 | + find_sfml_dependency(JPEG_LIBRARY "libjpeg" jpeg) |
| 322 | + |
| 323 | + # update the list |
| 324 | + set(SFML_GRAPHICS_DEPENDENCIES ${FREETYPE_LIBRARY} ${JPEG_LIBRARY}) |
| 325 | + set(SFML_DEPENDENCIES ${SFML_GRAPHICS_DEPENDENCIES} ${SFML_DEPENDENCIES}) |
| 326 | + endif() |
| 327 | + |
| 328 | + # sfml-audio |
| 329 | + list(FIND SFML_FIND_COMPONENTS "audio" FIND_SFML_AUDIO_COMPONENT) |
| 330 | + if(NOT ${FIND_SFML_AUDIO_COMPONENT} EQUAL -1) |
| 331 | + |
| 332 | + # find libraries |
| 333 | + find_sfml_dependency(OPENAL_LIBRARY "OpenAL" openal openal32) |
| 334 | + find_sfml_dependency(OGG_LIBRARY "Ogg" ogg) |
| 335 | + find_sfml_dependency(VORBIS_LIBRARY "Vorbis" vorbis) |
| 336 | + find_sfml_dependency(VORBISFILE_LIBRARY "VorbisFile" vorbisfile) |
| 337 | + find_sfml_dependency(VORBISENC_LIBRARY "VorbisEnc" vorbisenc) |
| 338 | + find_sfml_dependency(FLAC_LIBRARY "FLAC" flac) |
| 339 | + |
| 340 | + # update the list |
| 341 | + set(SFML_AUDIO_DEPENDENCIES ${OPENAL_LIBRARY} ${FLAC_LIBRARY} ${VORBISENC_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY}) |
| 342 | + set(SFML_DEPENDENCIES ${SFML_DEPENDENCIES} ${SFML_AUDIO_DEPENDENCIES}) |
| 343 | + endif() |
| 344 | + |
| 345 | +endif() |
| 346 | + |
| 347 | +# handle errors |
| 348 | +if(NOT SFML_VERSION_OK) |
| 349 | + # SFML version not ok |
| 350 | + set(FIND_SFML_ERROR "SFML found but version too low (requested: ${SFML_FIND_VERSION}, found: ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR}.${SFML_VERSION_PATCH})") |
| 351 | + set(SFML_FOUND FALSE) |
| 352 | +elseif(SFML_STATIC_LIBRARIES AND FIND_SFML_DEPENDENCIES_NOTFOUND) |
| 353 | + set(FIND_SFML_ERROR "SFML found but some of its dependencies are missing (${FIND_SFML_DEPENDENCIES_NOTFOUND})") |
| 354 | + set(SFML_FOUND FALSE) |
| 355 | +elseif(NOT SFML_FOUND) |
| 356 | + # include directory or library not found |
| 357 | + set(FIND_SFML_ERROR "Could NOT find SFML (missing: ${FIND_SFML_MISSING})") |
| 358 | +endif() |
| 359 | +if (NOT SFML_FOUND) |
| 360 | + if(SFML_FIND_REQUIRED) |
| 361 | + # fatal error |
| 362 | + message(FATAL_ERROR ${FIND_SFML_ERROR}) |
| 363 | + elseif(NOT SFML_FIND_QUIETLY) |
| 364 | + # error but continue |
| 365 | + message("${FIND_SFML_ERROR}") |
| 366 | + endif() |
| 367 | +endif() |
| 368 | + |
| 369 | +# handle success |
| 370 | +if(SFML_FOUND AND NOT SFML_FIND_QUIETLY) |
| 371 | + message(STATUS "Found SFML ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR}.${SFML_VERSION_PATCH} in ${SFML_INCLUDE_DIR}") |
| 372 | +endif() |
0 commit comments