Skip to content

Commit

Permalink
add example CMake configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Feb 17, 2020
1 parent f339b24 commit 3a99ca1
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
76 changes: 76 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
project (imgui)
cmake_minimum_required (VERSION 3.2)

option (IMGUI_EXAMPLES "Build ImGui examples" ON)
option (IMGUI_DEMO "Include the ImGui demo window implementation in library" ON)

option (IMGUI_IMPL_SDL "Build the SDL implementation (only if supported)" ON)
option (IMGUI_IMPL_METAL "Build the Metal implementation (only if supported)" ON)
option (IMGUI_IMPL_OSX "Build the OSX implementation (only if supported)" ON)
option (IMGUI_IMPL_GLFW "Build the GLFW implementation (only if supported)" ON)
option (IMGUI_IMPL_GLUT "Build the GLUT implementation (only if supported)" ON)
option (IMGUI_IMPL_OPENGL "Build the OpenGL implementation (only if supported)" ON)
option (IMGUI_IMPL_OPENGL2 "Build the OpenGL 2 (legacy) implementation (only if supported)" ${IMGUI_IMPL_OPENGL})

set (CMAKE_CXX_STANDARD 11)

if (IMGUI_DEMO)
set (IMGUI_DEMO_SRC imgui_demo.cpp)
endif ()

add_library (imgui STATIC
imgui.cpp
imgui_draw.cpp
imgui_widgets.cpp
${IMGUI_DEMO_SRC}
)

target_include_directories (imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")

if (NOT IMGUI_DEMO)
target_compile_definitions (imgui PUBLIC -DIMGUI_DISABLE_DEMO_WINDOWS=1)
endif ()

if (IMGUI_IMPL_SDL)
include (examples/imgui_impl_sdl.cmake)
endif ()
if (IMGUI_IMPL_METAL)
include (examples/imgui_impl_metal.cmake)
endif ()
if (IMGUI_IMPL_OSX)
include (examples/imgui_impl_osx.cmake)
endif ()
if (IMGUI_IMPL_GLFW)
include (examples/imgui_impl_glfw.cmake)
endif ()
if (IMGUI_IMPL_OPENGL OR IMGUI_IMPL_OPENGL2)
include (examples/imgui_impl_opengl.cmake)
endif ()
if (IMGUI_IMPL_GLUT)
include (examples/imgui_impl_glut.cmake)
endif ()

if (IMGUI_EXAMPLES)
set (IMGUI_EXAMPLE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")

#add_subdirectory (examples/example_allegro5)
add_subdirectory (examples/example_apple_metal)
add_subdirectory (examples/example_apple_opengl2)
#add_subdirectory (examples/example_emscripten)
add_subdirectory (examples/example_glfw_metal)
add_subdirectory (examples/example_glfw_opengl2)
add_subdirectory (examples/example_glfw_opengl3)
#add_subdirectory (examples/example_glfw_vulkan)
add_subdirectory (examples/example_glut_opengl2)
#add_subdirectory (examples/example_marmalade)
add_subdirectory (examples/example_null)
#add_subdirectory (examples/example_sdl_directx11)
add_subdirectory (examples/example_sdl_metal)
add_subdirectory (examples/example_sdl_opengl2)
add_subdirectory (examples/example_sdl_opengl3)
#add_subdirectory (examples/example_sdl_vulkan)
#add_subdirectory (examples/example_win32_directx10)
#add_subdirectory (examples/example_win32_directx11)
#add_subdirectory (examples/example_win32_directx12)
#add_subdirectory (examples/example_win32_directx9)
endif ()
18 changes: 18 additions & 0 deletions examples/example_apple_metal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if (TARGET imgui-metal AND TARGET imgui-osx)
# TODO proper bundling of assets for macOS and iOS

add_executable (imgui_example_apple_metal
Shared/main.m
Shared/AppDelegate.m
Shared/Renderer.mm
Shared/ViewController.mm
)

target_link_libraries (imgui_example_apple_metal
imgui-metal imgui-osx
)

set_target_properties (imgui_example_apple_metal
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
11 changes: 11 additions & 0 deletions examples/example_apple_opengl2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-osx AND TARGET imgui-opengl2)
add_executable (imgui_example_apple_opengl2 main.mm)

target_link_libraries (imgui_example_apple_opengl2
imgui-osx imgui-opengl2
)

set_target_properties (imgui_example_apple_opengl2
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
11 changes: 11 additions & 0 deletions examples/example_glfw_metal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-glfw AND TARGET imgui-metal)
add_executable (imgui_example_glfw_metal main.mm)

target_link_libraries (imgui_example_glfw_metal
imgui-glfw imgui-metal
)

set_target_properties (imgui_example_glfw_metal
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
11 changes: 11 additions & 0 deletions examples/example_glfw_opengl2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-glfw AND TARGET imgui-opengl2)
add_executable (imgui_example_glfw_opengl2 main.cpp)

target_link_libraries (imgui_example_glfw_opengl2
imgui-glfw imgui-opengl2
)

set_target_properties (imgui_example_glfw_opengl2
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
11 changes: 11 additions & 0 deletions examples/example_glfw_opengl3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-glfw AND TARGET imgui-opengl)
add_executable (imgui_example_glfw_opengl3 main.cpp)

target_link_libraries (imgui_example_glfw_opengl3
imgui-glfw imgui-opengl
)

set_target_properties (imgui_example_glfw_opengl3
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
11 changes: 11 additions & 0 deletions examples/example_glut_opengl2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-glut AND TARGET imgui-opengl2)
add_executable (imgui_example_glut_opengl2 main.cpp)

target_link_libraries (imgui_example_glut_opengl2
imgui-glut imgui-opengl2
)

set_target_properties (imgui_example_glut_opengl2
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
6 changes: 6 additions & 0 deletions examples/example_null/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_executable (imgui_example_null main.cpp)
target_link_libraries (imgui_example_null imgui)

set_target_properties (imgui_example_null
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
11 changes: 11 additions & 0 deletions examples/example_sdl_metal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-sdl AND TARGET imgui-metal)
add_executable (imgui_example_sdl_metal main.mm)

target_link_libraries (imgui_example_sdl_metal
imgui-sdl imgui-metal
)

set_target_properties (imgui_example_sdl_metal
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
11 changes: 11 additions & 0 deletions examples/example_sdl_opengl2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-sdl AND TARGET imgui-opengl2)
add_executable (imgui_example_sdl_opengl2 main.cpp)

target_link_libraries (imgui_example_sdl_opengl2
imgui-sdl imgui-opengl2
)

set_target_properties (imgui_example_sdl_opengl2
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
11 changes: 11 additions & 0 deletions examples/example_sdl_opengl3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (TARGET imgui-sdl AND TARGET imgui-opengl)
add_executable (imgui_example_sdl_opengl3 main.cpp)

target_link_libraries (imgui_example_sdl_opengl3
imgui-sdl imgui-opengl
)

set_target_properties (imgui_example_sdl_opengl3
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${IMGUI_EXAMPLE_OUTPUT_DIR}"
)
endif ()
12 changes: 12 additions & 0 deletions examples/imgui_impl_glfw.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
find_package (GLFW3)

if (GLFW3_DIR)
add_library (imgui-glfw OBJECT
"${CMAKE_CURRENT_LIST_DIR}/imgui_impl_glfw.cpp"
)

target_link_libraries (imgui-glfw PUBLIC imgui glfw)
target_include_directories (imgui-glfw PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
else ()
message (WARNING "IMGUI_IMPL_GLFW set to ON but glfw3 could not be located")
endif ()
26 changes: 26 additions & 0 deletions examples/imgui_impl_glut.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
find_package (GLUT)

if (GLUT_glut_LIBRARY)
add_library (imgui-glut OBJECT
"${CMAKE_CURRENT_LIST_DIR}/imgui_impl_glut.cpp"
)

target_link_libraries (imgui-glut PUBLIC
imgui
"${GLUT_glut_LIBRARY}"
)

if (APPLE)
target_link_libraries (imgui-glut PUBLIC
"${GLUT_cocoa_LIBRARY}"
)
endif ()

target_include_directories (imgui-glut PUBLIC "${CMAKE_CURRENT_LIST_DIR}")

target_include_directories (imgui-glut SYSTEM PUBLIC
"${GLUT_INCLUDE_DIR}"
)
else ()
message (WARNING "IMGUI_IMPL_GLUT set to ON but GLUT could not be found")
endif ()
19 changes: 19 additions & 0 deletions examples/imgui_impl_metal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if (APPLE)
add_library (imgui-metal OBJECT
"${CMAKE_CURRENT_LIST_DIR}/imgui_impl_metal.mm"
)

target_link_libraries (imgui-metal PUBLIC
imgui
"-framework Cocoa" "-framework Metal" "-framework QuartzCore"
)

target_include_directories (imgui-metal PUBLIC "${CMAKE_CURRENT_LIST_DIR}")

set_property (
TARGET imgui-metal
APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc"
)
else ()
message (WARNING "IMGUI_IMPL_METAL set to ON but platform is not Apple")
endif ()
40 changes: 40 additions & 0 deletions examples/imgui_impl_opengl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
find_package (OpenGL)

if (OPENGL_gl_LIBRARY)
if (IMGUI_IMPL_OPENGL2)
add_library (imgui-opengl2 OBJECT
"${CMAKE_CURRENT_LIST_DIR}/imgui_impl_opengl2.cpp"
)

target_link_libraries (imgui-opengl2 PUBLIC
imgui
"${OPENGL_gl_LIBRARY}"
)

target_include_directories (imgui-opengl2 PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
target_include_directories (imgui-opengl2 SYSTEM PUBLIC "${OPENGL_INCLUDE_DIR}")
endif ()

if (IMGUI_IMPL_OPENGL)
find_package (GLEW)

if (GLEW_DIR)
add_library (imgui-opengl OBJECT
"${CMAKE_CURRENT_LIST_DIR}/imgui_impl_opengl3.cpp"
)

target_link_libraries (imgui-opengl PUBLIC
imgui
"${OPENGL_gl_LIBRARY}"
glew
)

target_include_directories (imgui-opengl PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
target_include_directories (imgui-opengl SYSTEM PUBLIC "${OPENGL_INCLUDE_DIR}")
else ()
message (WARNING "IMGUI_IMPL_OPENGL set to ON but GLEW could not be found")
endif ()
endif ()
else ()
message (WARNING "IMGUI_IMPL_OPENGL and/or IMGUI_IMPL_OPENGL2 set to ON but OpenGL could not be found")
endif ()
15 changes: 15 additions & 0 deletions examples/imgui_impl_osx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if (APPLE)
add_library (imgui-osx OBJECT
"${CMAKE_CURRENT_LIST_DIR}/imgui_impl_osx.mm"
)

target_link_libraries (imgui-osx PUBLIC imgui "-framework Cocoa" "-framework AppKit")
target_include_directories (imgui-osx PUBLIC "${CMAKE_CURRENT_LIST_DIR}")

set_property (
TARGET imgui-osx
APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc"
)
else ()
message (WARNING "IMGUI_IMPL_OSX set to ON but platform is not Apple")
endif ()
19 changes: 19 additions & 0 deletions examples/imgui_impl_sdl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
find_package (SDL2)

if (SDL2_DIR)
add_library (imgui-sdl OBJECT
"${CMAKE_CURRENT_LIST_DIR}/imgui_impl_sdl.cpp"
)

target_link_libraries (imgui-sdl PUBLIC imgui sdl2)
target_include_directories (imgui-sdl PUBLIC "${CMAKE_CURRENT_LIST_DIR}")

# Fixes a strange inclusion problem on MacOS due to an unconventional
# SDL installation with Homebrew. Innocuous if SDL is being pulled in
# from somewhere else.
if (APPLE)
target_include_directories (imgui-sdl SYSTEM PUBLIC "/usr/local/include/SDL2")
endif ()
else ()
message (WARNING "IMGUI_IMPL_SDL set to ON but SDL2 not found on system or in project")
endif ()

0 comments on commit 3a99ca1

Please sign in to comment.