This is a minimal C++ application using SDL2 with CMake.
It is based on the following resources:
- Using SDL2 with CMake
- StackOverflow answer that navigated me through the most basic SDL concepts
- The SDl2 Tutorial by GLUSoft
Given you have brew and the XCode command line tools (xcode-select -install
) You can install SDL2 for development via:
brew install cmake
brew install sdl2
sudo apt install libsdl2-dev cmake g++
- Install cmake
- Install the latest development archive for windows from the SDL2 releases page.
- Unpack that somewhere
- Configure cmake to find that directory
To configure CMake to find SDL2, use this configuration, name it sdl2-config.cmake
and put it next to where you downloaded the development libraries. This is based on the blog linked above.
set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")
# Support both 32 and 64 bit builds
if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2main.lib")
else ()
set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2main.lib")
endif ()
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)