-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
add basic CMake implementation #7094
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
project(imgui LANGUAGES C CXX) | ||
|
||
add_library(imgui imgui.cpp imgui_draw.cpp imgui_tables.cpp imgui_widgets.cpp) | ||
target_include_directories(imgui PUBLIC .) | ||
|
||
add_subdirectory(backends) | ||
add_subdirectory(misc/cpp) | ||
|
||
ocornut marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
|
||
ocornut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
option(IMGUI_BACKEND_ALLEGRO "Enable the Allegro backend" OFF) | ||
if(IMGUI_BACKEND_ALLEGRO) | ||
add_library(imgui_backend_allegro imgui_impl_allegro5.cpp) | ||
target_include_directories(imgui_backend_allegro PUBLIC .) | ||
target_link_libraries(imgui_backend_allegro PUBLIC imgui) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_ANDROID "Enable the Android backend" OFF) | ||
if(IMGUI_BACKEND_ANDROID) | ||
add_library(imgui_backend_android imgui_impl_android.cpp) | ||
target_include_directories(imgui_backend_android PUBLIC .) | ||
target_link_libraries(imgui_backend_android PUBLIC android imgui) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_DX10 "Enable the DirectX 10 backend" OFF) | ||
if(IMGUI_BACKEND_DX10) | ||
add_library(imgui_backend_dx10 imgui_impl_dx10.cpp) | ||
target_include_directories(imgui_backend_dx10 PUBLIC .) | ||
target_link_libraries(imgui_backend_dx10 PUBLIC imgui d3d10.lib d3dcompiler.lib) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_DX11 "Enable the DirectX 11 backend" OFF) | ||
if(IMGUI_BACKEND_DX11) | ||
add_library(imgui_backend_dx11 imgui_impl_dx11.cpp) | ||
target_include_directories(imgui_backend_dx11 PUBLIC .) | ||
target_link_libraries(imgui_backend_dx11 PUBLIC imgui d3d11.lib d3dcompiler.lib) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_DX12 "Enable the DirectX 12 backend" OFF) | ||
if(IMGUI_BACKEND_DX12) | ||
add_library(imgui_backend_dx12 imgui_impl_dx12.cpp) | ||
target_include_directories(imgui_backend_dx12 PUBLIC .) | ||
target_link_libraries(imgui_backend_dx12 PUBLIC imgui d3d12.lib d3dcompiler.lib dxgi.lib) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_DX9 "Enable the DirectX 9 backend" OFF) | ||
if(IMGUI_BACKEND_DX9) | ||
add_library(imgui_backend_dx9 imgui_impl_dx9.cpp) | ||
target_include_directories(imgui_backend_dx9 PUBLIC .) | ||
target_link_libraries(imgui_backend_dx9 PUBLIC imgui d3d9.lib) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_GLFW "Enable the GLFW backends" OFF) | ||
if(IMGUI_BACKEND_GLFW) | ||
find_package(glfw3 REQUIRED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and for other This won't work very well for packages that don't want to use glfw added via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't |
||
add_library(imgui_backend_glfw imgui_impl_glfw.cpp) | ||
target_include_directories(imgui_backend_glfw PUBLIC .) | ||
target_link_libraries(imgui_backend_glfw PUBLIC imgui glfw) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_GLUT "Enable the GLUT backend" OFF) | ||
if(IMGUI_BACKEND_GLUT) | ||
find_package(glut REQUIRED) | ||
add_library(imgui_backend_glut imgui_impl_glut.cpp) | ||
target_include_directories(imgui_backend_glut PUBLIC .) | ||
target_link_libraries(imgui_backend_glut PUBLIC imgui glut) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_METAL "Enable the Metal backend" OFF) | ||
if(IMGUI_BACKEND_METAL) | ||
add_library(imgui_backend_metal imgui_impl_metal.mm) | ||
target_include_directories(imgui_backend_metal PUBLIC .) | ||
target_link_libraries(imgui_backend_metal PUBLIC imgui "-framework Metal -framework MetalKit -framework QuartzCore") | ||
endif() | ||
|
||
option(IMGUI_BACKEND_OPENGL "Enable the OpenGL backends" OFF) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think people would want one or the other, but rarely both, so it's worth separating into "IMGUI_BACKEND_OPENGL2" and "IMGUI_BACKEND_OPENGL3" |
||
if(IMGUI_BACKEND_OPENGL) | ||
find_package(OpenGL REQUIRED) | ||
|
||
add_library(imgui_backend_opengl2 imgui_impl_opengl2.cpp) | ||
target_include_directories(imgui_backend_opengl2 PUBLIC .) | ||
target_link_libraries(imgui_backend_opengl2 PUBLIC imgui OpenGL::OpenGL) | ||
|
||
add_library(imgui_backend_opengl3 imgui_impl_opengl3.cpp) | ||
target_include_directories(imgui_backend_opengl3 PUBLIC .) | ||
target_link_libraries(imgui_backend_opengl3 PUBLIC imgui OpenGL::OpenGL) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_OSX "Enable the OSX backend" OFF) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "IMGUI_BACKEND_COCOA"? Because "OSX backend" is a bit confusing. |
||
if(IMGUI_BACKEND_OSX) | ||
add_library(imgui_backend_osx imgui_impl_osx.mm) | ||
target_include_directories(imgui_backend_osx PUBLIC .) | ||
target_link_libraries(imgui_backend_osx PUBLIC imgui "-framework Cocoa") | ||
endif() | ||
|
||
option(IMGUI_BACKEND_SDL2 "Enable the SDL2 backends" OFF) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and everywhere else: "backends" should be "backend" |
||
if(IMGUI_BACKEND_SDL2) | ||
find_package(SDL2 REQUIRED) | ||
|
||
add_library(imgui_backend_sdl2 imgui_impl_sdl2.cpp) | ||
target_include_directories(imgui_backend_sdl2 PUBLIC .) | ||
target_link_libraries(imgui_backend_sdl2 PUBLIC imgui SDL2::SDL2main SDL2::SDL2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also if(BUILD_SHARED_LIBS)
target_link_libraries(imgui_packend_sdl2 PUBLIC
SDL2::SDL2
)
else()
target_link_libraries(imgui_packend_sdl2 PUBLIC
SDL2::SDL2-static
)
endif() |
||
|
||
add_library(imgui_backend_sdlrenderer2 imgui_impl_sdlrenderer2.cpp) | ||
target_include_directories(imgui_backend_sdlrenderer2 PUBLIC .) | ||
target_link_libraries(imgui_backend_sdlrenderer2 PUBLIC imgui SDL2::SDL2main SDL2::SDL2) | ||
Comment on lines
+95
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely needs to be optional in the same way that OpenGL backends are optional, for example. If I use OpenGL, I have no need for sdlrenderer impl. |
||
endif() | ||
|
||
option(IMGUI_BACKEND_SDL3 "Enable the SDL3 backends" OFF) | ||
if(IMGUI_BACKEND_SDL3) | ||
find_package(SDL3 REQUIRED) | ||
add_library(imgui_backend_sdl3 imgui_impl_sdl3.cpp) | ||
target_include_directories(imgui_backend_sdl3 PUBLIC .) | ||
target_link_libraries(imgui_backend_sdl3 PUBLIC imgui SDL3::SDL3) | ||
|
||
add_library(imgui_backend_sdlrenderer3 imgui_impl_sdlrenderer3.cpp) | ||
target_include_directories(imgui_backend_sdlrenderer3 PUBLIC .) | ||
target_link_libraries(imgui_backend_sdlrenderer3 PUBLIC imgui SDL3::SDL3) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_VULKAN "Enable the Vulkan backends" OFF) | ||
if(IMGUI_BACKEND_VULKAN) | ||
find_package(Vulkan REQUIRED) | ||
add_library(imgui_backend_vulkan imgui_impl_vulkan.cpp) | ||
target_include_directories(imgui_backend_vulkan PUBLIC .) | ||
target_link_libraries(imgui_backend_vulkan PUBLIC imgui Vulkan::Vulkan) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_WGPU "Enable the WGPU backends" OFF) | ||
if(IMGUI_BACKEND_WGPU) | ||
find_package(wgpu REQUIRED) | ||
add_library(imgui_backend_wgpu imgui_impl_wgpu.cpp) | ||
target_include_directories(imgui_backend_wgpu PUBLIC .) | ||
target_link_libraries(imgui_backend_wgpu PUBLIC imgui wgpu) | ||
endif() | ||
|
||
option(IMGUI_BACKEND_WIN32 "Enable the Win32 backend" OFF) | ||
if(IMGUI_BACKEND_WIN32) | ||
add_library(imgui_backend_win32 imgui_impl_win32.cpp) | ||
target_include_directories(imgui_backend_win32 PUBLIC .) | ||
target_link_libraries(imgui_backend_win32 PUBLIC imgui) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_library(imgui_stdlib imgui_stdlib.cpp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't see why imgui_stdlib should be a separate lib here - probably should be included with the main |
||
target_include_directories(imgui_stdlib PUBLIC .) | ||
target_link_libraries(imgui_stdlib PUBLIC imgui) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and everywhere else
${CMAKE_CURRENT_LIST_DIR}
seems to be more explicit for me than a "."