From 71db168277f37f22e4e70445005264fdb4ba9dbc Mon Sep 17 00:00:00 2001 From: Marek Rusinowski Date: Wed, 27 Sep 2023 23:16:20 +0200 Subject: [PATCH] Add RmlUi to build system Not all is ready and there will be more work needed on build system, but the basic integration of RmlUi Core is done. - I've not created and linked any of the provided GL3 or SDL backends, that needs separate work - Lua bindings are blocked on https://github.com/mikke89/RmlUi/issues/302 we need to find some workaround for that - Tracy integration is blocked on https://github.com/mikke89/RmlUi/issues/516 --- .gitmodules | 3 +++ CMakeLists.txt | 3 +++ rts/System/SpringApp.cpp | 17 +++++++++++++++++ rts/builds/headless/CMakeLists.txt | 1 + rts/builds/legacy/CMakeLists.txt | 2 ++ rts/lib/CMakeLists.txt | 17 +++++++++++++++++ rts/lib/RmlUi | 1 + 7 files changed, 44 insertions(+) create mode 160000 rts/lib/RmlUi diff --git a/.gitmodules b/.gitmodules index d3e69d8daa..32c4e8429a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -30,3 +30,6 @@ [submodule "rts/lib/cereal"] path = rts/lib/cereal url = https://github.com/USCiLab/cereal.git +[submodule "rts/lib/RmlUi"] + path = rts/lib/RmlUi + url = https://github.com/mikke89/RmlUi.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6459eda087..81f2336482 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,9 @@ else() set(JAVA_COMPILE_FLAG_CONDITIONAL "-g:lines,source") endif() +# By default, the libraries that don't explicily specify SHARED/STATIC are build statically. +# See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html +option(BUILD_SHARED_LIBS "Build shared (dynamic) libraries" OFF) # Tell windows to pass arguments around in @response files # (32k arg limit workaround) diff --git a/rts/System/SpringApp.cpp b/rts/System/SpringApp.cpp index 7a152d9641..df98e6bef9 100644 --- a/rts/System/SpringApp.cpp +++ b/rts/System/SpringApp.cpp @@ -6,6 +6,9 @@ #include #include +// Include before other headers that define a bunch of macros that break stuff. +#include + #include #include @@ -216,6 +219,17 @@ SpringApp::~SpringApp() spring_clock::PopTickRate(); } +class DummyRmlUiSpringSystemInterface : public Rml::SystemInterface { +public: + double GetElapsedTime() override { + return 0.0; + } + +private: + std::chrono::steady_clock::time_point start; +}; + +static DummyRmlUiSpringSystemInterface dummyRmlUiSpringSystemInterface; /** * @brief Initializes the SpringApp instance @@ -241,6 +255,9 @@ bool SpringApp::Init() Watchdog::Install(); Watchdog::RegisterThread(WDT_MAIN, true); + // A dummy call to basic RmlUi function to verify that all is linking correctly. + Rml::SetSystemInterface(&dummyRmlUiSpringSystemInterface); + // Create Window if (!InitWindow(("Spring " + SpringVersion::GetSync()).c_str())) { SDL_Quit(); diff --git a/rts/builds/headless/CMakeLists.txt b/rts/builds/headless/CMakeLists.txt index 4cfeb536ca..41cfe619de 100644 --- a/rts/builds/headless/CMakeLists.txt +++ b/rts/builds/headless/CMakeLists.txt @@ -27,6 +27,7 @@ list(APPEND engineHeadlessLibraries ${engineCommonLibraries}) list(APPEND engineHeadlessLibraries no-sound) list(APPEND engineHeadlessLibraries engineSim) list(APPEND engineHeadlessLibraries pr-downloader) +list(APPEND engineHeadlessLibraries RmlCore) include_directories(${ENGINE_SRC_ROOT_DIR}/lib/assimp/include) include_directories(${ENGINE_SRC_ROOT_DIR}/lib/asio/include) diff --git a/rts/builds/legacy/CMakeLists.txt b/rts/builds/legacy/CMakeLists.txt index ba43e7f522..edf8c68767 100644 --- a/rts/builds/legacy/CMakeLists.txt +++ b/rts/builds/legacy/CMakeLists.txt @@ -36,6 +36,7 @@ if (FONTCONFIG_FOUND) endif (PREFER_STATIC_LIBS) endif (FONTCONFIG_FOUND) +# !!! If you change freetype resolution here, change it also in rts/lib find_freetype_hack() # hack to find different named freetype.dll find_package_static(Freetype REQUIRED) foreach(f ${FREETYPE_INCLUDE_DIRS}) @@ -64,6 +65,7 @@ list(APPEND engineLibraries ${engineCommonLibraries}) list(APPEND engineLibraries ${SPRING_SIM_LIBRARIES}) list(APPEND engineLibraries engineSim) list(APPEND engineLibraries pr-downloader) +list(APPEND engineLibraries RmlCore) ### Assemble external incude dirs list(APPEND engineIncludes ${OPENAL_INCLUDE_DIR}) diff --git a/rts/lib/CMakeLists.txt b/rts/lib/CMakeLists.txt index e64914ace7..3eb7137c52 100644 --- a/rts/lib/CMakeLists.txt +++ b/rts/lib/CMakeLists.txt @@ -85,3 +85,20 @@ option(TRACY_ON_DEMAND "Enable tracy profiling" ON) option(TRACY_PROFILE_MEMORY "Profile memory allocations" OFF) add_subdirectory(tracy) + +# TODO(p2004): Enabling tracy for RmlUi is at the momemnt broken and waits for +# resolution upstream https://github.com/mikke89/RmlUi/issues/516. +# if (TRACY_ENABLE) +# set(ENABLE_TRACY_PROFILING ON CACHE BOOL "Enable RmlUi tracy profiling") +# # Place the include directories for tracy in TRACY_INCLUDE_DIR as that's +# # what RmlUi expects to be set in their FindTracy.cmake +# get_target_property(TRACY_INCLUDE_DIR TracyClient INCLUDE_DIRECTORIES) +# endif() + +# We resolve freetype here to make sure RmlUi find_package picks the same +# correct version as picked by the engine. +# !!! If you change freetype resolution here, change it also in rts/builds/legacy +find_freetype_hack() # hack to find different named freetype.dll +find_package_static(Freetype REQUIRED) + +add_subdirectory(RmlUi) diff --git a/rts/lib/RmlUi b/rts/lib/RmlUi new file mode 160000 index 0000000000..a602da2440 --- /dev/null +++ b/rts/lib/RmlUi @@ -0,0 +1 @@ +Subproject commit a602da244048f99fa1730194c8479b377227f7c6