Last active
August 20, 2025 06:46
-
-
Save nezvers/aef217ac8048585619283906089bb5c9 to your computer and use it in GitHub Desktop.
SDL3 + Dear ImGui CMake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cmake_minimum_required(VERSION 3.12) | |
| include(FetchContent) | |
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | |
| set(CMAKE_CXX_STANDARD 17) | |
| # SDL3 ______________________________________________ | |
| FetchContent_Declare( | |
| sdl3 | |
| DOWNLOAD_EXTRACT_TIMESTAMP OFF | |
| URL https://github.com/libsdl-org/SDL/archive/refs/tags/release-3.2.8.zip | |
| ) | |
| set(BUILD_SHARED_LIBS OFF) | |
| set(FETCHCONTENT_QUIET NO) | |
| FetchContent_MakeAvailable(sdl3) | |
| # Dear Imgui _____________________________________ | |
| FetchContent_Declare( | |
| imgui | |
| DOWNLOAD_EXTRACT_TIMESTAMP OFF | |
| URL https://github.com/ocornut/imgui/archive/refs/tags/v1.91.9b-docking.zip | |
| ) | |
| FetchContent_MakeAvailable(imgui) | |
| add_library(imgui STATIC | |
| ${imgui_SOURCE_DIR}/imgui.cpp | |
| ${imgui_SOURCE_DIR}/imgui_demo.cpp | |
| ${imgui_SOURCE_DIR}/imgui_draw.cpp | |
| ${imgui_SOURCE_DIR}/imgui_tables.cpp | |
| ${imgui_SOURCE_DIR}/imgui_widgets.cpp | |
| ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl3.cpp | |
| ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer3.cpp | |
| ) | |
| target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR} "${imgui_SOURCE_DIR}/backends") | |
| target_link_libraries(imgui PUBLIC SDL3-static) | |
| # Project __________________________________________________________ | |
| set(PROJECT_NAME Sdl3Template) | |
| project(${PROJECT_NAME}) | |
| include_directories("${CMAKE_SOURCE_DIR}/include") | |
| file(GLOB SRC_FILES "src/*.cpp" "src/*.hpp" "src/*.c" "src/*.h") | |
| add_executable(${PROJECT_NAME} ${SRC_FILES}) | |
| target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/include") | |
| target_link_libraries(${PROJECT_NAME} PRIVATE SDL3-static imgui) | |
| # Setting ASSETS_PATH | |
| if(CMAKE_BUILD_TYPE STREQUAL "Debug") | |
| target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # Set the asset path macro to the absolute path on the dev machine | |
| else() | |
| target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="./assets") # Set the asset path macro in release mode to a relative path that assumes the assets folder is in the same directory as the game executable | |
| endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment