├── FindSDL2.cmake ├── FindSDL2_image.cmake ├── FindSDL2_mixer.cmake ├── FindSDL2_ttf.cmake └── readme.md /FindSDL2.cmake: -------------------------------------------------------------------------------- 1 | 2 | # This module defines 3 | # SDL2_LIBRARY, the name of the library to link against 4 | # SDL2_FOUND, if false, do not try to link to SDL2 5 | # SDL2_INCLUDE_DIR, where to find SDL.h 6 | # 7 | # This module responds to the the flag: 8 | # SDL2_BUILDING_LIBRARY 9 | # If this is defined, then no SDL2main will be linked in because 10 | # only applications need main(). 11 | # Otherwise, it is assumed you are building an application and this 12 | # module will attempt to locate and set the the proper link flags 13 | # as part of the returned SDL2_LIBRARY variable. 14 | # 15 | # Don't forget to include SDLmain.h and SDLmain.m your project for the 16 | # OS X framework based version. (Other versions link to -lSDL2main which 17 | # this module will try to find on your behalf.) Also for OS X, this 18 | # module will automatically add the -framework Cocoa on your behalf. 19 | # 20 | # 21 | # Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration 22 | # and no SDL2_LIBRARY, it means CMake did not find your SDL2 library 23 | # (SDL2.dll, libsdl2.so, SDL2.framework, etc). 24 | # Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. 25 | # Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value 26 | # as appropriate. These values are used to generate the final SDL2_LIBRARY 27 | # variable, but when these values are unset, SDL2_LIBRARY does not get created. 28 | # 29 | # 30 | # $SDL2DIR is an environment variable that would 31 | # correspond to the ./configure --prefix=$SDL2DIR 32 | # used in building SDL2. 33 | # l.e.galup 9-20-02 34 | # 35 | # Modified by Eric Wing. 36 | # Added code to assist with automated building by using environmental variables 37 | # and providing a more controlled/consistent search behavior. 38 | # Added new modifications to recognize OS X frameworks and 39 | # additional Unix paths (FreeBSD, etc). 40 | # Also corrected the header search path to follow "proper" SDL guidelines. 41 | # Added a search for SDL2main which is needed by some platforms. 42 | # Added a search for threads which is needed by some platforms. 43 | # Added needed compile switches for MinGW. 44 | # 45 | # On OSX, this will prefer the Framework version (if found) over others. 46 | # People will have to manually change the cache values of 47 | # SDL2_LIBRARY to override this selection or set the CMake environment 48 | # CMAKE_INCLUDE_PATH to modify the search paths. 49 | # 50 | # Note that the header path has changed from SDL2/SDL.h to just SDL.h 51 | # This needed to change because "proper" SDL convention 52 | # is #include "SDL.h", not . This is done for portability 53 | # reasons because not all systems place things in SDL2/ (see FreeBSD). 54 | 55 | #============================================================================= 56 | # Copyright 2003-2009 Kitware, Inc. 57 | # 58 | # Distributed under the OSI-approved BSD License (the "License"); 59 | # see accompanying file Copyright.txt for details. 60 | # 61 | # This software is distributed WITHOUT ANY WARRANTY; without even the 62 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 63 | # See the License for more information. 64 | #============================================================================= 65 | # (To distribute this file outside of CMake, substitute the full 66 | # License text for the above reference.) 67 | 68 | # message("") 69 | 70 | SET(SDL2_SEARCH_PATHS 71 | ~/Library/Frameworks 72 | /Library/Frameworks 73 | /usr/local 74 | /usr 75 | /sw # Fink 76 | /opt/local # DarwinPorts 77 | /opt/csw # Blastwave 78 | /opt 79 | ${SDL2_PATH} 80 | ) 81 | 82 | FIND_PATH(SDL2_INCLUDE_DIR SDL.h 83 | HINTS 84 | $ENV{SDL2DIR} 85 | PATH_SUFFIXES include/SDL2 include 86 | PATHS ${SDL2_SEARCH_PATHS} 87 | ) 88 | 89 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 90 | set(PATH_SUFFIXES lib64 lib/x64 lib) 91 | else() 92 | set(PATH_SUFFIXES lib/x86 lib) 93 | endif() 94 | 95 | FIND_LIBRARY(SDL2_LIBRARY_TEMP 96 | NAMES SDL2 97 | HINTS 98 | $ENV{SDL2DIR} 99 | PATH_SUFFIXES ${PATH_SUFFIXES} 100 | PATHS ${SDL2_SEARCH_PATHS} 101 | ) 102 | 103 | IF(NOT SDL2_BUILDING_LIBRARY) 104 | IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") 105 | # Non-OS X framework versions expect you to also dynamically link to 106 | # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms 107 | # seem to provide SDL2main for compatibility even though they don't 108 | # necessarily need it. 109 | FIND_LIBRARY(SDL2MAIN_LIBRARY 110 | NAMES SDL2main 111 | HINTS 112 | $ENV{SDL2DIR} 113 | PATH_SUFFIXES ${PATH_SUFFIXES} 114 | PATHS ${SDL2_SEARCH_PATHS} 115 | ) 116 | ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") 117 | ENDIF(NOT SDL2_BUILDING_LIBRARY) 118 | 119 | # SDL2 may require threads on your system. 120 | # The Apple build may not need an explicit flag because one of the 121 | # frameworks may already provide it. 122 | # But for non-OSX systems, I will use the CMake Threads package. 123 | IF(NOT APPLE) 124 | FIND_PACKAGE(Threads) 125 | ENDIF(NOT APPLE) 126 | 127 | # MinGW needs an additional link flag, -mwindows 128 | # It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows 129 | IF(MINGW) 130 | SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW") 131 | ENDIF(MINGW) 132 | 133 | IF(SDL2_LIBRARY_TEMP) 134 | # For SDL2main 135 | IF(NOT SDL2_BUILDING_LIBRARY) 136 | IF(SDL2MAIN_LIBRARY) 137 | SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) 138 | ENDIF(SDL2MAIN_LIBRARY) 139 | ENDIF(NOT SDL2_BUILDING_LIBRARY) 140 | 141 | # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. 142 | # CMake doesn't display the -framework Cocoa string in the UI even 143 | # though it actually is there if I modify a pre-used variable. 144 | # I think it has something to do with the CACHE STRING. 145 | # So I use a temporary variable until the end so I can set the 146 | # "real" variable in one-shot. 147 | IF(APPLE) 148 | SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") 149 | ENDIF(APPLE) 150 | 151 | # For threads, as mentioned Apple doesn't need this. 152 | # In fact, there seems to be a problem if I used the Threads package 153 | # and try using this line, so I'm just skipping it entirely for OS X. 154 | IF(NOT APPLE) 155 | SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) 156 | ENDIF(NOT APPLE) 157 | 158 | # For MinGW library 159 | IF(MINGW) 160 | SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) 161 | ENDIF(MINGW) 162 | 163 | # Set the final string here so the GUI reflects the final state. 164 | SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") 165 | # Set the temp variable to INTERNAL so it is not seen in the CMake GUI 166 | SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") 167 | ENDIF(SDL2_LIBRARY_TEMP) 168 | 169 | # message("") 170 | 171 | INCLUDE(FindPackageHandleStandardArgs) 172 | 173 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) 174 | -------------------------------------------------------------------------------- /FindSDL2_image.cmake: -------------------------------------------------------------------------------- 1 | # Locate SDL_image library 2 | # 3 | # This module defines: 4 | # 5 | # :: 6 | # 7 | # SDL2_IMAGE_LIBRARIES, the name of the library to link against 8 | # SDL2_IMAGE_INCLUDE_DIRS, where to find the headers 9 | # SDL2_IMAGE_FOUND, if false, do not try to link against 10 | # SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image 11 | # 12 | # 13 | # 14 | # For backward compatibility the following variables are also set: 15 | # 16 | # :: 17 | # 18 | # SDLIMAGE_LIBRARY (same value as SDL2_IMAGE_LIBRARIES) 19 | # SDLIMAGE_INCLUDE_DIR (same value as SDL2_IMAGE_INCLUDE_DIRS) 20 | # SDLIMAGE_FOUND (same value as SDL2_IMAGE_FOUND) 21 | # 22 | # 23 | # 24 | # $SDLDIR is an environment variable that would correspond to the 25 | # ./configure --prefix=$SDLDIR used in building SDL. 26 | # 27 | # Created by Eric Wing. This was influenced by the FindSDL.cmake 28 | # module, but with modifications to recognize OS X frameworks and 29 | # additional Unix paths (FreeBSD, etc). 30 | 31 | #============================================================================= 32 | # Copyright 2005-2009 Kitware, Inc. 33 | # Copyright 2012 Benjamin Eikel 34 | # 35 | # Distributed under the OSI-approved BSD License (the "License"); 36 | # see accompanying file Copyright.txt for details. 37 | # 38 | # This software is distributed WITHOUT ANY WARRANTY; without even the 39 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 40 | # See the License for more information. 41 | #============================================================================= 42 | # (To distribute this file outside of CMake, substitute the full 43 | # License text for the above reference.) 44 | 45 | find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h 46 | HINTS 47 | ENV SDL2IMAGEDIR 48 | ENV SDL2DIR 49 | PATH_SUFFIXES SDL2 50 | # path suffixes to search inside ENV{SDLDIR} 51 | include/SDL2 include 52 | PATHS ${SDL2_IMAGE_PATH} 53 | ) 54 | 55 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 56 | set(VC_LIB_PATH_SUFFIX lib/x64) 57 | else() 58 | set(VC_LIB_PATH_SUFFIX lib/x86) 59 | endif() 60 | 61 | find_library(SDL2_IMAGE_LIBRARY 62 | NAMES SDL2_image 63 | HINTS 64 | ENV SDL2IMAGEDIR 65 | ENV SDL2DIR 66 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 67 | PATHS ${SDL2_IMAGE_PATH} 68 | ) 69 | 70 | if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") 71 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") 72 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") 73 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") 74 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") 75 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") 76 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") 77 | set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) 78 | unset(SDL2_IMAGE_VERSION_MAJOR_LINE) 79 | unset(SDL2_IMAGE_VERSION_MINOR_LINE) 80 | unset(SDL2_IMAGE_VERSION_PATCH_LINE) 81 | unset(SDL2_IMAGE_VERSION_MAJOR) 82 | unset(SDL2_IMAGE_VERSION_MINOR) 83 | unset(SDL2_IMAGE_VERSION_PATCH) 84 | endif() 85 | 86 | set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) 87 | set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) 88 | 89 | include(FindPackageHandleStandardArgs) 90 | 91 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image 92 | REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS 93 | VERSION_VAR SDL2_IMAGE_VERSION_STRING) 94 | 95 | # for backward compatibility 96 | set(SDLIMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES}) 97 | set(SDLIMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS}) 98 | set(SDLIMAGE_FOUND ${SDL2_IMAGE_FOUND}) 99 | 100 | mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) 101 | -------------------------------------------------------------------------------- /FindSDL2_mixer.cmake: -------------------------------------------------------------------------------- 1 | # Locate SDL_MIXER library 2 | # 3 | # This module defines: 4 | # 5 | # :: 6 | # 7 | # SDL2_MIXER_LIBRARIES, the name of the library to link against 8 | # SDL2_MIXER_INCLUDE_DIRS, where to find the headers 9 | # SDL2_MIXER_FOUND, if false, do not try to link against 10 | # SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL_MIXER 11 | # 12 | # 13 | # 14 | # For backward compatibility the following variables are also set: 15 | # 16 | # :: 17 | # 18 | # SDLMIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES) 19 | # SDLMIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS) 20 | # SDLMIXER_FOUND (same value as SDL2_MIXER_FOUND) 21 | # 22 | # 23 | # 24 | # $SDLDIR is an environment variable that would correspond to the 25 | # ./configure --prefix=$SDLDIR used in building SDL. 26 | # 27 | # Created by Eric Wing. This was influenced by the FindSDL.cmake 28 | # module, but with modifications to recognize OS X frameworks and 29 | # additional Unix paths (FreeBSD, etc). 30 | 31 | #============================================================================= 32 | # Copyright 2005-2009 Kitware, Inc. 33 | # Copyright 2012 Benjamin Eikel 34 | # 35 | # Distributed under the OSI-approved BSD License (the "License"); 36 | # see accompanying file Copyright.txt for details. 37 | # 38 | # This software is distributed WITHOUT ANY WARRANTY; without even the 39 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 40 | # See the License for more information. 41 | #============================================================================= 42 | # (To distribute this file outside of CMake, substitute the full 43 | # License text for the above reference.) 44 | 45 | find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h 46 | HINTS 47 | ENV SDL2MIXERDIR 48 | ENV SDL2DIR 49 | PATH_SUFFIXES SDL2 50 | # path suffixes to search inside ENV{SDLDIR} 51 | include/SDL2 include 52 | PATHS ${SDL2_MIXER_PATH} 53 | ) 54 | 55 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 56 | set(VC_LIB_PATH_SUFFIX lib/x64) 57 | else() 58 | set(VC_LIB_PATH_SUFFIX lib/x86) 59 | endif() 60 | 61 | find_library(SDL2_MIXER_LIBRARY 62 | NAMES SDL2_mixer 63 | HINTS 64 | ENV SDL2MIXERDIR 65 | ENV SDL2DIR 66 | PATH_SUFFIXES lib bin ${VC_LIB_PATH_SUFFIX} 67 | PATHS ${SDL2_MIXER_PATH} 68 | ) 69 | 70 | if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") 71 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") 72 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") 73 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") 74 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") 75 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") 76 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") 77 | set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) 78 | unset(SDL2_MIXER_VERSION_MAJOR_LINE) 79 | unset(SDL2_MIXER_VERSION_MINOR_LINE) 80 | unset(SDL2_MIXER_VERSION_PATCH_LINE) 81 | unset(SDL2_MIXER_VERSION_MAJOR) 82 | unset(SDL2_MIXER_VERSION_MINOR) 83 | unset(SDL2_MIXER_VERSION_PATCH) 84 | endif() 85 | 86 | set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) 87 | set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) 88 | 89 | include(FindPackageHandleStandardArgs) 90 | 91 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer 92 | REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS 93 | VERSION_VAR SDL2_MIXER_VERSION_STRING) 94 | 95 | # for backward compatibility 96 | set(SDLMIXER_LIBRARY ${SDL2_MIXER_LIBRARIES}) 97 | set(SDLMIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS}) 98 | set(SDLMIXER_FOUND ${SDL2_MIXER_FOUND}) 99 | 100 | mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) 101 | -------------------------------------------------------------------------------- /FindSDL2_ttf.cmake: -------------------------------------------------------------------------------- 1 | # Locate SDL_ttf library 2 | # 3 | # This module defines: 4 | # 5 | # :: 6 | # 7 | # SDL2_TTF_LIBRARIES, the name of the library to link against 8 | # SDL2_TTF_INCLUDE_DIRS, where to find the headers 9 | # SDL2_TTF_FOUND, if false, do not try to link against 10 | # SDL2_TTF_VERSION_STRING - human-readable string containing the version of SDL_ttf 11 | # 12 | # 13 | # 14 | # For backward compatibility the following variables are also set: 15 | # 16 | # :: 17 | # 18 | # SDLTTF_LIBRARY (same value as SDL2_TTF_LIBRARIES) 19 | # SDLTTF_INCLUDE_DIR (same value as SDL2_TTF_INCLUDE_DIRS) 20 | # SDLTTF_FOUND (same value as SDL2_TTF_FOUND) 21 | # 22 | # 23 | # 24 | # $SDLDIR is an environment variable that would correspond to the 25 | # ./configure --prefix=$SDLDIR used in building SDL. 26 | # 27 | # Created by Eric Wing. This was influenced by the FindSDL.cmake 28 | # module, but with modifications to recognize OS X frameworks and 29 | # additional Unix paths (FreeBSD, etc). 30 | 31 | #============================================================================= 32 | # Copyright 2005-2009 Kitware, Inc. 33 | # Copyright 2012 Benjamin Eikel 34 | # 35 | # Distributed under the OSI-approved BSD License (the "License"); 36 | # see accompanying file Copyright.txt for details. 37 | # 38 | # This software is distributed WITHOUT ANY WARRANTY; without even the 39 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 40 | # See the License for more information. 41 | #============================================================================= 42 | # (To distribute this file outside of CMake, substitute the full 43 | # License text for the above reference.) 44 | 45 | find_path(SDL2_TTF_INCLUDE_DIR SDL_ttf.h 46 | HINTS 47 | ENV SDL2TTFDIR 48 | ENV SDL2DIR 49 | PATH_SUFFIXES SDL2 50 | # path suffixes to search inside ENV{SDLDIR} 51 | include/SDL2 include 52 | PATHS ${SDL2_TTF_PATH} 53 | ) 54 | 55 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) 56 | set(VC_LIB_PATH_SUFFIX lib/x64) 57 | else () 58 | set(VC_LIB_PATH_SUFFIX lib/x86) 59 | endif () 60 | 61 | find_library(SDL2_TTF_LIBRARY 62 | NAMES SDL2_ttf 63 | HINTS 64 | ENV SDL2TTFDIR 65 | ENV SDL2DIR 66 | PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} 67 | PATHS ${SDL2_TTF_PATH} 68 | ) 69 | 70 | if (SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") 71 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") 72 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$") 73 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$") 74 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}") 75 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}") 76 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}") 77 | set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH}) 78 | unset(SDL2_TTF_VERSION_MAJOR_LINE) 79 | unset(SDL2_TTF_VERSION_MINOR_LINE) 80 | unset(SDL2_TTF_VERSION_PATCH_LINE) 81 | unset(SDL2_TTF_VERSION_MAJOR) 82 | unset(SDL2_TTF_VERSION_MINOR) 83 | unset(SDL2_TTF_VERSION_PATCH) 84 | endif () 85 | 86 | set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) 87 | set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR}) 88 | 89 | include(FindPackageHandleStandardArgs) 90 | 91 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf 92 | REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS 93 | VERSION_VAR SDL2_TTF_VERSION_STRING) 94 | 95 | # for backward compatibility 96 | set(SDLTTF_LIBRARY ${SDL2_TTF_LIBRARIES}) 97 | set(SDLTTF_INCLUDE_DIR ${SDL2_TTF_INCLUDE_DIRS}) 98 | set(SDLTTF_FOUND ${SDL2_TTF_FOUND}) 99 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | This repository contains CMake scripts for finding the `SDL2`, `SDL2_image` and 3 | `SDL2_ttf` libraries and headers. 4 | 5 | CMake itself comes with corresponding scripts for SDL 1.2, which hopefully in 6 | time will be updated for SDL2 and make this repo redundant. In the mean 7 | time, I'm putting them up here in case anyone else finds them useful. 8 | 9 | I've tested them on Linux and Mac OS using the Makefile and XCode targets. 10 | On Linux, you'll need the SDL2 development packages installed from your distro 11 | package manager. On Mac OS you can install the development frameworks 12 | from the SDL website or alternatively, if you use Homebrew you can run 13 | `brew install sdl2` to install the development packages. 14 | 15 | ## Usage 16 | 17 | ### General 18 | 19 | In order to use these scripts, you first need to tell CMake where to find them, via 20 | the `CMAKE_MODULE_PATH` variable. For example, if you put them in a 21 | subdirectory called `cmake`, then in your root `CMakeLists.txt` add the line 22 | 23 | ```cmake 24 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${project_SOURCE_DIR}/cmake") 25 | ``` 26 | 27 | where `project` is the name of your project. You can then use the packages 28 | themselves by adding 29 | 30 | ```cmake 31 | find_package(SDL2 REQUIRED) 32 | find_package(SDL2_image REQUIRED) 33 | find_package(SDL2_ttf REQUIRED) 34 | 35 | include_directories(${SDL2_INCLUDE_DIR} 36 | ${SDL2_IMAGE_INCLUDE_DIR} 37 | ${SDL2_TTF_INCLUDE_DIR}) 38 | target_link_libraries(target ${SDL2_LIBRARY} 39 | ${SDL2_IMAGE_LIBRARIES} 40 | ${SDL2_TTF_LIBRARIES}) 41 | 42 | ``` 43 | 44 | or whatever is appropriate for your project. 45 | 46 | ### mingw32 / msys 47 | 48 | This section supplements ```Usage -> General``` section. You still are required 49 | to incorporate ```General``` configuration settings in you CMakeLists.txt. 50 | 51 | Because cmake binaries for windows aren't aware of *nix/win paths conversion, 52 | default paths FindSDL2 will look in won't do any good. For that you should set SDL2_PATH variable. 53 | For example: 54 | ```cmake 55 | set(SDL2_PATH "D:\\apps\\SDL2\\i686-w64-mingw32") 56 | ``` 57 | 58 | ```bash 59 | mkdir build 60 | cd build 61 | cmake .. -G"MSYS Makefiles" 62 | make 63 | ``` 64 | 65 | 66 | ## Licence 67 | 68 | I am not the original author of these scripts. I found `FindSDL2.cmake` 69 | after some Googling, and hacked up the `image` and `ttf` scripts from the 70 | SDL1 versions that come with CMake. The original scripts, and my changes, 71 | are released under the two-clause BSD licence. 72 | 73 | ## Bugs 74 | 75 | These scripts are provided in the hope that you might find them useful. They 76 | work for me and hopefully they'll work for you too. If you fix any 77 | issues with them then I'd appreciate a pull request so other 78 | users can get your fixes too, but that's up to you :-). 79 | 80 | 81 | --------------------------------------------------------------------------------