Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imgui: make backends available as optional components, convert -docking versions into an option #25325

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3b053a8
imgui: make backends available as optional components
valgur Aug 30, 2024
27bdbd0
imgui: disable glut backend due missing binaries and being considered…
valgur Sep 23, 2024
a2c92f9
imgui: add transitive vulkan-headers
valgur Sep 23, 2024
3b715bc
imgui: sdl2 backend is not available in old versions
valgur Sep 23, 2024
5584c83
imgui: bump sdl
valgur Sep 23, 2024
f68daa9
imgui: move Objective-C++ backends to a separate test
valgur Sep 23, 2024
293df93
imgui: ensure cxx_std_11 is set
valgur Sep 23, 2024
989430c
imgui: fix required macOS frameworks
valgur Sep 23, 2024
4f1fac6
imgui: add enable_metal_cpp option
valgur Sep 23, 2024
4163b70
imgui: rename export header
valgur Sep 23, 2024
5055e37
imgui: fix MSVC shared build
valgur Sep 24, 2024
cb5e64b
imgui: freetype support cannot be built separately
valgur Sep 24, 2024
bd5139b
imgui: enable DirectX 9 and 10, Metal C++ bindings
valgur Sep 24, 2024
823aa9f
imgui: tidy CMakeLists.txt
valgur Sep 24, 2024
75e557b
imgui: bump lunasvg
valgur Sep 24, 2024
bb1c305
imgui: temporarily enable lunasvg as well
valgur Sep 24, 2024
be4be74
imgui: lunasvg is not available for all versions
valgur Sep 24, 2024
1695475
imgui: lunasvg in 1.89.x is buggy
valgur Sep 24, 2024
9f6b90e
imgui: add metal-cpp dependency
valgur Sep 24, 2024
9a7c239
imgui: disable heavier SDL2 and Vulkan backends, disable freetype by …
valgur Sep 24, 2024
2b349e6
imgui: fix different config param name in old version
valgur Sep 24, 2024
d7cd1ea
Merge remote-tracking branch 'upstream/master' into feature/imgui-ref…
valgur Oct 21, 2024
feaa8a5
imgui: convert -docking versions into a recipe option instead
valgur Oct 21, 2024
edbbcaa
Merge remote-tracking branch 'refs/remotes/upstream/master' into feat…
valgur Oct 24, 2024
720b407
Merge remote-tracking branch 'upstream/master' into feature/imgui-ref…
valgur Nov 5, 2024
c13dbf6
imgui: drop Conan 1.x support
valgur Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 208 additions & 42 deletions recipes/imgui/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,56 +1,222 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(imgui LANGUAGES CXX)

set(MISC_DIR ${IMGUI_SRC_DIR}/misc)
set(EXTRA_FONTS_DIR ${MISC_DIR}/fonts)
set(IMGUI_EXPORT_HEADERS imgui_export_headers.h)

file(GLOB SOURCE_FILES ${IMGUI_SRC_DIR}/*.cpp)
file(GLOB HEADER_FILES ${IMGUI_SRC_DIR}/*.h)

file(GLOB EXTRA_FONTS_FILES ${EXTRA_FONTS_DIR}/*.ttf)
if (MSVC)
file(GLOB EXTRA_NATVIS_FILES ${MISC_DIR}/natvis/*.natvis)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

set(BINARY_TO_COMPRESSED_BIN binary_to_compressed_c)

add_executable(${BINARY_TO_COMPRESSED_BIN} ${EXTRA_FONTS_DIR}/binary_to_compressed_c.cpp)
target_compile_features(${BINARY_TO_COMPRESSED_BIN} PRIVATE cxx_std_11)
add_library(imgui
imgui.cpp
imgui_demo.cpp
imgui_draw.cpp
imgui_tables.cpp
imgui_widgets.cpp
misc/cpp/imgui_stdlib.cpp
)
target_include_directories(imgui PUBLIC ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})

add_library(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES
set_target_properties(imgui PROPERTIES
CXX_VISIBILITY_PRESET hidden
OBJCXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
set(IMGUI_EXPORT_HEADER imgui_export.h)
include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME}
generate_export_header(imgui
EXPORT_MACRO_NAME IMGUI_API
EXPORT_FILE_NAME ${IMGUI_EXPORT_HEADERS}
EXPORT_FILE_NAME ${IMGUI_EXPORT_HEADER}
)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${IMGUI_SRC_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
# Enable __declspec(dllexport) in backend libs as well
add_compile_definitions(imgui_EXPORTS)

if(IMGUI_FREETYPE)
find_package(freetype CONFIG REQUIRED)
target_sources(imgui PRIVATE misc/freetype/imgui_freetype.cpp)
target_link_libraries(imgui PRIVATE freetype)
install(FILES misc/freetype/imgui_freetype.h DESTINATION include)
if(IMGUI_FREETYPE_LUNASVG)
find_package(lunasvg CONFIG REQUIRED)
target_link_libraries(imgui PRIVATE lunasvg::lunasvg)
endif()
endif()

if(IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS)
target_link_libraries(imgui PRIVATE "-framework ApplicationServices")
endif()

if(IMGUI_IMPL_ALLEGRO5)
find_package(Allegro CONFIG REQUIRED)
add_library(imgui-allegro5 backends/imgui_impl_allegro5.cpp)
target_link_libraries(imgui-allegro5 PRIVATE Allegro::allegro Allegro::allegro_ttf Allegro::allegro_font Allegro::allegro_main)
install(FILES backends/imgui_impl_allegro5.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-allegro5)
endif()

if(IMGUI_IMPL_ANDROID)
add_library(imgui-android backends/imgui_impl_android.cpp)
install(FILES backends/imgui_impl_android.h DESTINATION include)
target_link_libraries(imgui-android PRIVATE android log EGL GLESv3)
list(APPEND IMGUI_COMPONENTS imgui-android)
endif()

if(IMGUI_IMPL_DX9)
add_library(imgui-dx9 backends/imgui_impl_dx9.cpp)
target_link_libraries(imgui-dx9 PRIVATE d3d9)
install(FILES backends/imgui_impl_dx9.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-dx9)
endif()

if(IMGUI_IMPL_DX10)
add_library(imgui-dx10 backends/imgui_impl_dx10.cpp)
target_link_libraries(imgui-dx9 PRIVATE d3d10)
install(FILES backends/imgui_impl_dx10.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-dx10)
endif()

if(IMGUI_IMPL_DX11)
add_library(imgui-dx11 backends/imgui_impl_dx11.cpp)
target_link_libraries(imgui-dx11 PRIVATE d3d11)
install(FILES backends/imgui_impl_dx11.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-dx11)
endif()

if(IMGUI_IMPL_DX12)
add_library(imgui-dx12 backends/imgui_impl_dx12.cpp)
target_link_libraries(imgui-dx12 PRIVATE d3d12)
install(FILES backends/imgui_impl_dx12.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-dx12)
endif()

if(IMGUI_IMPL_GLFW)
add_library(imgui-glfw backends/imgui_impl_glfw.cpp)
if(NOT EMSCRIPTEN)
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(imgui-glfw PRIVATE glfw)
endif()
install(FILES backends/imgui_impl_glfw.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-glfw)
endif()

if(IMGUI_IMPL_GLUT)
add_library(imgui-glut backends/imgui_impl_glut.cpp)
if(NOT EMSCRIPTEN)
find_package(GLUT REQUIRED)
target_link_libraries(imgui-glut PRIVATE GLUT::GLUT)
endif()
install(FILES backends/imgui_impl_glut.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-glut)
endif()

if(IMGUI_IMPL_METAL)
enable_language(OBJCXX)
add_library(imgui-metal backends/imgui_impl_metal.mm)
set_source_files_properties(backends/imgui_impl_metal.mm PROPERTIES COMPILE_FLAGS -fobjc-weak)
target_link_libraries(imgui-metal PRIVATE
"-framework Foundation"
"-framework Metal"
"-framework QuartzCore"
)
install(FILES backends/imgui_impl_metal.h DESTINATION include)
if(IMGUI_IMPL_METAL_CPP)
find_package(metal-cpp CONFIG REQUIRED)
target_link_libraries(imgui-metal PRIVATE metal-cpp::metal-cpp)
endif()
list(APPEND IMGUI_COMPONENTS imgui-metal)
endif()

if(IMGUI_IMPL_OPENGL2)
find_package(OpenGL REQUIRED)
add_library(imgui-opengl2 backends/imgui_impl_opengl2.cpp)
target_link_libraries(imgui-opengl2 PRIVATE OpenGL::GL)
install(FILES backends/imgui_impl_opengl2.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-opengl2)
endif()

if(IMGUI_IMPL_OPENGL3)
find_package(OpenGL REQUIRED)
add_library(imgui-opengl3 backends/imgui_impl_opengl3.cpp)
target_link_libraries(imgui-opengl3 PRIVATE OpenGL::GL)
install(FILES backends/imgui_impl_opengl3.h DESTINATION include)
install(FILES backends/imgui_impl_opengl3_loader.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-opengl3)
endif()

if(IMGUI_IMPL_OSX)
enable_language(OBJCXX)
add_library(imgui-osx backends/imgui_impl_osx.mm)
target_link_libraries(imgui-osx PRIVATE
"-framework AppKit"
"-framework Carbon"
"-framework Cocoa"
"-framework Foundation"
"-framework GameController"
)
install(FILES backends/imgui_impl_osx.h DESTINATION include)
if(IMGUI_IMPL_METAL_CPP_EXTENSIONS)
find_package(metal-cpp CONFIG REQUIRED)
target_link_libraries(imgui-osx PRIVATE metal-cpp::metal-cpp)
endif()
list(APPEND IMGUI_COMPONENTS imgui-osx)
endif()

if(IMGUI_IMPL_SDL2)
find_package(SDL2 CONFIG REQUIRED)
add_library(imgui-sdl2 backends/imgui_impl_sdl2.cpp)
target_link_libraries(imgui-sdl2 PRIVATE SDL2::SDL2)
install(FILES backends/imgui_impl_sdl2.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-sdl2)
endif()

if(IMGUI_IMPL_SDLRENDERER2)
find_package(SDL2 CONFIG REQUIRED)
add_library(imgui-sdlrenderer2 backends/imgui_impl_sdlrenderer2.cpp)
target_link_libraries(imgui-sdlrenderer2 PRIVATE SDL2::SDL2)
install(FILES backends/imgui_impl_sdlrenderer2.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-sdlrenderer2)
endif()

if(IMGUI_IMPL_VULKAN)
find_package(Vulkan REQUIRED)
add_library(imgui-vulkan backends/imgui_impl_vulkan.cpp)
target_link_libraries(imgui-vulkan PRIVATE Vulkan::Vulkan)
install(FILES backends/imgui_impl_vulkan.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-vulkan)
endif()

if(IMGUI_IMPL_WIN32)
add_library(imgui-win32 backends/imgui_impl_win32.cpp)
target_link_libraries(imgui-win32 PRIVATE dwmapi xinput)
install(FILES backends/imgui_impl_win32.h DESTINATION include)
list(APPEND IMGUI_COMPONENTS imgui-win32)
endif()

foreach(component ${IMGUI_COMPONENTS})
target_link_libraries(${component} PUBLIC imgui)
endforeach()

if(IMGUI_IMPL_TOOLS)
add_executable(binary_to_compressed_c misc/fonts/binary_to_compressed_c.cpp)
install(TARGETS binary_to_compressed_c DESTINATION bin)
endif()

install(TARGETS imgui ${IMGUI_COMPONENTS}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

file(GLOB IMGUI_HEADERS *.h)
install(FILES
misc/cpp/imgui_stdlib.h
${IMGUI_HEADERS}
${PROJECT_BINARY_DIR}/${IMGUI_EXPORT_HEADER}
DESTINATION include
)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)

include(GNUInstallDirs)

install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${BINARY_TO_COMPRESSED_BIN}
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${HEADER_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${IMGUI_EXPORT_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
install(FILES ${EXTRA_FONTS_FILES}
DESTINATION ${CMAKE_INSTALL_PREFIX}/res/fonts
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)

file(GLOB EXTRA_FONTS_FILES misc/fonts/*.ttf)
install(FILES ${EXTRA_FONTS_FILES} DESTINATION res/fonts)

if (MSVC)
install(FILES ${EXTRA_NATVIS_FILES}
DESTINATION ${CMAKE_INSTALL_PREFIX}/res/natvis
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
file(GLOB EXTRA_NATVIS_FILES misc/natvis/*.natvis)
install(FILES ${EXTRA_NATVIS_FILES} DESTINATION res/natvis)
endif()
Loading