Browse Source

Fix Qt5 build compatibility issues

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 2 months ago
parent
commit
96d9dd396d

+ 5 - 21
CMakeLists.txt

@@ -31,6 +31,8 @@ endif()
 
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
+set(CMAKE_AUTOMOC ON)
+
 # engine core moved under game; no separate engine subdir target
 add_subdirectory(render)
 add_subdirectory(game)
@@ -78,27 +80,9 @@ if(QT_VERSION_MAJOR EQUAL 6)
             Qt6::QuickControls2
     )
 else()
-    qt5_add_resources(standard_of_iron "qml_resources"
-        PREFIX "/StandardOfIron"
-        FILES
-            ui/qml/Main.qml
-            ui/qml/MainMenu.qml
-            ui/qml/MapSelect.qml
-            ui/qml/HUD.qml
-            ui/qml/HUDTop.qml
-            ui/qml/HUDBottom.qml
-            ui/qml/HUDVictory.qml
-            ui/qml/GameView.qml
-    )
-    qt5_add_resources(standard_of_iron "assets" 
-        PREFIX "/"
-        FILES
-            assets/shaders/basic.vert
-            assets/shaders/basic.frag
-            assets/shaders/grid.frag
-            assets/maps/test_map.json
-            assets/visuals/unit_visuals.json
-    )
+    qt5_add_resources(qml_resources qml_resources.qrc)
+    qt5_add_resources(assets_resources assets.qrc)
+    target_sources(standard_of_iron PRIVATE ${qml_resources} ${assets_resources})
 endif()
 
 target_link_libraries(standard_of_iron

+ 9 - 0
assets.qrc

@@ -0,0 +1,9 @@
+<RCC>
+    <qresource prefix="/">
+        <file>assets/shaders/basic.vert</file>
+        <file>assets/shaders/basic.frag</file>
+        <file>assets/shaders/grid.frag</file>
+        <file>assets/maps/test_map.json</file>
+        <file>assets/visuals/unit_visuals.json</file>
+    </qresource>
+</RCC>

+ 2 - 2
game/CMakeLists.txt

@@ -9,7 +9,7 @@ add_library(engine_core STATIC
 )
 
 target_include_directories(engine_core PUBLIC .)
-target_link_libraries(engine_core PUBLIC Qt6::Core)
+target_link_libraries(engine_core PUBLIC Qt${QT_VERSION_MAJOR}::Core)
 
 add_library(game_systems STATIC
     systems/movement_system.cpp
@@ -42,4 +42,4 @@ add_library(game_systems STATIC
 )
 
 target_include_directories(game_systems PUBLIC .)
-target_link_libraries(game_systems PUBLIC Qt6::Core Qt6::Gui engine_core render_gl)
+target_link_libraries(game_systems PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui engine_core render_gl)

+ 1 - 0
game/map/terrain_service.cpp

@@ -1,4 +1,5 @@
 #include "terrain_service.h"
+#include <cmath>
 #include "../systems/building_collision_registry.h"
 #include "map_definition.h"
 #include <QDebug>

+ 1 - 0
game/systems/combat_system.cpp

@@ -1,4 +1,5 @@
 #include "combat_system.h"
+#include <cmath>
 #include "../core/component.h"
 #include "../core/event_manager.h"
 #include "../core/world.h"

+ 1 - 0
game/systems/production_system.cpp

@@ -1,4 +1,5 @@
 #include "production_system.h"
+#include <cmath>
 #include "../core/component.h"
 #include "../core/world.h"
 #include "../map/map_transformer.h"

+ 2 - 0
main.cpp

@@ -21,7 +21,9 @@ int main(int argc, char *argv[]) {
   }
   qputenv("QT_OPENGL", "desktop");
   qputenv("QSG_RHI_BACKEND", "opengl");
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
   QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi);
+#endif
 
   QSurfaceFormat fmt;
   fmt.setVersion(3, 3);

+ 12 - 0
qml_resources.qrc

@@ -0,0 +1,12 @@
+<RCC>
+    <qresource prefix="/StandardOfIron">
+        <file>ui/qml/Main.qml</file>
+        <file>ui/qml/MainMenu.qml</file>
+        <file>ui/qml/MapSelect.qml</file>
+        <file>ui/qml/HUD.qml</file>
+        <file>ui/qml/HUDTop.qml</file>
+        <file>ui/qml/HUDBottom.qml</file>
+        <file>ui/qml/HUDVictory.qml</file>
+        <file>ui/qml/GameView.qml</file>
+    </qresource>
+</RCC>

+ 1 - 1
render/CMakeLists.txt

@@ -30,4 +30,4 @@ add_library(render_gl STATIC
 )
 
 target_include_directories(render_gl PUBLIC .)
-target_link_libraries(render_gl PUBLIC Qt6::Core Qt6::OpenGL ${OPENGL_LIBRARIES} engine_core)
+target_link_libraries(render_gl PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::OpenGL ${OPENGL_LIBRARIES} engine_core)

+ 1 - 0
render/geom/selection_ring.cpp

@@ -1,5 +1,6 @@
 #include "selection_ring.h"
 #include <QVector3D>
+#include <cmath>
 
 namespace Render::Geom {
 

+ 13 - 6
tools/map_editor/CMakeLists.txt

@@ -1,12 +1,19 @@
-qt6_add_executable(map_editor
-    main.cpp
-    editor_window.cpp
-)
+if(QT_VERSION_MAJOR EQUAL 6)
+    qt6_add_executable(map_editor
+        main.cpp
+        editor_window.cpp
+    )
+else()
+    add_executable(map_editor
+        main.cpp
+        editor_window.cpp
+    )
+endif()
 
 target_link_libraries(map_editor
     PRIVATE
-    Qt6::Core
-    Qt6::Widgets
+    Qt${QT_VERSION_MAJOR}::Core
+    Qt${QT_VERSION_MAJOR}::Widgets
     engine_core
     render_gl
 )