├── FindSDL2.cmake ├── FindSDL2_gfx.cmake ├── FindSDL2_image.cmake ├── FindSDL2_mixer.cmake ├── FindSDL2_net.cmake ├── FindSDL2_ttf.cmake ├── LICENSE.md └── README.md /FindSDL2.cmake: -------------------------------------------------------------------------------- 1 | # Licensed under the ISC license. Please see the LICENSE.md file for details. 2 | # Copyright (c) 2019 Sandro Stikić 3 | 4 | #[[============================================================================ 5 | FindSDL2 6 | --------- 7 | 8 | Try to find SDL2. 9 | 10 | This module defines the following IMPORTED targets: 11 | - SDL2::Core — Libraries should link against this. 12 | - SDL2::SDL2 — Applications should link against this instead of SDL2::Core. 13 | 14 | This module defines the following variables: 15 | - SDL2_FOUND 16 | - SDL2main_FOUND 17 | - SDL2_VERSION_STRING 18 | - SDL2_LIBRARIES (deprecated) 19 | - SDL2_INCLUDE_DIRS (deprecated) 20 | #============================================================================]] 21 | 22 | # Look for SDL2. 23 | find_path(SDL2_INCLUDE_DIR SDL.h 24 | PATH_SUFFIXES SDL2 include/SDL2 include 25 | PATHS ${SDL2_PATH} 26 | ) 27 | 28 | if (NOT SDL2_LIBRARIES) 29 | # Determine architecture. 30 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 31 | set(_SDL2_PATH_SUFFIX lib/x64) 32 | else() 33 | set(_SDL2_PATH_SUFFIX lib/x86) 34 | endif() 35 | 36 | # Look for the release version of SDL2. 37 | find_library(SDL2_LIBRARY_RELEASE 38 | NAMES SDL2 SDL-2.0 39 | PATH_SUFFIXES lib ${_SDL2_PATH_SUFFIX} 40 | PATHS ${SDL2_PATH} 41 | ) 42 | 43 | # Look for the debug version of SDL2. 44 | find_library(SDL2_LIBRARY_DEBUG 45 | NAMES SDL2d 46 | PATH_SUFFIXES lib ${_SDL2_PATH_SUFFIX} 47 | PATHS ${SDL2_PATH} 48 | ) 49 | 50 | # Look for SDL2main. 51 | find_library(SDL2main_LIBRARIES 52 | NAMES SDL2main 53 | PATH_SUFFIXES lib ${_SDL2_PATH_SUFFIX} 54 | PATHS ${SDL2_PATH} 55 | ) 56 | 57 | include(SelectLibraryConfigurations) 58 | select_library_configurations(SDL2) 59 | endif() 60 | 61 | # Find the SDL2 version. 62 | if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") 63 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") 64 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") 65 | file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") 66 | string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") 67 | string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") 68 | string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") 69 | set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}) 70 | unset(SDL2_VERSION_MAJOR_LINE) 71 | unset(SDL2_VERSION_MINOR_LINE) 72 | unset(SDL2_VERSION_PATCH_LINE) 73 | unset(SDL2_VERSION_MAJOR) 74 | unset(SDL2_VERSION_MINOR) 75 | unset(SDL2_VERSION_PATCH) 76 | endif() 77 | 78 | include(FindPackageHandleStandardArgs) 79 | find_package_handle_standard_args(SDL2 80 | REQUIRED_VARS SDL2_LIBRARIES SDL2_INCLUDE_DIR 81 | VERSION_VAR SDL2_VERSION_STRING) 82 | 83 | find_package_handle_standard_args(SDL2main 84 | REQUIRED_VARS SDL2main_LIBRARIES SDL2_INCLUDE_DIR 85 | VERSION_VAR SDL2_VERSION_STRING 86 | NAME_MISMATCHED) 87 | 88 | if(SDL2_FOUND) 89 | set(SDL2_LIBRARIES ${SDL2_LIBRARY}) 90 | set(SDL2_INCLUDE_DIR ${SDL2_INCLUDE_DIR}) 91 | 92 | # Define the core SDL2 target. 93 | if(NOT TARGET SDL2::Core) 94 | add_library(SDL2::Core UNKNOWN IMPORTED) 95 | set_target_properties(SDL2::Core PROPERTIES 96 | INTERFACE_INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}) 97 | 98 | # Link against Cocoa on macOS. 99 | if(APPLE) 100 | set_property(TARGET SDL2::Core APPEND PROPERTY 101 | INTERFACE_LINK_OPTIONS -framework Cocoa) 102 | endif() 103 | 104 | if(SDL2_LIBRARY_RELEASE) 105 | set_property(TARGET SDL2::Core APPEND PROPERTY 106 | IMPORTED_CONFIGURATIONS RELEASE) 107 | set_target_properties(SDL2::Core PROPERTIES 108 | IMPORTED_LOCATION_RELEASE ${SDL2_LIBRARY_RELEASE}) 109 | endif() 110 | 111 | if(SDL2_LIBRARY_DEBUG) 112 | set_property(TARGET SDL2::Core APPEND PROPERTY 113 | IMPORTED_CONFIGURATIONS DEBUG) 114 | set_target_properties(SDL2::Core PROPERTIES 115 | IMPORTED_LOCATION_DEBUG ${SDL2_LIBRARY_DEBUG}) 116 | endif() 117 | 118 | if(NOT SDL2_LIBRARY_RELEASE AND NOT SDL2_LIBRARY_DEBUG) 119 | set_property(TARGET SDL2::Core APPEND PROPERTY 120 | IMPORTED_LOCATION ${SDL2_LIBRARY}) 121 | endif() 122 | endif() 123 | 124 | # Define the SDL2 target. 125 | if(NOT TARGET SDL2::SDL2) 126 | add_library(SDL2::SDL2 UNKNOWN IMPORTED) 127 | set_target_properties(SDL2::SDL2 PROPERTIES 128 | INTERFACE_LINK_LIBRARIES SDL2::Core 129 | IMPORTED_LOCATION ${SDL2main_LIBRARIES}) 130 | endif() 131 | endif() 132 | -------------------------------------------------------------------------------- /FindSDL2_gfx.cmake: -------------------------------------------------------------------------------- 1 | # Licensed under the ISC license. Please see the LICENSE.md file for details. 2 | # Copyright (c) 2019 Sandro Stikić 3 | 4 | #[[============================================================================ 5 | FindSDL2 6 | --------- 7 | 8 | Try to find SDL2_gfx. 9 | 10 | This module defines the following IMPORTED targets: 11 | - SDL2::Gfx — Link against this. 12 | 13 | This module defines the following variables: 14 | - SDL2_GFX_FOUND 15 | - SDL2_GFX_VERSION_STRING 16 | - SDL2_GFX_LIBRARIES (deprecated) 17 | - SDL2_GFX_INCLUDE_DIRS (deprecated) 18 | #============================================================================]] 19 | 20 | # Ensure SDL2 is installed. 21 | find_package(SDL2 REQUIRED QUIET) 22 | 23 | if(NOT SDL2_FOUND) 24 | message(FATAL_ERROR "SDL2 not found") 25 | endif() 26 | 27 | # Look for SDL2_gfx. 28 | find_path(SDL2_GFX_INCLUDE_DIR SDL2_gfxPrimitives.h 29 | PATH_SUFFIXES SDL2 include/SDL2 include 30 | PATHS ${SDL2_GFX_PATH} 31 | ) 32 | 33 | if (NOT SDL2_GFX_LIBRARIES) 34 | # Determine architecture. 35 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 36 | set(_SDL2_GFX_PATH_SUFFIX lib/x64) 37 | else() 38 | set(_SDL2_GFX_PATH_SUFFIX lib/x86) 39 | endif() 40 | 41 | # Look for the release version of SDL2. 42 | find_library(SDL2_GFX_LIBRARY_RELEASE 43 | NAMES SDL2_gfx 44 | PATH_SUFFIXES lib ${_SDL2_GFX_PATH_SUFFIX} 45 | PATHS ${SDL2_GFX_PATH} 46 | ) 47 | 48 | # Look for the debug version of SDL2. 49 | find_library(SDL2_GFX_LIBRARY_DEBUG 50 | NAMES SDL2_gfxd 51 | PATH_SUFFIXES lib ${_SDL2_GFX_PATH_SUFFIX} 52 | PATHS ${SDL2_GFX_PATH} 53 | ) 54 | 55 | include(SelectLibraryConfigurations) 56 | select_library_configurations(SDL2_GFX) 57 | endif() 58 | 59 | # Find the SDL2_gfx version. 60 | if(SDL2_GFX_INCLUDE_DIR AND EXISTS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h") 61 | file(STRINGS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h" SDL2_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL2_GFXPRIMITIVES_MAJOR[ \t]+[0-9]+$") 62 | file(STRINGS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h" SDL2_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_GFXPRIMITIVES_MINOR[ \t]+[0-9]+$") 63 | file(STRINGS "${SDL2_GFX_INCLUDE_DIR}/SDL2_gfxPrimitives.h" SDL2_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_GFXPRIMITIVES_MICRO[ \t]+[0-9]+$") 64 | string(REGEX REPLACE "^#define[ \t]+SDL2_GFXPRIMITIVES_MAJOR[ \t]+([0-9]+)$" "\\1" SDL2_GFX_VERSION_MAJOR "${SDL2_GFX_VERSION_MAJOR_LINE}") 65 | string(REGEX REPLACE "^#define[ \t]+SDL2_GFXPRIMITIVES_MINOR[ \t]+([0-9]+)$" "\\1" SDL2_GFX_VERSION_MINOR "${SDL2_GFX_VERSION_MINOR_LINE}") 66 | string(REGEX REPLACE "^#define[ \t]+SDL2_GFXPRIMITIVES_MICRO[ \t]+([0-9]+)$" "\\1" SDL2_GFX_VERSION_PATCH "${SDL2_GFX_VERSION_PATCH_LINE}") 67 | set(SDL2_GFX_VERSION_STRING ${SDL2_GFX_VERSION_MAJOR}.${SDL2_GFX_VERSION_MINOR}.${SDL2_GFX_VERSION_PATCH}) 68 | unset(SDL2_GFX_VERSION_MAJOR_LINE) 69 | unset(SDL2_GFX_VERSION_MINOR_LINE) 70 | unset(SDL2_GFX_VERSION_PATCH_LINE) 71 | unset(SDL2_GFX_VERSION_MAJOR) 72 | unset(SDL2_GFX_VERSION_MINOR) 73 | unset(SDL2_GFX_VERSION_PATCH) 74 | endif() 75 | 76 | include(FindPackageHandleStandardArgs) 77 | find_package_handle_standard_args(SDL2_gfx 78 | REQUIRED_VARS SDL2_GFX_LIBRARIES SDL2_GFX_INCLUDE_DIR 79 | VERSION_VAR SDL2_GFX_VERSION_STRING) 80 | 81 | if(SDL2_GFX_FOUND) 82 | set(SDL2_GFX_LIBRARIES ${SDL2_GFX_LIBRARY}) 83 | set(SDL2_GFX_INCLUDE_DIR ${SDL2_GFX_INCLUDE_DIR}) 84 | 85 | # Define the SDL2_gfx target. 86 | if(NOT TARGET SDL2::Gfx) 87 | add_library(SDL2::Gfx UNKNOWN IMPORTED) 88 | set_target_properties(SDL2::Gfx PROPERTIES 89 | INTERFACE_INCLUDE_DIRECTORIES ${SDL2_GFX_INCLUDE_DIR}) 90 | 91 | if(SDL2_GFX_LIBRARY_RELEASE) 92 | set_property(TARGET SDL2::Gfx APPEND PROPERTY 93 | IMPORTED_CONFIGURATIONS RELEASE) 94 | set_target_properties(SDL2::Gfx PROPERTIES 95 | IMPORTED_LOCATION_RELEASE ${SDL2_GFX_LIBRARY_RELEASE}) 96 | endif() 97 | 98 | if(SDL2_GFX_LIBRARY_DEBUG) 99 | set_property(TARGET SDL2::Gfx APPEND PROPERTY 100 | IMPORTED_CONFIGURATIONS DEBUG) 101 | set_target_properties(SDL2::Gfx PROPERTIES 102 | IMPORTED_LOCATION_DEBUG ${SDL2_GFX_LIBRARY_DEBUG}) 103 | endif() 104 | 105 | if(NOT SDL2_GFX_LIBRARY_RELEASE AND NOT SDL2_GFX_LIBRARY_DEBUG) 106 | set_property(TARGET SDL2::Gfx APPEND PROPERTY 107 | IMPORTED_LOCATION ${SDL2_GFX_LIBRARY}) 108 | endif() 109 | endif() 110 | endif() 111 | -------------------------------------------------------------------------------- /FindSDL2_image.cmake: -------------------------------------------------------------------------------- 1 | # Licensed under the ISC license. Please see the LICENSE.md file for details. 2 | # Copyright (c) 2019 Sandro Stikić 3 | 4 | #[[============================================================================ 5 | FindSDL2 6 | --------- 7 | 8 | Try to find SDL2_image. 9 | 10 | This module defines the following IMPORTED targets: 11 | - SDL2::Image — Link against this. 12 | 13 | This module defines the following variables: 14 | - SDL2_IMAGE_FOUND 15 | - SDL2_IMAGE_VERSION_STRING 16 | - SDL2_IMAGE_LIBRARIES (deprecated) 17 | - SDL2_IMAGE_INCLUDE_DIRS (deprecated) 18 | #============================================================================]] 19 | 20 | # Ensure SDL2 is installed. 21 | find_package(SDL2 REQUIRED QUIET) 22 | 23 | if(NOT SDL2_FOUND) 24 | message(FATAL_ERROR "SDL2 not found") 25 | endif() 26 | 27 | # Look for SDL2_image. 28 | find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h 29 | PATH_SUFFIXES SDL2 include/SDL2 include 30 | PATHS ${SDL2_IMAGE_PATH} 31 | ) 32 | 33 | if (NOT SDL2_IMAGE_LIBRARIES) 34 | # Determine architecture. 35 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 36 | set(_SDL2_IMAGE_PATH_SUFFIX lib/x64) 37 | else() 38 | set(_SDL2_IMAGE_PATH_SUFFIX lib/x86) 39 | endif() 40 | 41 | # Look for the release version of SDL2. 42 | find_library(SDL2_IMAGE_LIBRARY_RELEASE 43 | NAMES SDL2_image 44 | PATH_SUFFIXES lib ${_SDL2_IMAGE_PATH_SUFFIX} 45 | PATHS ${SDL2_IMAGE_PATH} 46 | ) 47 | 48 | # Look for the debug version of SDL2. 49 | find_library(SDL2_IMAGE_LIBRARY_DEBUG 50 | NAMES SDL2_imaged 51 | PATH_SUFFIXES lib ${_SDL2_IMAGE_PATH_SUFFIX} 52 | PATHS ${SDL2_IMAGE_PATH} 53 | ) 54 | 55 | include(SelectLibraryConfigurations) 56 | select_library_configurations(SDL2_IMAGE) 57 | endif() 58 | 59 | # Find the SDL2_image version. 60 | if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") 61 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") 62 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") 63 | file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") 64 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") 65 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") 66 | string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") 67 | set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) 68 | unset(SDL2_IMAGE_VERSION_MAJOR_LINE) 69 | unset(SDL2_IMAGE_VERSION_MINOR_LINE) 70 | unset(SDL2_IMAGE_VERSION_PATCH_LINE) 71 | unset(SDL2_IMAGE_VERSION_MAJOR) 72 | unset(SDL2_IMAGE_VERSION_MINOR) 73 | unset(SDL2_IMAGE_VERSION_PATCH) 74 | endif() 75 | 76 | include(FindPackageHandleStandardArgs) 77 | find_package_handle_standard_args(SDL2_image 78 | REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIR 79 | VERSION_VAR SDL2_IMAGE_VERSION_STRING) 80 | 81 | if(SDL2_IMAGE_FOUND) 82 | set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) 83 | set(SDL2_IMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIR}) 84 | 85 | # Define the SDL2_image target. 86 | if(NOT TARGET SDL2::Image) 87 | add_library(SDL2::Image UNKNOWN IMPORTED) 88 | set_target_properties(SDL2::Image PROPERTIES 89 | INTERFACE_INCLUDE_DIRECTORIES "${SDL2_IMAGE_INCLUDE_DIR}") 90 | 91 | if(SDL2_IMAGE_LIBRARY_RELEASE) 92 | set_property(TARGET SDL2::Image APPEND PROPERTY 93 | IMPORTED_CONFIGURATIONS RELEASE) 94 | set_target_properties(SDL2::Image PROPERTIES 95 | IMPORTED_LOCATION_RELEASE "${SDL2_IMAGE_LIBRARY_RELEASE}") 96 | endif() 97 | 98 | if(SDL2_IMAGE_LIBRARY_DEBUG) 99 | set_property(TARGET SDL2::Image APPEND PROPERTY 100 | IMPORTED_CONFIGURATIONS DEBUG) 101 | set_target_properties(SDL2::Image PROPERTIES 102 | IMPORTED_LOCATION_DEBUG "${SDL2_IMAGE_LIBRARY_DEBUG}") 103 | endif() 104 | 105 | if(NOT SDL2_IMAGE_LIBRARY_RELEASE AND NOT SDL2_IMAGE_LIBRARY_DEBUG) 106 | set_property(TARGET SDL2::Image APPEND PROPERTY 107 | IMPORTED_LOCATION "${SDL2_IMAGE_LIBRARY}") 108 | endif() 109 | endif() 110 | endif() 111 | -------------------------------------------------------------------------------- /FindSDL2_mixer.cmake: -------------------------------------------------------------------------------- 1 | # Licensed under the ISC license. Please see the LICENSE.md file for details. 2 | # Copyright (c) 2019 Sandro Stikić 3 | 4 | #[[============================================================================ 5 | FindSDL2 6 | --------- 7 | 8 | Try to find SDL2_mixer. 9 | 10 | This module defines the following IMPORTED targets: 11 | - SDL2::Mixer — Link against this. 12 | 13 | This module defines the following variables: 14 | - SDL2_MIXER_FOUND 15 | - SDL2_MIXER_VERSION_STRING 16 | - SDL2_MIXER_LIBRARIES (deprecated) 17 | - SDL2_MIXER_INCLUDE_DIRS (deprecated) 18 | #============================================================================]] 19 | 20 | # Ensure SDL2 is installed. 21 | find_package(SDL2 REQUIRED QUIET) 22 | 23 | if(NOT SDL2_FOUND) 24 | message(FATAL_ERROR "SDL2 not found") 25 | endif() 26 | 27 | # Look for SDL2_mixer. 28 | find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h 29 | PATH_SUFFIXES SDL2 include/SDL2 include 30 | PATHS ${SDL2_MIXER_PATH} 31 | ) 32 | 33 | if (NOT SDL2_MIXER_LIBRARIES) 34 | # Determine architecture. 35 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 36 | set(_SDL2_MIXER_PATH_SUFFIX lib/x64) 37 | else() 38 | set(_SDL2_MIXER_PATH_SUFFIX lib/x86) 39 | endif() 40 | 41 | # Look for the release version of SDL2. 42 | find_library(SDL2_MIXER_LIBRARY_RELEASE 43 | NAMES SDL2_mixer 44 | PATH_SUFFIXES lib ${_SDL2_MIXER_PATH_SUFFIX} 45 | PATHS ${SDL2_MIXER_PATH} 46 | ) 47 | 48 | # Look for the debug version of SDL2. 49 | find_library(SDL2_MIXER_LIBRARY_DEBUG 50 | NAMES SDL2_mixerd 51 | PATH_SUFFIXES lib ${_SDL2_MIXER_PATH_SUFFIX} 52 | PATHS ${SDL2_MIXER_PATH} 53 | ) 54 | 55 | include(SelectLibraryConfigurations) 56 | select_library_configurations(SDL2_MIXER) 57 | endif() 58 | 59 | # Find the SDL2_mixer version. 60 | if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") 61 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") 62 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") 63 | file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") 64 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") 65 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") 66 | string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") 67 | set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) 68 | unset(SDL2_MIXER_VERSION_MAJOR_LINE) 69 | unset(SDL2_MIXER_VERSION_MINOR_LINE) 70 | unset(SDL2_MIXER_VERSION_PATCH_LINE) 71 | unset(SDL2_MIXER_VERSION_MAJOR) 72 | unset(SDL2_MIXER_VERSION_MINOR) 73 | unset(SDL2_MIXER_VERSION_PATCH) 74 | endif() 75 | 76 | include(FindPackageHandleStandardArgs) 77 | find_package_handle_standard_args(SDL2_mixer 78 | REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIR 79 | VERSION_VAR SDL2_MIXER_VERSION_STRING) 80 | 81 | if(SDL2_MIXER_FOUND) 82 | set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) 83 | set(SDL2_MIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIR}) 84 | 85 | # Define the SDL2_mixer target. 86 | if(NOT TARGET SDL2::Mixer) 87 | add_library(SDL2::Mixer UNKNOWN IMPORTED) 88 | set_target_properties(SDL2::Mixer PROPERTIES 89 | INTERFACE_INCLUDE_DIRECTORIES ${SDL2_MIXER_INCLUDE_DIR}) 90 | 91 | if(SDL2_MIXER_LIBRARY_RELEASE) 92 | set_property(TARGET SDL2::Mixer APPEND PROPERTY 93 | IMPORTED_CONFIGURATIONS RELEASE) 94 | set_target_properties(SDL2::Mixer PROPERTIES 95 | IMPORTED_LOCATION_RELEASE ${SDL2_MIXER_LIBRARY_RELEASE}) 96 | endif() 97 | 98 | if(SDL2_MIXER_LIBRARY_DEBUG) 99 | set_property(TARGET SDL2::Mixer APPEND PROPERTY 100 | IMPORTED_CONFIGURATIONS DEBUG) 101 | set_target_properties(SDL2::Mixer PROPERTIES 102 | IMPORTED_LOCATION_DEBUG ${SDL2_MIXER_LIBRARY_DEBUG}) 103 | endif() 104 | 105 | if(NOT SDL2_MIXER_LIBRARY_RELEASE AND NOT SDL2_MIXER_LIBRARY_DEBUG) 106 | set_property(TARGET SDL2::Mixer APPEND PROPERTY 107 | IMPORTED_LOCATION ${SDL2_MIXER_LIBRARY}) 108 | endif() 109 | endif() 110 | endif() 111 | -------------------------------------------------------------------------------- /FindSDL2_net.cmake: -------------------------------------------------------------------------------- 1 | # Licensed under the ISC license. Please see the LICENSE.md file for details. 2 | # Copyright (c) 2019 Sandro Stikić 3 | 4 | #[[============================================================================ 5 | FindSDL2 6 | --------- 7 | 8 | Try to find SDL2_net. 9 | 10 | This module defines the following IMPORTED targets: 11 | - SDL2::Net — Link against this. 12 | 13 | This module defines the following variables: 14 | - SDL2_NET_FOUND 15 | - SDL2_NET_VERSION_STRING 16 | - SDL2_NET_LIBRARIES (deprecated) 17 | - SDL2_NET_INCLUDE_DIRS (deprecated) 18 | #============================================================================]] 19 | 20 | # Ensure SDL2 is installed. 21 | find_package(SDL2 REQUIRED QUIET) 22 | 23 | if(NOT SDL2_FOUND) 24 | message(FATAL_ERROR "SDL2 not found") 25 | endif() 26 | 27 | # Look for SDL2_net. 28 | find_path(SDL2_NET_INCLUDE_DIR SDL_net.h 29 | PATH_SUFFIXES SDL2 include/SDL2 include 30 | PATHS ${SDL2_NET_PATH} 31 | ) 32 | 33 | if (NOT SDL2_NET_LIBRARIES) 34 | # Determine architecture. 35 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 36 | set(_SDL2_NET_PATH_SUFFIX lib/x64) 37 | else() 38 | set(_SDL2_NET_PATH_SUFFIX lib/x86) 39 | endif() 40 | 41 | # Look for the release version of SDL2. 42 | find_library(SDL2_NET_LIBRARY_RELEASE 43 | NAMES SDL2_net 44 | PATH_SUFFIXES lib ${_SDL2_NET_PATH_SUFFIX} 45 | PATHS ${SDL2_NET_PATH} 46 | ) 47 | 48 | # Look for the debug version of SDL2. 49 | find_library(SDL2_NET_LIBRARY_DEBUG 50 | NAMES SDL2_netd 51 | PATH_SUFFIXES lib ${_SDL2_NET_PATH_SUFFIX} 52 | PATHS ${SDL2_NET_PATH} 53 | ) 54 | 55 | include(SelectLibraryConfigurations) 56 | select_library_configurations(SDL2_NET) 57 | endif() 58 | 59 | # Find the SDL2_net version. 60 | if(SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") 61 | file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+[0-9]+$") 62 | file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+[0-9]+$") 63 | file(STRINGS "${SDL2_NET_INCLUDE_DIR}/SDL_net.h" SDL2_NET_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+[0-9]+$") 64 | string(REGEX REPLACE "^#define[ \t]+SDL_NET_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MAJOR "${SDL2_NET_VERSION_MAJOR_LINE}") 65 | string(REGEX REPLACE "^#define[ \t]+SDL_NET_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_MINOR "${SDL2_NET_VERSION_MINOR_LINE}") 66 | string(REGEX REPLACE "^#define[ \t]+SDL_NET_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_NET_VERSION_PATCH "${SDL2_NET_VERSION_PATCH_LINE}") 67 | set(SDL2_NET_VERSION_STRING ${SDL2_NET_VERSION_MAJOR}.${SDL2_NET_VERSION_MINOR}.${SDL2_NET_VERSION_PATCH}) 68 | unset(SDL2_NET_VERSION_MAJOR_LINE) 69 | unset(SDL2_NET_VERSION_MINOR_LINE) 70 | unset(SDL2_NET_VERSION_PATCH_LINE) 71 | unset(SDL2_NET_VERSION_MAJOR) 72 | unset(SDL2_NET_VERSION_MINOR) 73 | unset(SDL2_NET_VERSION_PATCH) 74 | endif() 75 | 76 | include(FindPackageHandleStandardArgs) 77 | find_package_handle_standard_args(SDL2_net 78 | REQUIRED_VARS SDL2_NET_LIBRARIES SDL2_NET_INCLUDE_DIR 79 | VERSION_VAR SDL2_NET_VERSION_STRING) 80 | 81 | if(SDL2_NET_FOUND) 82 | set(SDL2_NET_LIBRARIES ${SDL2_NET_LIBRARY}) 83 | set(SDL2_NET_INCLUDE_DIR ${SDL2_NET_INCLUDE_DIR}) 84 | 85 | # Define the SDL2_net target. 86 | if(NOT TARGET SDL2::Net) 87 | add_library(SDL2::Net UNKNOWN IMPORTED) 88 | set_target_properties(SDL2::Net PROPERTIES 89 | INTERFACE_INCLUDE_DIRECTORIES ${SDL2_NET_INCLUDE_DIR}) 90 | 91 | if(SDL2_NET_LIBRARY_RELEASE) 92 | set_property(TARGET SDL2::Net APPEND PROPERTY 93 | IMPORTED_CONFIGURATIONS RELEASE) 94 | set_target_properties(SDL2::Net PROPERTIES 95 | IMPORTED_LOCATION_RELEASE ${SDL2_NET_LIBRARY_RELEASE}) 96 | endif() 97 | 98 | if(SDL2_NET_LIBRARY_DEBUG) 99 | set_property(TARGET SDL2::Net APPEND PROPERTY 100 | IMPORTED_CONFIGURATIONS DEBUG) 101 | set_target_properties(SDL2::Net PROPERTIES 102 | IMPORTED_LOCATION_DEBUG ${SDL2_NET_LIBRARY_DEBUG}) 103 | endif() 104 | 105 | if(NOT SDL2_NET_LIBRARY_RELEASE AND NOT SDL2_NET_LIBRARY_DEBUG) 106 | set_property(TARGET SDL2::Net APPEND PROPERTY 107 | IMPORTED_LOCATION ${SDL2_NET_LIBRARY}) 108 | endif() 109 | endif() 110 | endif() 111 | -------------------------------------------------------------------------------- /FindSDL2_ttf.cmake: -------------------------------------------------------------------------------- 1 | # Licensed under the ISC license. Please see the LICENSE.md file for details. 2 | # Copyright (c) 2019 Sandro Stikić 3 | 4 | #[[============================================================================ 5 | FindSDL2 6 | --------- 7 | 8 | Try to find SDL2_ttf. 9 | 10 | This module defines the following IMPORTED targets: 11 | - SDL2::TTF — Link against this. 12 | 13 | This module defines the following variables: 14 | - SDL2_TTF_FOUND 15 | - SDL2_TTF_VERSION_STRING 16 | - SDL2_TTF_LIBRARIES (deprecated) 17 | - SDL2_TTF_INCLUDE_DIRS (deprecated) 18 | #============================================================================]] 19 | 20 | # Ensure SDL2 is installed. 21 | find_package(SDL2 REQUIRED QUIET) 22 | 23 | if(NOT SDL2_FOUND) 24 | message(FATAL_ERROR "SDL2 not found") 25 | endif() 26 | 27 | # Look for SDL2_ttf. 28 | find_path(SDL2_TTF_INCLUDE_DIR SDL_ttf.h 29 | PATH_SUFFIXES SDL2 include/SDL2 include 30 | PATHS ${SDL2_TTF_PATH} 31 | ) 32 | 33 | if (NOT SDL2_TTF_LIBRARIES) 34 | # Determine architecture. 35 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 36 | set(_SDL2_TTF_PATH_SUFFIX lib/x64) 37 | else() 38 | set(_SDL2_TTF_PATH_SUFFIX lib/x86) 39 | endif() 40 | 41 | # Look for the release version of SDL2. 42 | find_library(SDL2_TTF_LIBRARY_RELEASE 43 | NAMES SDL2_ttf 44 | PATH_SUFFIXES lib ${_SDL2_TTF_PATH_SUFFIX} 45 | PATHS ${SDL2_TTF_PATH} 46 | ) 47 | 48 | # Look for the debug version of SDL2. 49 | find_library(SDL2_TTF_LIBRARY_DEBUG 50 | NAMES SDL2_ttfd 51 | PATH_SUFFIXES lib ${_SDL2_TTF_PATH_SUFFIX} 52 | PATHS ${SDL2_TTF_PATH} 53 | ) 54 | 55 | include(SelectLibraryConfigurations) 56 | select_library_configurations(SDL2_TTF) 57 | endif() 58 | 59 | # Find the SDL2_ttf version. 60 | if(SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") 61 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") 62 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$") 63 | file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$") 64 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}") 65 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}") 66 | string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}") 67 | set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH}) 68 | unset(SDL2_TTF_VERSION_MAJOR_LINE) 69 | unset(SDL2_TTF_VERSION_MINOR_LINE) 70 | unset(SDL2_TTF_VERSION_PATCH_LINE) 71 | unset(SDL2_TTF_VERSION_MAJOR) 72 | unset(SDL2_TTF_VERSION_MINOR) 73 | unset(SDL2_TTF_VERSION_PATCH) 74 | endif() 75 | 76 | include(FindPackageHandleStandardArgs) 77 | find_package_handle_standard_args(SDL2_ttf 78 | REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIR 79 | VERSION_VAR SDL2_TTF_VERSION_STRING) 80 | 81 | if(SDL2_TTF_FOUND) 82 | set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) 83 | set(SDL2_TTF_INCLUDE_DIR ${SDL2_TTF_INCLUDE_DIR}) 84 | 85 | # Define the SDL2_ttf target. 86 | if(NOT TARGET SDL2::TTF) 87 | add_library(SDL2::TTF UNKNOWN IMPORTED) 88 | set_target_properties(SDL2::TTF PROPERTIES 89 | INTERFACE_INCLUDE_DIRECTORIES ${SDL2_TTF_INCLUDE_DIR}) 90 | 91 | if(SDL2_TTF_LIBRARY_RELEASE) 92 | set_property(TARGET SDL2::TTF APPEND PROPERTY 93 | IMPORTED_CONFIGURATIONS RELEASE) 94 | set_target_properties(SDL2::TTF PROPERTIES 95 | IMPORTED_LOCATION_RELEASE ${SDL2_TTF_LIBRARY_RELEASE}) 96 | endif() 97 | 98 | if(SDL2_TTF_LIBRARY_DEBUG) 99 | set_property(TARGET SDL2::TTF APPEND PROPERTY 100 | IMPORTED_CONFIGURATIONS DEBUG) 101 | set_target_properties(SDL2::TTF PROPERTIES 102 | IMPORTED_LOCATION_DEBUG ${SDL2_TTF_LIBRARY_DEBUG}) 103 | endif() 104 | 105 | if(NOT SDL2_TTF_LIBRARY_RELEASE AND NOT SDL2_TTF_LIBRARY_DEBUG) 106 | set_property(TARGET SDL2::TTF APPEND PROPERTY 107 | IMPORTED_LOCATION ${SDL2_TTF_LIBRARY}) 108 | endif() 109 | endif() 110 | endif() 111 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright © 2019 [Sandro Stikić](mailto:sandro@stikic.me) 2 | 3 | Permission to use, copy, modify, and/or distribute this software for 4 | any purpose with or without fee is hereby granted, provided that the 5 | above copyright notice and this permission notice appear in all 6 | copies. 7 | 8 | **The software is provided "as is" and the author disclaims all 9 | warranties with regard to this software including all implied 10 | warranties of merchantability and fitness. In no event shall the 11 | author be liable for any special, direct, indirect, or consequential 12 | damages or any damages whatsoever resulting from loss of use, data or 13 | profits, whether in an action of contract, negligence or other 14 | tortious action, arising out of or in connection with the use or 15 | performance of this software.** 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |
3 | sdl2-logo 4 |
5 | CMake Modern FindSDL2 6 |
7 |

8 | 9 |

10 | CMake modules to find SDL2 and its extensions. 11 |

12 | 13 |

14 | Usage • 15 | License • 16 | Acknowledgments 17 |

18 | 19 | ## Usage 20 | Add this repository as a submodule to your project. 21 | ```cmake 22 | git submodule add https://github.com/opeik/cmake-modern-findsdl2 cmake/sdl2 23 | ``` 24 | Include the new modules. 25 | ```cmake 26 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2) 27 | ``` 28 | Find the package you want to use. 29 | ```cmake 30 | find_package(SDL2 REQUIRED) 31 | find_package(SDL2_ttf REQUIRED) 32 | find_package(SDL2_gfx REQUIRED) 33 | find_package(SDL2_image REQUIRED) 34 | find_package(SDL2_mixer REQUIRED) 35 | find_package(SDL2_net REQUIRED) 36 | ``` 37 | Link against it. 38 | ```cmake 39 | target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2 SDL2::TTF 40 | SDL2::Image SDL2::Mixer SDL2::Net SDL2::Gfx) 41 | ``` 42 | 43 | If you're writing an application, link against `SDL2::SDL2`. If you're writing 44 | a library, link against `SDL2::Core` instead. 45 | 46 | ## License 47 | This project is licensed under the ISC license. Please see the [`LICENSE.md`](LICENSE.md) 48 | file for details. 49 | 50 | ## Acknowledgments 51 | * Thanks to [aminosbh](https://github.com/aminosbh) for creating similar cmake 52 | scripts which I referenced 53 | --------------------------------------------------------------------------------