Compare commits

...

2 Commits

Author SHA1 Message Date
sonoro1234
08677d259c GenerateCimguiBindings is now a module available for several backend_tests 2025-03-24 10:34:25 +01:00
sonoro1234
8f15ab3f80 example_sdlgpu3: small changes (less crazy includes arg) 2025-03-24 09:25:09 +01:00
5 changed files with 48 additions and 110 deletions

View File

@@ -1,8 +1,11 @@
# This downloads cimgui, configures it to generate the SDL3 and SDLGPU3 bindings, # This downloads cimgui, configures it to generate the SDL3 and SDLGPU3 bindings,
# and adds it as a cmake target for you to link to. Feel free to copy this file # and adds it as a cmake target for you to link to. Feel free to copy this file
# into your project, or refit it to your needs. # into your project, or refit it to your needs.
#include(CMakePrintHelpers)
function(IncludesStr comp includes) function(IncludesStr comp includes)
#message("includes is ${includes}") #cmake_print_variables(includes)
if("${comp}" STREQUAL "cl") if("${comp}" STREQUAL "cl")
set(Ist "/I") set(Ist "/I")
else() else()
@@ -10,18 +13,18 @@ function(IncludesStr comp includes)
endif() endif()
set(incstr "") set(incstr "")
foreach(inc ${${includes}}) foreach(inc ${${includes}})
#message("inc is ${inc}") set(incstr ${incstr} ${Ist}${inc})
set(incstr ${Ist}${inc} ${incstr})
endforeach() endforeach()
set(incstr ${incstr} PARENT_SCOPE) set(incstr ${incstr} PARENT_SCOPE)
endfunction() endfunction()
include(CMakePrintHelpers)
function(GenerateCimguiBindings target platbk rendbk inclist)
function(GenerateCimguiBindings target platbk rendbk _inclist)
include(FetchContent) include(FetchContent)
cmake_print_variables(inclist) #cmake_print_variables(_inclist)
cmake_print_variables(${${inclist}}) set(__inclist ${${_inclist}})
#cmake_print_variables(__inclist)
# NOTE: In your own project, you may want to pin this project to a particular commit # NOTE: In your own project, you may want to pin this project to a particular commit
FetchContent_Declare( FetchContent_Declare(
cimgui cimgui
@@ -41,16 +44,15 @@ function(GenerateCimguiBindings target platbk rendbk inclist)
# since this will be executed on each "configure" (whenever you run cmake) # since this will be executed on each "configure" (whenever you run cmake)
string(TOUPPER ${platbk} PLATBK) string(TOUPPER ${platbk} PLATBK)
string(TOUPPER ${rendbk} RENDBK) string(TOUPPER ${rendbk} RENDBK)
string(FIND "${cimgui_impl}" ${RENDBK} rendbk_position) string(FIND "${cimgui_impl}" CIMGUI_USE_${RENDBK} rendbk_position)
string(FIND "${cimgui_impl}" ${PLATBK} platbk_position) string(FIND "${cimgui_impl}" CIMGUI_USE_${PLATBK} platbk_position)
# If we don't find it, rendbk_position will be -1 # If we don't find it, rendbk_position will be -1
if(rendbk_position EQUAL -1 OR platbk_position EQUAL -1) if(rendbk_position EQUAL -1 OR platbk_position EQUAL -1)
#get compiler name #get compiler name
cmake_path(GET CMAKE_C_COMPILER FILENAME C_COMP) cmake_path(GET CMAKE_C_COMPILER FILENAME C_COMP)
cmake_path(REMOVE_EXTENSION C_COMP) cmake_path(REMOVE_EXTENSION C_COMP)
#get includes string #get includes string
IncludesStr(${C_COMP} inclist) IncludesStr(${C_COMP} __inclist)
#IncludesStr(${C_COMP} ${${inclist}})
message(STATUS "incstr is ${incstr}") message(STATUS "incstr is ${incstr}")
execute_process( execute_process(
COMMAND luajit generator.lua ${C_COMP} "internal noimstrv" ${platbk} ${rendbk} ${incstr} COMMAND luajit generator.lua ${C_COMP} "internal noimstrv" ${platbk} ${rendbk} ${incstr}
@@ -59,6 +61,7 @@ function(GenerateCimguiBindings target platbk rendbk inclist)
RESULT_VARIABLE build_command_result RESULT_VARIABLE build_command_result
) )
if(NOT ${build_command_result} EQUAL 0) if(NOT ${build_command_result} EQUAL 0)
message(STATUS "cimgui generation failed: Do you have LuaJIT?")
message(STATUS "cimgui generation failed: ${build_command_result}") message(STATUS "cimgui generation failed: ${build_command_result}")
message(FATAL_ERROR "error_command: ${error_command}") message(FATAL_ERROR "error_command: ${error_command}")
endif() endif()
@@ -87,5 +90,4 @@ function(GenerateCimguiBindings target platbk rendbk inclist)
target_compile_definitions(${target} PUBLIC "-DIMGUI_IMPL_API=extern \"C\" ") target_compile_definitions(${target} PUBLIC "-DIMGUI_IMPL_API=extern \"C\" ")
endif(WIN32) endif(WIN32)
target_compile_features(${target} PRIVATE cxx_std_11) target_compile_features(${target} PRIVATE cxx_std_11)
#target_link_libraries(${target} PRIVATE SDL3::SDL3)
endfunction() endfunction()

View File

@@ -1,109 +1,44 @@
Project(cimgui_glfwdx11)
cmake_minimum_required(VERSION 3.11) cmake_minimum_required(VERSION 3.11)
if(WIN32) # to mingw work as all the others project(cimgui_glfwdx11 LANGUAGES C CXX)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif(WIN32)
#run in build dir set(CMAKE_C_STANDARD 11)
set (CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
set (CMAKE_CXX_STANDARD 11) include(FetchContent)
# general settings
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../imgui/backends)
set(BAKENDS_FOLDER "../../imgui/backends/")
else()
set(BAKENDS_FOLDER "../../imgui/examples/")
endif()
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../imgui/imgui_tables.cpp)
set(TABLES_SOURCE "../../imgui/imgui_tables.cpp")
else()
set(TABLES_SOURCE "")
endif()
include_directories(../../imgui)
add_definitions("-DIMGUI_USER_CONFIG=\"../cimconfig.h\"")
add_definitions("-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1")
include_directories(../../)
set(IMGUI_SOURCES
../../cimgui.cpp
../../imgui/imgui.cpp
../../imgui/imgui_draw.cpp
../../imgui/imgui_demo.cpp
../../imgui/imgui_widgets.cpp
${TABLES_SOURCE}
)
set(IMGUI_LIBRARIES )
if (WIN32)
add_definitions("-DIMGUI_IMPL_API=extern \"C\" __declspec\(dllexport\)")
else(WIN32)
add_definitions("-DIMGUI_IMPL_API=extern \"C\" ")
endif(WIN32)
add_compile_definitions("IMGUI_IMPL_OPENGL_LOADER_GL3W")
# optional adding freetype
option(IMGUI_FREETYPE "add Freetype2" OFF)
if(IMGUI_FREETYPE)
FIND_PACKAGE(freetype REQUIRED PATHS ${FREETYPE_PATH})
list(APPEND IMGUI_LIBRARIES freetype)
list(APPEND IMGUI_SOURCES ../../imgui/misc/freetype/imgui_freetype.cpp)
add_definitions("-DCIMGUI_FREETYPE=1")
endif(IMGUI_FREETYPE)
# dx11
list(APPEND IMGUI_SOURCES ${BAKENDS_FOLDER}imgui_impl_dx11.cpp)
if(WIN32)
list(APPEND IMGUI_LIBRARIES opengl32)
else(WIN32) # Unix
list(APPEND IMGUI_LIBRARIES GL)
endif(WIN32)
# GLFW
list(APPEND IMGUI_SOURCES ${BAKENDS_FOLDER}imgui_impl_glfw.cpp)
set(GLFW_VERSION 3.3.8) set(GLFW_VERSION 3.3.8)
include(FetchContent) FetchContent_Declare(
FetchContent_Declare(
glfw glfw
URL https://github.com/glfw/glfw/archive/refs/tags/${GLFW_VERSION}.tar.gz) URL https://github.com/glfw/glfw/archive/refs/tags/${GLFW_VERSION}.tar.gz
GIT_PROGRESS true)
FetchContent_GetProperties(glfw) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
if (NOT glfw_POPULATED) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(FETCHCONTENT_QUIET NO) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_Populate(glfw) if (NOT STATIC_BUILD)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
if (NOT STATIC_BUILD)
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
endif()
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR} EXCLUDE_FROM_ALL)
endif() endif()
#add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR} EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(glfw)
install(TARGETS glfw RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR} install(TARGETS glfw RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
LIBRARY DESTINATION ${CMAKE_CURRENT_BINARY_DIR} LIBRARY DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
) )
#FIND_PACKAGE(glfw3 PATHS "C:/LuaGL/gitsources/BUILDS/GLFW/install")
if (NOT STATIC_BUILD) include(../cmake/GenerateCimguiBindings.cmake)
add_library(cimgui SHARED ${IMGUI_SOURCES})
else()
add_library(cimgui STATIC ${IMGUI_SOURCES})
endif()
target_link_libraries(cimgui ${IMGUI_LIBRARIES} glfw) set(inclulist "")
GenerateCimguiBindings(cimgui_with_backend "glfw" dx11 inclulist)
target_link_libraries(cimgui_with_backend PRIVATE glfw d3dcompiler dwmapi)
# using library
add_executable(${PROJECT_NAME} main.c)
target_compile_definitions(${PROJECT_NAME} PUBLIC -DCIMGUI_USE_DX11 -DCIMGUI_USE_GLFW)
target_link_libraries(${PROJECT_NAME} d3d11 d3dcompiler.lib cimgui)
add_executable(${PROJECT_NAME}
main.c
)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw cimgui_with_backend d3d11 d3dcompiler dwmapi)
target_compile_definitions(
${PROJECT_NAME}
PRIVATE
CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1
CIMGUI_USE_GLFW=1
CIMGUI_USE_DX11=1
)

View File

@@ -1,6 +1,7 @@
# GLFWDX11
This example needs dx11 in generation before compile. (add dx11 to generator.bat(sh) and generate) This example needs dx11 in generation before compile.
Generation will be done from cmake but you need LuaJIT in the system.
`STATIC_BUILD` is the cmake variable to do static linking `STATIC_BUILD` is the cmake variable to do static linking
Only tested with VC nmake.

View File

@@ -1,4 +1,4 @@
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS //#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS is done in cmake
#include "cimgui.h" #include "cimgui.h"
#include "cimgui_impl.h" #include "cimgui_impl.h"
#define D3D11_NO_HELPERS #define D3D11_NO_HELPERS

View File

@@ -13,10 +13,10 @@ FetchContent_Declare(
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE) set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(sdl3) FetchContent_MakeAvailable(sdl3)
include(GenerateCimguiBindings.cmake) include(../cmake/GenerateCimguiBindings.cmake)
set(inclist ${sdl3_SOURCE_DIR}/include) set(inclulist ${sdl3_SOURCE_DIR}/include)
GenerateCimguiBindings(cimgui_with_backend sdl3 sdlgpu3 "${inclist}") GenerateCimguiBindings(cimgui_with_backend sdl3 sdlgpu3 inclulist)
target_link_libraries(cimgui_with_backend PRIVATE SDL3::SDL3) target_link_libraries(cimgui_with_backend PRIVATE SDL3::SDL3)
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME}