|
| 1 | +# ------------------------------------------------------------------------------ |
| 2 | +# Static library target wrapping Dear ImGui (docking branch). |
| 3 | +# |
| 4 | +# Expected layout: |
| 5 | +# <this file's parent>/../../3rdparty/imgui/ ← git submodule |
| 6 | +# |
| 7 | +# The submodule must be the "docking" branch of |
| 8 | +# https://github.com/ocornut/imgui |
| 9 | +# ------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +cmake_minimum_required(VERSION 3.5) |
| 12 | +project(imgui_static LANGUAGES CXX) |
| 13 | + |
| 14 | +# Locate the submodule root relative to this file |
| 15 | +get_filename_component(_IMGUI_ROOT |
| 16 | + "${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/imgui" ABSOLUTE) |
| 17 | + |
| 18 | +if(NOT EXISTS "${_IMGUI_ROOT}/imgui.h") |
| 19 | + message(FATAL_ERROR |
| 20 | + "Dear ImGui submodule not found at ${_IMGUI_ROOT}.\n" |
| 21 | + "Run: git submodule update --init --recursive") |
| 22 | +endif() |
| 23 | + |
| 24 | +# Find GLFW (already required by mrpt-gui, so it will be present) |
| 25 | +find_package(glfw3 REQUIRED) |
| 26 | +find_package(OpenGL REQUIRED) |
| 27 | + |
| 28 | +set(_IMGUI_SRCS |
| 29 | + ${_IMGUI_ROOT}/imgui.cpp |
| 30 | + ${_IMGUI_ROOT}/imgui_draw.cpp |
| 31 | + ${_IMGUI_ROOT}/imgui_tables.cpp |
| 32 | + ${_IMGUI_ROOT}/imgui_widgets.cpp |
| 33 | +# ${_IMGUI_ROOT}/imgui_demo.cpp # can be excluded in release builds |
| 34 | + ${_IMGUI_ROOT}/misc/cpp/imgui_stdlib.cpp # std::string InputText support |
| 35 | + ${_IMGUI_ROOT}/backends/imgui_impl_glfw.cpp |
| 36 | + ${_IMGUI_ROOT}/backends/imgui_impl_opengl3.cpp |
| 37 | +) |
| 38 | + |
| 39 | +add_library(imgui_static STATIC ${_IMGUI_SRCS}) |
| 40 | +set_target_properties(imgui_static PROPERTIES POSITION_INDEPENDENT_CODE TRUE) |
| 41 | + |
| 42 | +target_include_directories(imgui_static |
| 43 | + PUBLIC |
| 44 | + ${_IMGUI_ROOT} |
| 45 | + ${_IMGUI_ROOT}/backends |
| 46 | + ${_IMGUI_ROOT}/misc/cpp |
| 47 | +) |
| 48 | + |
| 49 | +# Enable the docking branch feature set: |
| 50 | +target_compile_definitions(imgui_static |
| 51 | + PUBLIC |
| 52 | + IMGUI_ENABLE_DOCKING # activates docking API |
| 53 | + IMGUI_IMPL_OPENGL_LOADER_GLEW # or GLAD — adjust to whatever mrpt uses |
| 54 | +) |
| 55 | + |
| 56 | +target_link_libraries(imgui_static |
| 57 | + PUBLIC |
| 58 | + glfw |
| 59 | + OpenGL::GL |
| 60 | +) |
| 61 | + |
| 62 | +# Suppress warnings from third-party code |
| 63 | +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") |
| 64 | + target_compile_options(imgui_static PRIVATE -w) |
| 65 | +endif() |
| 66 | + |
| 67 | +# Export as an alias so parent CMake can use it as imgui::imgui |
| 68 | +add_library(imgui::imgui ALIAS imgui_static) |
0 commit comments