Skip to content

Instantly share code, notes, and snippets.

@Zenger
Created November 20, 2024 03:57
Show Gist options
  • Save Zenger/146dd45d057b2b75bf6185c9094a099e to your computer and use it in GitHub Desktop.
Save Zenger/146dd45d057b2b75bf6185c9094a099e to your computer and use it in GitHub Desktop.
Hassle free SDL2 CMake config
# In this example we assume mingw32 and x86_64-w64-mingw32 SDL2 is used
# In your main.cxx file make sure to use this macro before including SDL2 header or you'll get issues
# define SDL2_MAIN_HANDLED
# include <SDL2/SDL.h>
cmake_minimum_required(VERSION 3.22)
project(YourProject)
set(CMAKE_CXX_STANDARD 14)
set(SDL2PATH "C:/Your/Path/To/SDL2-2.30.9/x86_64-w64-mingw32")
set(CMAKE_PREFIX_PATH "${SDL2PATH}/lib/cmake/SDL2")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
add_executable(YourProject main.cpp)
target_link_libraries(YourProject ${SDL2_LIBRARIES})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment