Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
93 changes: 93 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
cmake_minimum_required(VERSION 3.23)
project(rlImGui VERSION 0.1.0)

option(BUILD_EXAMPLES "Build examples" OFF)

include(FetchContent)

find_package(imgui QUIET)
if (NOT imgui_FOUND)
FetchContent_Declare(
imgui
URL https://github.com/ocornut/imgui/archive/refs/heads/master.zip
URL_HASH MD5=cc306a442c28bc853615eb9579292130
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(imgui)
add_library(imgui STATIC)
add_library(imgui::imgui ALIAS imgui)
target_sources(imgui
PUBLIC
FILE_SET HEADERS
FILES
${imgui_SOURCE_DIR}/imgui.h
${imgui_SOURCE_DIR}/imgui_internal.h
${imgui_SOURCE_DIR}/imstb_rectpack.h
${imgui_SOURCE_DIR}/imstb_textedit.h
${imgui_SOURCE_DIR}/imstb_truetype.h
BASE_DIRS ${imgui_SOURCE_DIR}
PRIVATE
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
)
endif ()

find_package(raylib QUIET)
if (NOT raylib_FOUND)
FetchContent_Declare(
raylib
URL https://github.com/raysan5/raylib/archive/refs/heads/master.zip
URL_HASH MD5=cbb82e5c9beca98fd27787821e7c0cf2
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(raylib)
endif ()


add_library(rlImGui STATIC)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this STATIC?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll work on the SHARED option, I'll get back to you in a couple of days.

target_sources(rlImGui
PUBLIC
FILE_SET HEADERS
FILES rlImGui.h rlImGuiColors.h imgui_impl_raylib.h
PRIVATE
rlImGui.cpp
)
target_link_libraries(rlImGui PUBLIC imgui::imgui raylib)

set_target_properties(rlImGui PROPERTIES EXPORT_NAME "rlImGui")
install(TARGETS rlImGui
EXPORT rlImGuiTargets
ARCHIVE DESTINATION lib
FILE_SET HEADERS DESTINATION include
)

install(EXPORT rlImGuiTargets
NAMESPACE rlImGui::
DESTINATION lib/cmake/rlImGui
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/rlImGuiConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/rlImGuiConfigVersion.cmake"
DESTINATION lib/cmake/rlImGui
)

configure_file(cmake/rlImGuiConfig.cmake.in rlImGuiConfig.cmake @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/rlImGuiConfig.cmake"
DESTINATION lib/cmake/rlImGui
)


if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()

3 changes: 3 additions & 0 deletions cmake/rlImGuiConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/rlImGuiTargets.cmake")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What file does this reference? it's not in the PR.
Could you explain what the purpose of this file is?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target files are created automatically by cmake on executing cmake --target install

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files .cmake.in are templates. When we call cmake install cmake replaces @var@ with the value VAR from CMakeLists.txt and the result is what the consumer of the library will get after the installation.

47 changes: 47 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

add_executable(simple)
target_sources(simple
PRIVATE simple.cpp
)
target_link_libraries(simple PRIVATE rlImGui)
add_custom_command(TARGET simple POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${PROJECT_SOURCE_DIR}/resources/parrots.png" "$<TARGET_FILE_DIR:simple>/resources/parrots.png"
)


add_executable(editor)
target_sources(editor
PRIVATE editor.cpp
)
target_link_libraries(editor PRIVATE rlImGui)
add_custom_command(TARGET editor POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${PROJECT_SOURCE_DIR}/resources/parrots.png" "$<TARGET_FILE_DIR:editor>/resources/parrots.png"
)


add_executable(imgui_style_example)
target_sources(imgui_style_example
PRIVATE imgui_style_example.cpp
)
target_link_libraries(imgui_style_example PRIVATE rlImGui)
add_custom_command(TARGET imgui_style_example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this didn't copy files

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove them

"${PROJECT_SOURCE_DIR}/resources/driusstraight.ttf" "$<TARGET_FILE_DIR:imgui_style_example>/resources/driusstraight.ttf"
)


add_executable(docking_example)
target_sources(docking_example
PRIVATE docking_example.cpp
)
target_link_libraries(docking_example PRIVATE rlImGui)


add_executable(asset_browser)
target_sources(asset_browser
PRIVATE asset_browser/main.cpp asset_browser/asset_browser.cpp asset_browser/imgui_utils.cpp asset_browser/item_views.cpp
asset_browser/asset_browser.h asset_browser/imgui_utils.h asset_browser/item_view.h
)
target_link_libraries(asset_browser PRIVATE rlImGui)