Skip to content

Commit 005d7f6

Browse files
committed
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::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_sdl_opengl2; - example_sdl_opengl3; - example_sdl_vulkan; - example_glfw_opengl2; - example_glfw_opengl3; - example_glfw_vulkan.
1 parent 9aae45e commit 005d7f6

File tree

13 files changed

+729
-39
lines changed

13 files changed

+729
-39
lines changed

examples/CMakeLists.txt

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
3+
# Fetching version from header file
4+
file(STRINGS ../imgui.h ImGui_VERSION_NUM_HEADER_STRING
5+
REGEX "#define[ \t]+IMGUI_VERSION_NUM[ \t]+([0-9]+)"
6+
LIMIT_COUNT 1)
7+
string(REGEX REPLACE "#define[ \t]+IMGUI_VERSION_NUM[ \t]+([0-9]+)" "\\1"
8+
IMGUI_VERSION_NUM "${ImGui_VERSION_NUM_HEADER_STRING}")
9+
math(EXPR IMGUI_VERSION_MAJOR "${IMGUI_VERSION_NUM} / 10000")
10+
math(EXPR IMGUI_VERSION_MINOR "(${IMGUI_VERSION_NUM} % 10000) / 100")
11+
math(EXPR IMGUI_VERSION_PATCH "${IMGUI_VERSION_NUM} % 100")
12+
13+
project(imgui_examples
14+
VERSION "${IMGUI_VERSION_MAJOR}.${IMGUI_VERSION_MINOR}.${IMGUI_VERSION_PATCH}"
15+
LANGUAGES CXX)
16+
17+
get_filename_component(ImGui_SRCDIR "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY)
18+
19+
include("${CMAKE_CURRENT_LIST_DIR}/ImGuiModule.cmake")
20+
21+
set(ImGui_OPTIONS)
22+
23+
imgui_option(USER_CONFIG "Dear ImGui user config for include" "" STRING)
24+
imgui_option(EXAMPLES "Dear ImGui example applications" ON)
25+
imgui_option(BACKENDS "Dear ImGui platform and render backends" ON)
26+
imgui_option(MISC "Dear ImGui misc features" ON)
27+
imgui_option(3RDPARTY "Dear ImGui example dependencies" ON)
28+
if(EMSCRIPTEN)
29+
set(ImGui_OPENGL_LOADER_DEFAULT "GLEW")
30+
else()
31+
set(ImGui_OPENGL_LOADER_DEFAULT "GL3W")
32+
endif()
33+
imgui_option(OPENGL_LOADER
34+
"Dear ImGui OpenGL loader (GL3W, GLEW, GLAD or custom header)"
35+
"${ImGui_OPENGL_LOADER_DEFAULT}"
36+
STRINGS "GL3W" "GLEW" "GLAD")
37+
imgui_option(FREETYPE "Dear ImGui will build font atlases using FreeType instead of stb_truetype" OFF)
38+
imgui_option(TOOLS "Dear ImGui auxiliary applications" OFF)
39+
imgui_option(PACKAGE "Dear ImGui packaging" OFF)
40+
41+
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake"
42+
CONTENT "${ImGui_OPTIONS_CMAKE}")
43+
44+
include("${CMAKE_CURRENT_LIST_DIR}/ImGuiTargets.cmake")
45+
46+
set(ImGui_DIR "${CMAKE_CURRENT_LIST_DIR}")
47+
48+
imgui_example(example_null
49+
TARGETS Core)
50+
51+
if(EMSCRIPTEN)
52+
imgui_example(example_emscripten_opengl3
53+
BACKENDS ImplSDL2 ImplOpenGL3)
54+
else()
55+
imgui_example(example_glut_opengl2
56+
BACKENDS ImplGLUT ImplOpenGL2)
57+
58+
imgui_example(example_sdl_opengl2
59+
BACKENDS ImplSDL2 ImplOpenGL2)
60+
61+
imgui_example(example_sdl_opengl3
62+
BACKENDS ImplSDL2 ImplOpenGL3)
63+
64+
imgui_example(example_sdl_vulkan
65+
BACKENDS ImplSDL2 ImplVulkan)
66+
67+
imgui_example(example_glfw_opengl2
68+
BACKENDS ImplGlfw ImplOpenGL2)
69+
70+
imgui_example(example_glfw_opengl3
71+
BACKENDS ImplGlfw ImplOpenGL3)
72+
73+
imgui_example(example_glfw_vulkan
74+
BACKENDS ImplGlfw ImplVulkan)
75+
endif()
76+
77+
if(NOT "${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
78+
foreach(FILE ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake)
79+
configure_file(${FILE} ${FILE} COPYONLY)
80+
endforeach()
81+
endif()
82+
83+
install(FILES ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake
84+
"${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake"
85+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/imgui)
86+
87+
if(ImGui_PACKAGE)
88+
if(NOT DEFINED CPACK_PACKAGE_NAME)
89+
set(CPACK_PACKAGE_NAME "dear-imgui")
90+
endif()
91+
include(CPack)
92+
endif()

examples/ImGuiConfig.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
if(NOT DEFINED ImGui_FIND_COMPONENTS)
2+
set(ImGui_FIND_COMPONENTS Core)
3+
endif()
4+
5+
include("${CMAKE_CURRENT_LIST_DIR}/ImGuiTargets.cmake")
6+
7+
foreach(COMPONENT ${ImGui_FIND_COMPONENTS})
8+
if(NOT ";${ImGui_AVAILABLE_COMPONENTS};" MATCHES ";${COMPONENT};")
9+
set(ImGui_FOUND FALSE)
10+
set(ImGui_NOT_FOUND_MESSAGE "Unavailable component: ${COMPONENT}.")
11+
endif()
12+
if(NOT ";${ImGui_SUPPORTED_COMPONENTS};" MATCHES ";${COMPONENT};")
13+
set(ImGui_FOUND FALSE)
14+
set(ImGui_NOT_FOUND_MESSAGE "Unsupported component: ${COMPONENT}.")
15+
endif()
16+
endforeach()
17+
18+
if(NOT ImGui_FOUND)
19+
set(ImGui_NOT_FOUND_MESSAGE "${ImGui_NOT_FOUND_MESSAGE}\nSupported components: ${ImGui_SUPPORTED_COMPONENTS}.")
20+
set(ImGui_NOT_FOUND_MESSAGE "${ImGui_NOT_FOUND_MESSAGE}\nAvailable components: ${ImGui_AVAILABLE_COMPONENTS}.")
21+
endif()

0 commit comments

Comments
 (0)