Azur/imgui-builds/CMakeLists.txt
Lephe 31da1c0998
meta: build system for Dear ImGui + GL3W + FreeType2
* Add build instructions for Dear ImGui that build the SDL +
  OpenGL 3 / OpenGL ES 2 backend.
* Use Dear ImGui's bundled GL3W as a loader (including in azur itself,
  which has not been using a loader until now).
* Properly select headers for OpenGL ES 2.0 (with the VAO extension) and
  attributes for WebGL; clear up OpenGL 4 error codes.
* If FreeType2 is available through pkg-config, or if empscripten is
  used (since it has a FreeType port), use FreeType to render fonts in
  Dear ImGui for much-appreciated hinting quality.

Minor changes:
* Add window title to azur_init().
* Use emscripten's infinite loop simulation to make sure everything
  stays in the same thread. This is needed for Dear ImGui to work.
2022-05-27 20:55:24 +01:00

63 lines
2.2 KiB
CMake

# The GL3W library which is generated along in Dear ImGui
if(AZUR_GRAPHICS_OPENGL_3_3)
add_library(gl3w
../imgui/examples/libs/gl3w/GL/gl3w.c)
target_include_directories(gl3w PUBLIC
../imgui/examples/libs/gl3w)
# Link with GLX for GL3X to find the extensions, and -ldl
target_link_libraries(gl3w INTERFACE PkgConfig::glx -ldl)
endif()
# The Dear ImGui library for SDL + OpenGL3/OpenGLES2
set(SOURCES
../imgui/imgui.cpp
../imgui/imgui_demo.cpp
../imgui/imgui_draw.cpp
../imgui/imgui_tables.cpp
../imgui/imgui_widgets.cpp
../imgui/backends/imgui_impl_opengl3.cpp
../imgui/backends/imgui_impl_sdl.cpp)
# Use Freetype if the library is installed, or the emscripten port
if(AZUR_PLATFORM_EMSCRIPTEN)
list(APPEND SOURCES ../imgui/misc/freetype/imgui_freetype.cpp)
else()
pkg_check_modules(freetype2 freetype2 IMPORTED_TARGET)
if(freetype2_FOUND)
list(APPEND SOURCES ../imgui/misc/freetype/imgui_freetype.cpp)
endif()
endif()
add_library(imgui ${SOURCES})
# Try to reduce the size of the binary code by including individual functions
# from the archive, instead of whole files
target_compile_options(imgui PRIVATE -ffunction-sections)
target_compile_options(imgui INTERFACE -Wl,--gc-sections)
# Use the pre-built GL3W loader on desktop
if(AZUR_GRAPHICS_OPENGL_3_3)
target_compile_definitions(imgui PUBLIC
-DIMGUI_IMPL_OPENGL_LOADER_GL3W="GL/gl3w.h")
target_link_libraries(imgui PUBLIC gl3w)
# Use the autonomous GLES 2.0 loader otherwise
elseif(AZUR_GRAPHICS_OPENGL_ES_2_0)
target_compile_definitions(imgui PUBLIC
-DIMGUI_IMPL_OPENGL_ES2)
endif()
# FreeType2 settings
if(freetype2_FOUND)
target_compile_definitions(imgui PUBLIC -DIMGUI_ENABLE_FREETYPE)
target_include_directories(imgui PRIVATE ../imgui/misc/freetype)
target_link_libraries(imgui PUBLIC PkgConfig::freetype2)
elseif(AZUR_PLATFORM_EMSCRIPTEN)
target_compile_definitions(imgui PUBLIC -DIMGUI_ENABLE_FREETYPE)
target_include_directories(imgui PRIVATE ../imgui/misc/freetype)
target_compile_options(imgui PUBLIC -sUSE_FREETYPE=2)
target_link_options(imgui INTERFACE -sUSE_FREETYPE=2)
endif()
# Provide include directories
target_include_directories(imgui PUBLIC ../imgui ../imgui/backends)