• Stars
    star
    325
  • Rank 129,350 (Top 3 %)
  • Language CMake
  • Created over 10 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CMake scripts for finding SDL2 headers and libraries on multiple platforms

This repository contains CMake scripts for finding the SDL2, SDL2_image and SDL2_ttf libraries and headers.

CMake itself comes with corresponding scripts for SDL 1.2, which hopefully in time will be updated for SDL2 and make this repo redundant. In the mean time, I'm putting them up here in case anyone else finds them useful.

I've tested them on Linux and Mac OS using the Makefile and XCode targets. On Linux, you'll need the SDL2 development packages installed from your distro package manager. On Mac OS you can install the development frameworks from the SDL website or alternatively, if you use Homebrew you can run brew install sdl2 to install the development packages.

Usage

General

In order to use these scripts, you first need to tell CMake where to find them, via the CMAKE_MODULE_PATH variable. For example, if you put them in a subdirectory called cmake, then in your root CMakeLists.txt add the line

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${project_SOURCE_DIR}/cmake")

where project is the name of your project. You can then use the packages themselves by adding

find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)

include_directories(${SDL2_INCLUDE_DIR}
                    ${SDL2_IMAGE_INCLUDE_DIR}
                    ${SDL2_TTF_INCLUDE_DIR})
target_link_libraries(target ${SDL2_LIBRARY}
                             ${SDL2_IMAGE_LIBRARIES}
                             ${SDL2_TTF_LIBRARIES})

or whatever is appropriate for your project.

mingw32 / msys

This section supplements Usage -> General section. You still are required to incorporate General configuration settings in you CMakeLists.txt.

Because cmake binaries for windows aren't aware of *nix/win paths conversion, default paths FindSDL2 will look in won't do any good. For that you should set SDL2_PATH variable. For example:

set(SDL2_PATH "D:\\apps\\SDL2\\i686-w64-mingw32")
mkdir build
cd build
cmake .. -G"MSYS Makefiles"
make

Licence

I am not the original author of these scripts. I found FindSDL2.cmake after some Googling, and hacked up the image and ttf scripts from the SDL1 versions that come with CMake. The original scripts, and my changes, are released under the two-clause BSD licence.

Bugs

These scripts are provided in the hope that you might find them useful. They work for me and hopefully they'll work for you too. If you fix any issues with them then I'd appreciate a pull request so other users can get your fixes too, but that's up to you :-).

More Repositories

1

raytracer.hpp

Simple compile-time raytracer using C++17
C
688
star
2

flux

A C++20 library for sequence-orientated programming
C++
474
star
3

NanoRange

Range-based goodness for C++17
C++
357
star
4

span

Implementation of C++20's std::span for older compilers
C++
326
star
5

cpp17_headers

C++17 library facilities for older compilers
C++
145
star
6

libflow

C++
62
star
7

numeris_romanis

Roman numeral support for C++17
C++
51
star
8

utf_ranges

A collection of Unicode utilities for C++ using Range-V3
C++
43
star
9

numeric_ranges

Numeric algorithms for C++20 Ranges
C++
30
star
10

gsound

GObject wrapper for libcanberra
C
13
star
11

rational

Single-header rational number library for C++14
C++
12
star
12

thinmatrix-gl-tutorials

C
10
star
13

systemd-glib

GObject bindings for the systemd D-Bus API
Vala
6
star
14

gvs

Work-in-progress GObject to GVariant serialization library
C
6
star
15

pretty_print.hpp

Single-header pretty-printing library for STL-compatible containers
C++
6
star
16

advent_of_code_2023

C++
6
star
17

modern-io

Modern IO library for C++
C++
5
star
18

leftpad

Of course I'm serious
C++
4
star
19

advent_of_code_2018

C++17/20 solutions for 2018's Advent of Code
C++
4
star
20

unicode.hpp

Unicode utilities for C++
C++
3
star
21

advent_of_code_2022

C++
3
star
22

sdlxx

Modern C++ binding for SDL2
C++
3
star
23

libsudoku

C and C++14 library for solving sudoku puzzles, using Range-V3
C++
2
star
24

advent_of_code_2020

C++
2
star
25

advent_of_code_2021

C++
1
star
26

wg21papertemplate

A LaTeX template for ISO C++ committee (aka WG21) papers.
TeX
1
star
27

variant

Clone of https://bitbucket.org/anthonyw/variant
C++
1
star