mirror of
https://github.com/cimgui/cimgui.git
synced 2025-10-09 19:21:39 +01:00
Compare commits
2 Commits
0992dbf89c
...
08677d259c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
08677d259c | ||
![]() |
8f15ab3f80 |
@@ -1,8 +1,11 @@
|
||||
# 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
|
||||
# into your project, or refit it to your needs.
|
||||
|
||||
#include(CMakePrintHelpers)
|
||||
|
||||
function(IncludesStr comp includes)
|
||||
#message("includes is ${includes}")
|
||||
#cmake_print_variables(includes)
|
||||
if("${comp}" STREQUAL "cl")
|
||||
set(Ist "/I")
|
||||
else()
|
||||
@@ -10,18 +13,18 @@ function(IncludesStr comp includes)
|
||||
endif()
|
||||
set(incstr "")
|
||||
foreach(inc ${${includes}})
|
||||
#message("inc is ${inc}")
|
||||
set(incstr ${Ist}${inc} ${incstr})
|
||||
set(incstr ${incstr} ${Ist}${inc})
|
||||
endforeach()
|
||||
set(incstr ${incstr} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
include(CMakePrintHelpers)
|
||||
|
||||
function(GenerateCimguiBindings target platbk rendbk inclist)
|
||||
|
||||
function(GenerateCimguiBindings target platbk rendbk _inclist)
|
||||
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
|
||||
FetchContent_Declare(
|
||||
cimgui
|
||||
@@ -41,16 +44,15 @@ function(GenerateCimguiBindings target platbk rendbk inclist)
|
||||
# since this will be executed on each "configure" (whenever you run cmake)
|
||||
string(TOUPPER ${platbk} PLATBK)
|
||||
string(TOUPPER ${rendbk} RENDBK)
|
||||
string(FIND "${cimgui_impl}" ${RENDBK} rendbk_position)
|
||||
string(FIND "${cimgui_impl}" ${PLATBK} platbk_position)
|
||||
string(FIND "${cimgui_impl}" CIMGUI_USE_${RENDBK} rendbk_position)
|
||||
string(FIND "${cimgui_impl}" CIMGUI_USE_${PLATBK} platbk_position)
|
||||
# If we don't find it, rendbk_position will be -1
|
||||
if(rendbk_position EQUAL -1 OR platbk_position EQUAL -1)
|
||||
#get compiler name
|
||||
cmake_path(GET CMAKE_C_COMPILER FILENAME C_COMP)
|
||||
cmake_path(REMOVE_EXTENSION C_COMP)
|
||||
#get includes string
|
||||
IncludesStr(${C_COMP} inclist)
|
||||
#IncludesStr(${C_COMP} ${${inclist}})
|
||||
IncludesStr(${C_COMP} __inclist)
|
||||
message(STATUS "incstr is ${incstr}")
|
||||
execute_process(
|
||||
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
|
||||
)
|
||||
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(FATAL_ERROR "error_command: ${error_command}")
|
||||
endif()
|
||||
@@ -87,5 +90,4 @@ function(GenerateCimguiBindings target platbk rendbk inclist)
|
||||
target_compile_definitions(${target} PUBLIC "-DIMGUI_IMPL_API=extern \"C\" ")
|
||||
endif(WIN32)
|
||||
target_compile_features(${target} PRIVATE cxx_std_11)
|
||||
#target_link_libraries(${target} PRIVATE SDL3::SDL3)
|
||||
endfunction()
|
@@ -1,109 +1,44 @@
|
||||
Project(cimgui_glfwdx11)
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
if(WIN32) # to mingw work as all the others
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
endif(WIN32)
|
||||
project(cimgui_glfwdx11 LANGUAGES C CXX)
|
||||
|
||||
#run in build dir
|
||||
set (CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
# 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)
|
||||
include(FetchContent)
|
||||
|
||||
set(GLFW_VERSION 3.3.8)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
FetchContent_Declare(
|
||||
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)
|
||||
if (NOT glfw_POPULATED)
|
||||
set(FETCHCONTENT_QUIET NO)
|
||||
FetchContent_Populate(glfw)
|
||||
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(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)
|
||||
endif()
|
||||
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
#add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
|
||||
FetchContent_MakeAvailable(glfw)
|
||||
install(TARGETS glfw RUNTIME 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)
|
||||
add_library(cimgui SHARED ${IMGUI_SOURCES})
|
||||
else()
|
||||
add_library(cimgui STATIC ${IMGUI_SOURCES})
|
||||
endif()
|
||||
include(../cmake/GenerateCimguiBindings.cmake)
|
||||
|
||||
target_link_libraries(cimgui ${IMGUI_LIBRARIES} glfw)
|
||||
|
||||
|
||||
# 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)
|
||||
set(inclulist "")
|
||||
GenerateCimguiBindings(cimgui_with_backend "glfw" dx11 inclulist)
|
||||
target_link_libraries(cimgui_with_backend PRIVATE glfw d3dcompiler dwmapi)
|
||||
|
||||
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
|
||||
)
|
||||
|
@@ -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
|
||||
|
||||
Only tested with VC nmake.
|
@@ -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_impl.h"
|
||||
#define D3D11_NO_HELPERS
|
||||
|
@@ -13,10 +13,10 @@ FetchContent_Declare(
|
||||
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(sdl3)
|
||||
|
||||
include(GenerateCimguiBindings.cmake)
|
||||
include(../cmake/GenerateCimguiBindings.cmake)
|
||||
|
||||
set(inclist ${sdl3_SOURCE_DIR}/include)
|
||||
GenerateCimguiBindings(cimgui_with_backend sdl3 sdlgpu3 "${inclist}")
|
||||
set(inclulist ${sdl3_SOURCE_DIR}/include)
|
||||
GenerateCimguiBindings(cimgui_with_backend sdl3 sdlgpu3 inclulist)
|
||||
target_link_libraries(cimgui_with_backend PRIVATE SDL3::SDL3)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
|
Reference in New Issue
Block a user