Skip to content

Commit 4319861

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::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}).
1 parent 5c1d2d1 commit 4319861

File tree

19 files changed

+872
-40
lines changed

19 files changed

+872
-40
lines changed

examples/CMakeLists.txt

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
imgui_option(OPENGL_LOADER
29+
"Dear ImGui OpenGL loader (IMGL3W, GL3W, GLEW, GLAD or CUSTOM)"
30+
"IMGL3W"
31+
STRINGS "IMGL3W" "GL3W" "GLEW" "GLAD" "CUSTOM")
32+
imgui_option(FREETYPE "Dear ImGui will build font atlases using FreeType instead of stb_truetype" OFF)
33+
imgui_option(TOOLS "Dear ImGui auxiliary applications" OFF)
34+
imgui_option(PACKAGE "Dear ImGui packaging" OFF)
35+
36+
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake"
37+
CONTENT "${ImGui_OPTIONS_CMAKE}")
38+
39+
include("${CMAKE_CURRENT_LIST_DIR}/ImGuiTargets.cmake")
40+
41+
set(ImGui_DIR "${CMAKE_CURRENT_LIST_DIR}")
42+
43+
imgui_example(example_null
44+
TARGETS Core)
45+
46+
imgui_example(example_sdl3_sdlrenderer3
47+
BACKENDS ImplSDL3 ImplSDLRenderer3)
48+
49+
imgui_example(example_sdl3_opengl3
50+
BACKENDS ImplSDL3 ImplOpenGL3)
51+
52+
imgui_example(example_glfw_opengl3
53+
BACKENDS ImplGlfw ImplOpenGL3)
54+
55+
if(NOT EMSCRIPTEN)
56+
imgui_example(example_glut_opengl2
57+
BACKENDS ImplGLUT ImplOpenGL2)
58+
59+
imgui_example(example_sdl2_sdlrenderer2
60+
BACKENDS ImplSDL2 ImplSDLRenderer2)
61+
62+
imgui_example(example_sdl2_opengl2
63+
BACKENDS ImplSDL2 ImplOpenGL2)
64+
65+
imgui_example(example_sdl2_opengl3
66+
BACKENDS ImplSDL2 ImplOpenGL3)
67+
68+
imgui_example(example_sdl2_vulkan
69+
BACKENDS ImplSDL2 ImplVulkan)
70+
71+
imgui_example(example_sdl3_vulkan
72+
BACKENDS ImplSDL3 ImplVulkan)
73+
74+
imgui_example(example_glfw_opengl2
75+
BACKENDS ImplGlfw ImplOpenGL2)
76+
77+
imgui_example(example_glfw_vulkan
78+
BACKENDS ImplGlfw ImplVulkan)
79+
endif()
80+
81+
if(NOT "${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
82+
foreach(FILE ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake)
83+
configure_file(${FILE} ${FILE} COPYONLY)
84+
endforeach()
85+
endif()
86+
87+
install(FILES ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake
88+
"${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake"
89+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/imgui)
90+
91+
if(ImGui_PACKAGE)
92+
if(NOT DEFINED CPACK_PACKAGE_NAME)
93+
set(CPACK_PACKAGE_NAME "dear-imgui")
94+
endif()
95+
include(CPack)
96+
endif()

examples/CMakePresets.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": 2,
3+
"configurePresets": [
4+
{
5+
"name": "vcpkg",
6+
"generator": "Ninja",
7+
"binaryDir": "${sourceDir}/../build/${presetName}",
8+
"cacheVariables": {
9+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
10+
}
11+
},
12+
{
13+
"name": "emscripten",
14+
"inherits": "vcpkg",
15+
"cacheVariables": {
16+
"VCPKG_TARGET_TRIPLET": "wasm32-emscripten",
17+
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "$env{EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake"
18+
}
19+
}
20+
]
21+
}

examples/ImGuiConfig.cmake

+21
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)