Skip to content

Commit

Permalink
Add CMake project
Browse files Browse the repository at this point in the history
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::ImplGlfw;
- ImGui::ImplOpenGL2;
- ImGui::ImplOpenGL3;
- ImGui::ImplVulkan;
- ImGui::FreeType;
- ImGui::StdLib;
- ImGui::BinaryToCompressedC.

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

Examples:
- example_null;
- example_emscripten_opengl3;
- example_glut_opengl2
- example_sdl2_opengl2;
- example_sdl2_opengl3;
- example_sdl2_vulkan;
- example_glfw_opengl2;
- example_glfw_opengl3;
- example_glfw_vulkan.
  • Loading branch information
podsvirov authored and ocornut committed Nov 7, 2024
1 parent f401021 commit 65e6ef1
Show file tree
Hide file tree
Showing 13 changed files with 729 additions and 40 deletions.
92 changes: 92 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
cmake_minimum_required(VERSION 3.1)

# 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)
if(EMSCRIPTEN)
set(ImGui_OPENGL_LOADER_DEFAULT "GLEW")
else()
set(ImGui_OPENGL_LOADER_DEFAULT "GL3W")
endif()
imgui_option(OPENGL_LOADER
"Dear ImGui OpenGL loader (GL3W, GLEW, GLAD or custom header)"
"${ImGui_OPENGL_LOADER_DEFAULT}"
STRINGS "GL3W" "GLEW" "GLAD")
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)

if(EMSCRIPTEN)
imgui_example(example_emscripten_opengl3
BACKENDS ImplSDL2 ImplOpenGL3)
else()
imgui_example(example_glut_opengl2
BACKENDS ImplGLUT ImplOpenGL2)

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_glfw_opengl2
BACKENDS ImplGlfw ImplOpenGL2)

imgui_example(example_glfw_opengl3
BACKENDS ImplGlfw ImplOpenGL3)

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/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

0 comments on commit 65e6ef1

Please sign in to comment.