Installs Impl & Quality Cleanups & Uniformity

This commit is contained in:
Pinwhell 2024-09-18 02:11:20 -04:00
parent 2f28247606
commit 9d5e4c3112
10 changed files with 134 additions and 24 deletions

1
.gitignore vendored
View File

@ -62,3 +62,4 @@ examples/example_sdl2_sdlrenderer/example_sdl2_sdlrenderer
## User Playground ## User Playground
playground/* playground/*
CMakeSettings.json

View File

@ -7,9 +7,15 @@ option(IMGUI_IMPL_OPENGL2 "Enable ImGui OpenGL2 implementation" OFF)
option(IMGUI_IMPL_OPENGL3 "Enable ImGui OpenGL3 implementation" OFF) option(IMGUI_IMPL_OPENGL3 "Enable ImGui OpenGL3 implementation" OFF)
option(IMGUI_ENABLE_PLAYGROUND "Enable playground subdirectory" OFF) option(IMGUI_ENABLE_PLAYGROUND "Enable playground subdirectory" OFF)
set(IMGUI_INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(IMGUI_INC_DIR
add_library(imgui-core STATIC) $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
target_sources(imgui-core PUBLIC imgui.cpp imgui_demo.cpp imgui_draw.cpp imgui_tables.cpp imgui_widgets.cpp) $<INSTALL_INTERFACE:include>)
include(cmake/add_library_ns.cmake)
include(cmake/target_include_dir_iface.cmake)
include(cmake/install_target.cmake)
add_library_ns(imgui core STATIC imgui.cpp imgui_demo.cpp imgui_draw.cpp imgui_tables.cpp imgui_widgets.cpp)
target_include_directories(imgui-core PUBLIC ${IMGUI_INC_DIR}) target_include_directories(imgui-core PUBLIC ${IMGUI_INC_DIR})
add_subdirectory(misc) add_subdirectory(misc)
@ -17,7 +23,25 @@ add_subdirectory(backends)
# Playground is a private space where dev might test/experiment/freestyle stuffs # Playground is a private space where dev might test/experiment/freestyle stuffs
if(IMGUI_ENABLE_PLAYGROUND) if(IMGUI_ENABLE_PLAYGROUND)
if(EXISTS playground) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/playground)
add_subdirectory(playground) add_subdirectory(playground)
endif() endif()
endif() endif()
install_target_and_headers(imgui core
imgui.h
imgui_internal.h
imconfig.h
imstb_truetype.h
imstb_textedit.h
imstb_rectpack.h
)
configure_file(cmake/imgui-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/imgui-config.cmake
@ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/imgui-config.cmake
DESTINATION lib/cmake/imgui)

View File

@ -3,26 +3,31 @@ find_package(OpenGL)
endif() endif()
if(IMGUI_IMPL_WIN32) if(IMGUI_IMPL_WIN32)
add_library(imgui-impl-win32 STATIC) add_library_ns(imgui win32 STATIC imgui_impl_win32.cpp)
target_sources(imgui-impl-win32 PUBLIC imgui_impl_win32.cpp) target_include_dir_iface(imgui-win32 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} include PRIVATE ${IMGUI_INC_DIR})
target_include_directories(imgui-impl-win32 PUBLIC ${IMGUI_INC_DIR}) install_target_and_headers(imgui win32
imgui_impl_win32.h
)
endif() endif()
if(OpenGL_FOUND) if(OpenGL_FOUND)
if(IMGUI_IMPL_OPENGL2) if(IMGUI_IMPL_OPENGL2)
add_library(imgui-impl-opengl2 STATIC) add_library_ns(imgui opengl2 STATIC imgui_impl_opengl2.cpp)
target_sources(imgui-impl-opengl2 PUBLIC imgui_impl_opengl2.cpp) target_include_dir_iface(imgui-opengl2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} include PRIVATE ${IMGUI_INC_DIR})
target_include_directories(imgui-impl-opengl2 PUBLIC ${IMGUI_INC_DIR}) target_link_libraries(imgui-opengl2 OpenGL::GL)
target_link_libraries(imgui-impl-opengl2 OpenGL::GL) install_target_and_headers(imgui opengl2
imgui_impl_opengl2.h
)
endif() endif()
if(IMGUI_IMPL_OPENGL3) if(IMGUI_IMPL_OPENGL3)
add_library(imgui-impl-opengl3 STATIC) add_library_ns(imgui opengl3 STATIC imgui_impl_opengl3.cpp)
target_sources(imgui-impl-opengl3 PUBLIC imgui_impl_opengl3.cpp) target_include_dir_iface(imgui-opengl3 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} include PRIVATE ${IMGUI_INC_DIR})
target_include_directories(imgui-impl-opengl3 PUBLIC ${IMGUI_INC_DIR}) target_link_libraries(imgui-opengl3 OpenGL::GL)
target_link_libraries(imgui-impl-opengl3 OpenGL::GL) install_target_and_headers(imgui opengl3
imgui_impl_opengl3.h
)
endif() endif()
endif() endif()

View File

@ -0,0 +1,14 @@
function(add_library_ns target_ns target_name)
# Forward all arguments after the target_name
set(args ${ARGN})
set(target_fullname ${target_ns}-${target_name})
# Call the original add_library command with the forwarded arguments
add_library(${target_fullname} ${args})
# Alias it properly
add_library(${target_ns}::${target_name} ALIAS ${target_fullname})
# Export name unambiguate
set_target_properties(${target_fullname} PROPERTIES EXPORT_NAME ${target_name})
endfunction()

View File

@ -0,0 +1,30 @@
@PACKAGE_INIT@ # Init
include(CMakeFindDependencyMacro)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/imgui-opengl2-targets.cmake" OR
EXISTS "${CMAKE_CURRENT_LIST_DIR}/imgui-opengl3-targets.cmake")
find_dependency(OpenGL)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/imgui-core-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/imgui-cpp-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/imgui-jumbo-targets.cmake")
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/imgui-freetype-targets.cmake")
find_dependency(Freetype)
include("${CMAKE_CURRENT_LIST_DIR}/imgui-freetype-targets.cmake")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/imgui-win32-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/imgui-win32-targets.cmake")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/imgui-opengl2-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/imgui-opengl2-targets.cmake")
endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/imgui-opengl3-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/imgui-opengl3-targets.cmake")
endif()

View File

@ -0,0 +1,19 @@
function(install_target_and_headers ns name)
set(target_name ${ns}-${name})
install(FILES
${ARGN}
DESTINATION include)
install(TARGETS ${target_name}
EXPORT ${target_name}-targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install(EXPORT ${target_name}-targets
FILE ${target_name}-targets.cmake
NAMESPACE ${ns}::
DESTINATION lib/cmake/${ns})
endfunction()

View File

@ -0,0 +1,10 @@
function(target_include_dir_iface target visibility build-inc install-inc)
set(args ${ARGN})
target_include_directories(
${target}
${visibility}
$<BUILD_INTERFACE:${build-inc}>
$<INSTALL_INTERFACE:${install-inc}>
${args}
)
endfunction()

View File

@ -1,3 +1,5 @@
add_library(imgui-cpp STATIC) add_library_ns(imgui cpp STATIC imgui_stdlib.cpp)
target_sources(imgui-cpp PUBLIC imgui_stdlib.cpp) target_include_dir_iface(imgui-cpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} include PRIVATE ${IMGUI_INC_DIR})
target_include_directories(imgui-cpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${IMGUI_INC_DIR}) install_target_and_headers(imgui cpp
imgui_stdlib.h
)

View File

@ -1,7 +1,9 @@
find_package(Freetype) find_package(Freetype)
if(Freetype_FOUND) if(Freetype_FOUND)
add_library(imgui-freetype STATIC) add_library_ns(imgui freetype STATIC imgui_freetype.cpp)
target_include_directories(imgui-freetype PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${IMGUI_INC_DIR}) target_include_dir_iface(imgui-freetype PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} include PRIVATE ${IMGUI_INC_DIR})
target_sources(imgui-freetype PUBLIC imgui_freetype.cpp)
target_link_libraries(imgui-freetype Freetype::Freetype) target_link_libraries(imgui-freetype Freetype::Freetype)
install_target_and_headers(imgui freetype
imgui_freetype.h
)
endif() endif()

View File

@ -1,2 +1,5 @@
add_library(imgui-jumbo INTERFACE) add_library_ns(imgui jumbo INTERFACE)
target_include_directories(imgui-jumbo INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_dir_iface(imgui-jumbo INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} include INTERFACE ${IMGUI_INC_DIR})
install_target_and_headers(imgui jumbo
imgui_single_file.h
)