Coder Social home page Coder Social logo

sdl2-cmake-scripts's Introduction

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 :-).

sdl2-cmake-scripts's People

Contributors

tcbrindle avatar emlai avatar falven avatar janisozaur avatar andyli avatar larsch avatar nsubtil avatar skycocoo avatar wrbs avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.