Allow disabling Dear ImGui integration in CMake

and do it automatically when using SDL1.2, as it requires SDL2
(or SDL3 once we support it)
This commit is contained in:
Daniel Gibson 2024-06-02 14:07:29 +02:00
parent ecee402927
commit 10312f6998
2 changed files with 26 additions and 6 deletions

View file

@ -56,6 +56,7 @@ endif()
option(DEDICATED "Build the dedicated server" OFF) option(DEDICATED "Build the dedicated server" OFF)
option(ONATIVE "Optimize for the host CPU" OFF) option(ONATIVE "Optimize for the host CPU" OFF)
option(SDL2 "Use SDL2 instead of SDL1.2" ON) option(SDL2 "Use SDL2 instead of SDL1.2" ON)
option(IMGUI "Build with Dear ImGui integration - requires SDL2 and C++11" ON)
option(REPRODUCIBLE_BUILD "Replace __DATE__ and __TIME__ by hardcoded values for reproducible builds" OFF) option(REPRODUCIBLE_BUILD "Replace __DATE__ and __TIME__ by hardcoded values for reproducible builds" OFF)
option(HARDLINK_GAME "Compile gamecode into executable (no game DLLs)" OFF) option(HARDLINK_GAME "Compile gamecode into executable (no game DLLs)" OFF)
@ -71,10 +72,6 @@ if(NOT MSVC) # GCC/clang or compatible, hopefully
endif() endif()
endif() endif()
# we need C++11 for ImGui
# TODO: if we allow disabling ImGui, we could disable setting the c++ standard - or maybe just embrace C++11?
set (CMAKE_CXX_STANDARD 11)
if(NOT CMAKE_SYSTEM_PROCESSOR) if(NOT CMAKE_SYSTEM_PROCESSOR)
message(FATAL_ERROR "No target CPU architecture set") message(FATAL_ERROR "No target CPU architecture set")
endif() endif()
@ -222,6 +219,20 @@ if(REPRODUCIBLE_BUILD)
add_definitions(-DID_REPRODUCIBLE_BUILD) add_definitions(-DID_REPRODUCIBLE_BUILD)
endif() endif()
if(IMGUI)
if(SDL2)
# we need C++11 for ImGui
set (CMAKE_CXX_STANDARD 11)
message(STATUS "Dear ImGui integration enabled")
else()
message(WARNING "Disabling IMGUI because SDL1.2 is used - it needs SDL2!")
set(IMGUI OFF)
add_definitions(-DIMGUI_DISABLE)
endif()
else()
message(STATUS "Dear ImGui integration disabled")
add_definitions(-DIMGUI_DISABLE)
endif()
find_package(CURL QUIET) find_package(CURL QUIET)
if(CURL_FOUND) if(CURL_FOUND)
@ -757,6 +768,7 @@ set(src_idlib
add_globbed_headers(src_idlib "idlib") add_globbed_headers(src_idlib "idlib")
if(IMGUI)
set(src_imgui set(src_imgui
libs/imgui/backends/imgui_impl_sdl2.cpp libs/imgui/backends/imgui_impl_sdl2.cpp
libs/imgui/backends/imgui_impl_opengl2.cpp libs/imgui/backends/imgui_impl_opengl2.cpp
@ -773,6 +785,9 @@ set(src_imgui
sys/sys_imgui.cpp sys/sys_imgui.cpp
sys/imgui_savestyle.cpp sys/imgui_savestyle.cpp
) )
else()
set(src_imgui sys/sys_imgui.h)
endif()
set(src_game set(src_game

View file

@ -1,9 +1,9 @@
#ifndef IMGUI_DISABLE
#define IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS
#include "Common.h" #include "Common.h"
#ifndef IMGUI_DISABLE
#include "idlib/LangDict.h" #include "idlib/LangDict.h"
@ -2386,6 +2386,11 @@ void Com_Dhewm3Settings_f( const idCmdArgs &args )
#else // IMGUI_DISABLE - just a stub function #else // IMGUI_DISABLE - just a stub function
void Com_Dhewm3Settings_f( const idCmdArgs &args ) {} #include "Common.h"
void Com_Dhewm3Settings_f( const idCmdArgs &args )
{
common->Warning( "Dear ImGui is disabled in this build, so the dhewm3 settings menu is not available!" );
}
#endif #endif