From 10312f699833c73e9b343184c20fd82b65267d81 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 2 Jun 2024 14:07:29 +0200 Subject: [PATCH] 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) --- neo/CMakeLists.txt | 23 +++++++++++++++++++---- neo/framework/Dhewm3SettingsMenu.cpp | 9 +++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index bec62303..fc8c3c98 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -56,6 +56,7 @@ endif() option(DEDICATED "Build the dedicated server" OFF) option(ONATIVE "Optimize for the host CPU" OFF) 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(HARDLINK_GAME "Compile gamecode into executable (no game DLLs)" OFF) @@ -71,10 +72,6 @@ if(NOT MSVC) # GCC/clang or compatible, hopefully 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) message(FATAL_ERROR "No target CPU architecture set") endif() @@ -222,6 +219,20 @@ if(REPRODUCIBLE_BUILD) add_definitions(-DID_REPRODUCIBLE_BUILD) 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) if(CURL_FOUND) @@ -757,6 +768,7 @@ set(src_idlib add_globbed_headers(src_idlib "idlib") +if(IMGUI) set(src_imgui libs/imgui/backends/imgui_impl_sdl2.cpp libs/imgui/backends/imgui_impl_opengl2.cpp @@ -773,6 +785,9 @@ set(src_imgui sys/sys_imgui.cpp sys/imgui_savestyle.cpp ) +else() +set(src_imgui sys/sys_imgui.h) +endif() set(src_game diff --git a/neo/framework/Dhewm3SettingsMenu.cpp b/neo/framework/Dhewm3SettingsMenu.cpp index 5c1df4f3..1d746f6e 100644 --- a/neo/framework/Dhewm3SettingsMenu.cpp +++ b/neo/framework/Dhewm3SettingsMenu.cpp @@ -1,9 +1,9 @@ +#ifndef IMGUI_DISABLE #define IMGUI_DEFINE_MATH_OPERATORS #include "Common.h" -#ifndef IMGUI_DISABLE #include "idlib/LangDict.h" @@ -2386,6 +2386,11 @@ void Com_Dhewm3Settings_f( const idCmdArgs &args ) #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