Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
cmake_minimum_required(VERSION 3.5)

# Fetching version from header file
file(STRINGS ../imgui.h ImGui_VERSION_NUM_HEADER_STRING
REGEX "#define[ \t]+IMGUI_VERSION_NUM[ \t]+([0-9]+)"
LIMIT_COUNT 1)
string(REGEX REPLACE "#define[ \t]+IMGUI_VERSION_NUM[ \t]+([0-9]+)" "\\1"
IMGUI_VERSION_NUM "${ImGui_VERSION_NUM_HEADER_STRING}")
math(EXPR IMGUI_VERSION_MAJOR "${IMGUI_VERSION_NUM} / 10000")
math(EXPR IMGUI_VERSION_MINOR "(${IMGUI_VERSION_NUM} % 10000) / 100")
math(EXPR IMGUI_VERSION_PATCH "${IMGUI_VERSION_NUM} % 100")

project(imgui_examples
VERSION "${IMGUI_VERSION_MAJOR}.${IMGUI_VERSION_MINOR}.${IMGUI_VERSION_PATCH}"
LANGUAGES CXX)

get_filename_component(ImGui_SRCDIR "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY)

include("${CMAKE_CURRENT_LIST_DIR}/ImGuiModule.cmake")

set(ImGui_OPTIONS)

imgui_option(USER_CONFIG "Dear ImGui user config for include" "" STRING)
imgui_option(EXAMPLES "Dear ImGui example applications" ON)
imgui_option(BACKENDS "Dear ImGui platform and render backends" ON)
imgui_option(MISC "Dear ImGui misc features" ON)
imgui_option(3RDPARTY "Dear ImGui example dependencies" ON)
imgui_option(OPENGL_LOADER
"Dear ImGui OpenGL loader (IMGL3W, GL3W, GLEW, GLAD or CUSTOM)"
"IMGL3W"
STRINGS "IMGL3W" "GL3W" "GLEW" "GLAD" "CUSTOM")
imgui_option(FREETYPE "Dear ImGui will build font atlases using FreeType instead of stb_truetype" OFF)
imgui_option(TOOLS "Dear ImGui auxiliary applications" OFF)
imgui_option(PACKAGE "Dear ImGui packaging" OFF)

file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake"
CONTENT "${ImGui_OPTIONS_CMAKE}")

include("${CMAKE_CURRENT_LIST_DIR}/ImGuiTargets.cmake")

set(ImGui_DIR "${CMAKE_CURRENT_LIST_DIR}")

imgui_example(example_null
TARGETS Core)

imgui_example(example_sdl3_sdlrenderer3
BACKENDS ImplSDL3 ImplSDLRenderer3)

imgui_example(example_sdl3_opengl3
BACKENDS ImplSDL3 ImplOpenGL3)

imgui_example(example_glfw_opengl3
BACKENDS ImplGlfw ImplOpenGL3)

if(NOT EMSCRIPTEN)
imgui_example(example_glut_opengl2
BACKENDS ImplGLUT ImplOpenGL2)

imgui_example(example_sdl2_sdlrenderer2
BACKENDS ImplSDL2 ImplSDLRenderer2)

imgui_example(example_sdl2_opengl2
BACKENDS ImplSDL2 ImplOpenGL2)

imgui_example(example_sdl2_opengl3
BACKENDS ImplSDL2 ImplOpenGL3)

imgui_example(example_sdl2_vulkan
BACKENDS ImplSDL2 ImplVulkan)

imgui_example(example_sdl3_vulkan
BACKENDS ImplSDL3 ImplVulkan)

imgui_example(example_glfw_opengl2
BACKENDS ImplGlfw ImplOpenGL2)

imgui_example(example_glfw_vulkan
BACKENDS ImplGlfw ImplVulkan)
endif()

if(NOT "${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
foreach(FILE ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake)
configure_file(${FILE} ${FILE} COPYONLY)
endforeach()
endif()

install(FILES ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake
"${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/imgui)

if(ImGui_PACKAGE)
if(NOT DEFINED CPACK_PACKAGE_NAME)
set(CPACK_PACKAGE_NAME "dear-imgui")
endif()
include(CPack)
endif()
21 changes: 21 additions & 0 deletions examples/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg",
"generator": "Ninja",
"binaryDir": "${sourceDir}/../build/${presetName}",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
{
"name": "emscripten",
"inherits": "vcpkg",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "wasm32-emscripten",
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "$env{EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake"
}
}
]
}
21 changes: 21 additions & 0 deletions examples/ImGuiConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if(NOT DEFINED ImGui_FIND_COMPONENTS)
set(ImGui_FIND_COMPONENTS Core)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/ImGuiTargets.cmake")

foreach(COMPONENT ${ImGui_FIND_COMPONENTS})
if(NOT ";${ImGui_AVAILABLE_COMPONENTS};" MATCHES ";${COMPONENT};")
set(ImGui_FOUND FALSE)
set(ImGui_NOT_FOUND_MESSAGE "Unavailable component: ${COMPONENT}.")
endif()
if(NOT ";${ImGui_SUPPORTED_COMPONENTS};" MATCHES ";${COMPONENT};")
set(ImGui_FOUND FALSE)
set(ImGui_NOT_FOUND_MESSAGE "Unsupported component: ${COMPONENT}.")
endif()
endforeach()

if(NOT ImGui_FOUND)
set(ImGui_NOT_FOUND_MESSAGE "${ImGui_NOT_FOUND_MESSAGE}\nSupported components: ${ImGui_SUPPORTED_COMPONENTS}.")
set(ImGui_NOT_FOUND_MESSAGE "${ImGui_NOT_FOUND_MESSAGE}\nAvailable components: ${ImGui_AVAILABLE_COMPONENTS}.")
endif()
Loading
Loading