1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-11 00:04:24 +00:00
imgui/examples/CMakeLists.txt
Konstantin Podsvirov b567ffe7e0 Add CMake project
Export Dear ImGui as CMake's ImGui package.

Options:
- ImGui_USER_CONFIG;
- ImGui_EXAMPLES;
- ImGui_BACKENDS;
- ImGui_MISC;
- ImGui_3RDPARTY;
- ImGui_OPENGL_LOADER;
- ImGui_FREETYPE;
- ImGui_TOOLS;
- ImGui_PACKAGE.

Export targets:
- ImGui::Core;
- ImGui::ImplGLUT;
- ImGui::ImplSDL2;
- ImGui::ImplSDLRenderer2;
- ImGui::ImplSDL3;
- ImGui::ImplSDLRenderer3;
- ImGui::ImplGlfw;
- ImGui::ImplOpenGL2;
- ImGui::ImplOpenGL3;
- ImGui::ImplVulkan;
- ImGui::FreeType;
- ImGui::StdLib;
- ImGui::BinaryToCompressedC.

Import targets from:
- build directory;
- installed package.

Examples:
- example_null;
- example_glut_opengl2
- example_sdl2_sdlrenderer2;
- example_sdl2_opengl2;
- example_sdl2_opengl3;
- example_sdl2_vulkan;
- example_sdl3_sdlrenderer3;
- example_sdl3_opengl3;
- example_sdl3_vulkan;
- example_glfw_opengl2;
- example_glfw_opengl3;
- example_glfw_vulkan.

Presets:
- vcpkg (require $env{VCPKG_ROOT});
- emscripten (inherits vcpkg and require $env{EMSCRIPTEN_ROOT}).
2025-06-25 21:37:37 +03:00

96 lines
3.1 KiB
CMake

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()