(Chore): Fixed cmake to work for imgui + raylib
This commit is contained in:
parent
40ff38d56b
commit
adf62d4c81
@ -1,36 +1,65 @@
|
|||||||
cmake_minimum_required(VERSION 3.24)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(RaylibStuff)
|
|
||||||
|
|
||||||
# nvim/fleet users (ONLY WORKS WITH MINGW/NINJA BUILDERS)
|
# Set the project name
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
project(RaylibDmx)
|
||||||
|
|
||||||
# Deps
|
# Set the C++ standard
|
||||||
add_subdirectory(lib/raylib)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
add_subdirectory(lib/imgui)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
add_subdirectory(lib/rlImGui)
|
|
||||||
|
|
||||||
# add source code
|
# Include FetchContent module
|
||||||
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp")
|
include(FetchContent)
|
||||||
set(PROJECT_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/src")
|
|
||||||
|
|
||||||
# exe
|
# Download and configure raylib
|
||||||
add_executable(${PROJECT_NAME})
|
FetchContent_Declare(
|
||||||
target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES})
|
raylib
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
|
GIT_REPOSITORY https://github.com/raysan5/raylib.git
|
||||||
|
GIT_TAG 4.5.0 # or the latest version you want to use
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(raylib)
|
||||||
|
|
||||||
# THIS IS WHEREE THE OTHER LIBRARIES ARE LINKED
|
# Download and configure ImGui
|
||||||
# SCREW YOU LINKER
|
FetchContent_Declare(
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE imgui raylib rlImGui)
|
imgui
|
||||||
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
||||||
|
GIT_TAG v1.89.2 # or the latest version you want to use
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(imgui)
|
||||||
|
|
||||||
# Web Configurations
|
# Build ImGui as a static library
|
||||||
if (${PLATFORM} STREQUAL "Web")
|
add_library(ImGui STATIC
|
||||||
# Tell Emscripten to build an example.html file.
|
${imgui_SOURCE_DIR}/imgui.cpp
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
|
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
||||||
endif()
|
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
||||||
|
${imgui_SOURCE_DIR}/imgui_tables.cpp
|
||||||
|
${imgui_SOURCE_DIR}/imgui_widgets.cpp
|
||||||
|
)
|
||||||
|
target_include_directories(ImGui PUBLIC ${imgui_SOURCE_DIR})
|
||||||
|
|
||||||
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
|
# Download and configure rlImGui (raylib backend for ImGui)
|
||||||
if (APPLE)
|
FetchContent_Declare(
|
||||||
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
|
rlimgui
|
||||||
target_link_libraries(${PROJECT_NAME} "-framework Cocoa")
|
GIT_REPOSITORY https://github.com/raylib-extras/rlImGui.git
|
||||||
target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
|
GIT_TAG main # Use the correct branch name
|
||||||
endif()
|
)
|
||||||
|
FetchContent_MakeAvailable(rlimgui)
|
||||||
|
|
||||||
|
# Add executable target with the source files
|
||||||
|
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
|
# Link raylib to your project
|
||||||
|
target_link_libraries(${PROJECT_NAME} raylib)
|
||||||
|
|
||||||
|
# Add rlImGui to the project
|
||||||
|
set(RLIMGUI_SOURCES
|
||||||
|
${rlimgui_SOURCE_DIR}/rlImGui.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create the rlImGui library
|
||||||
|
add_library(rlImGui STATIC ${RLIMGUI_SOURCES})
|
||||||
|
target_include_directories(rlImGui PUBLIC ${rlimgui_SOURCE_DIR} ${imgui_SOURCE_DIR})
|
||||||
|
target_link_libraries(rlImGui raylib ImGui)
|
||||||
|
|
||||||
|
# Link ImGui and rlImGui to your project
|
||||||
|
target_link_libraries(${PROJECT_NAME} ImGui rlImGui)
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
include(FetchContent)
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
imgui
|
|
||||||
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
|
||||||
GIT_SHALLOW TRUE
|
|
||||||
GIT_TAG master
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(imgui)
|
|
||||||
|
|
||||||
add_library(imgui STATIC
|
|
||||||
${imgui_SOURCE_DIR}/imgui.cpp
|
|
||||||
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
|
||||||
${imgui_SOURCE_DIR}/imgui_tables.cpp
|
|
||||||
${imgui_SOURCE_DIR}/imgui_widgets.cpp
|
|
||||||
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(imgui PUBLIC
|
|
||||||
${imgui_SOURCE_DIR}
|
|
||||||
)
|
|
@ -1,29 +0,0 @@
|
|||||||
# Use FetchContent to download and build raylib
|
|
||||||
# This is a faster alternative to using a git repo, since this just downloads the source
|
|
||||||
# while the git repo pull takes a lot longer. Not sure why, other repos don't seem to have this issue
|
|
||||||
|
|
||||||
# If you would like to use git instead, use this:
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
#FetchContent_Declare(
|
|
||||||
# raylib
|
|
||||||
# GIT_REPOSITORY "https://github.com/raysan5/raylib.git"
|
|
||||||
# GIT_TAG "master"
|
|
||||||
# GIT_SHALLOW TRUE
|
|
||||||
# GIT_PROGRESS TRUE
|
|
||||||
#)
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
|
|
||||||
set(FETCHCONTENT_QUIET FALSE)
|
|
||||||
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
|
|
||||||
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # don't build the supplied example games
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
raylib
|
|
||||||
URL https://github.com/raysan5/raylib/archive/refs/tags/4.5.0.tar.gz
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(raylib)
|
|
||||||
|
|
||||||
# Raylib conf
|
|
||||||
set(raylib_VERBOSE 1) # not 100 % sure if this does anything...
|
|
@ -1,48 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.24)
|
|
||||||
project(rlImGui)
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
|
||||||
rlImGui
|
|
||||||
GIT_REPOSITORY https://github.com/raylib-extras/rlImGui.git
|
|
||||||
GIT_SHALLOW TRUE
|
|
||||||
GIT_TAG main
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(rlImGui)
|
|
||||||
|
|
||||||
include_directories(${rlImGui_SOURCE_DIR})
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/imgui)
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/raylib/src)
|
|
||||||
|
|
||||||
add_library(rlImGui STATIC
|
|
||||||
${rlImGui_SOURCE_DIR}/rlImGui.h
|
|
||||||
${rlImGui_SOURCE_DIR}/imgui_impl_raylib.h
|
|
||||||
${rlImGui_SOURCE_DIR}/rlImGuiColors.h
|
|
||||||
)
|
|
||||||
|
|
||||||
target_sources(rlImGui PRIVATE
|
|
||||||
${CMAKE_SOURCE_DIR}/imgui/imgui.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/imgui/imgui_draw.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/imgui/imgui_demo.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/imgui/imgui_tables.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/imgui/imgui_widgets.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/imgui/backends/imgui_impl_opengl3.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(rlImGui PRIVATE raylib imgui)
|
|
||||||
|
|
||||||
if (APPLE)
|
|
||||||
target_link_libraries(rlImGui "-framework IOKit" "-framework Cocoa" "-framework OpenGL")
|
|
||||||
elseif(UNIX)
|
|
||||||
target_link_libraries(rlImGui PRIVATE GL m pthread dl X11)
|
|
||||||
elseif(WIN32)
|
|
||||||
target_link_libraries(rlImGui PRIVATE opengl32 gdi32 winmm)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_include_directories(rlImGui PUBLIC
|
|
||||||
${rlImGui_SOURCE_DIR}
|
|
||||||
${CMAKE_SOURCE_DIR}/imgui
|
|
||||||
${CMAKE_SOURCE_DIR}/raylib/src
|
|
||||||
)
|
|
20
src/main.cpp
20
src/main.cpp
@ -3,42 +3,31 @@
|
|||||||
#include "panel.h"
|
#include "panel.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
const int screenWidth = 1920;
|
const int screenWidth = 1920;
|
||||||
const int screenHeight = 1080;
|
const int screenHeight = 1080;
|
||||||
|
|
||||||
// Initialize Raylib
|
|
||||||
InitWindow(screenWidth, screenHeight, "DMX Raylib UI");
|
InitWindow(screenWidth, screenHeight, "DMX Raylib UI");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
// Initialize rlImGui
|
|
||||||
rlImGuiSetup(true); // Use true for dark theme, false for light theme
|
rlImGuiSetup(true); // Use true for dark theme, false for light theme
|
||||||
|
|
||||||
// Create the timeline and properties panels
|
|
||||||
Panel timelinePanel = {{0, 0, screenWidth * 0.75f, screenHeight * 0.6f}, "Timeline", LIGHTGRAY, DARKGRAY, true};
|
Panel timelinePanel = {{0, 0, screenWidth * 0.75f, screenHeight * 0.6f}, "Timeline", LIGHTGRAY, DARKGRAY, true};
|
||||||
Panel propertiesPanel = {{screenWidth * 0.75f, 0, screenWidth * 0.25f, screenHeight}, "Properties", LIGHTGRAY, DARKGRAY, true};
|
Panel propertiesPanel = {{screenWidth * 0.75f, 0, screenWidth * 0.25f, screenHeight}, "Properties", LIGHTGRAY, DARKGRAY, true};
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
// Update panels
|
|
||||||
timelinePanel.Update();
|
timelinePanel.Update();
|
||||||
propertiesPanel.Update();
|
propertiesPanel.Update();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// Start ImGui frame
|
|
||||||
rlImGuiBegin();
|
rlImGuiBegin();
|
||||||
|
bool open = true;
|
||||||
// Create a simple ImGui window (you can expand this with more GUI elements)
|
ImGui::ShowDemoWindow(&open);
|
||||||
ImGui::Begin("ImGui Panel");
|
|
||||||
ImGui::Text("Hello, world!");
|
|
||||||
// ImGui::SliderFloat("Slider", &timelinePanel.position.x, 0.0f, (float)screenWidth);
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
// End ImGui frame
|
|
||||||
rlImGuiEnd();
|
rlImGuiEnd();
|
||||||
|
|
||||||
// Draw Raylib panels
|
|
||||||
if (timelinePanel.isVisible) timelinePanel.Draw();
|
if (timelinePanel.isVisible) timelinePanel.Draw();
|
||||||
if (propertiesPanel.isVisible) propertiesPanel.Draw();
|
if (propertiesPanel.isVisible) propertiesPanel.Draw();
|
||||||
|
|
||||||
@ -46,9 +35,8 @@ int main() {
|
|||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown rlImGui
|
|
||||||
rlImGuiShutdown();
|
rlImGuiShutdown();
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user