Skip to content

Commit 6168de9

Browse files
Yadunundpaceholder
authored andcommitted
Support Qt5 build
Signed-off-by: Yadunund <yadunund@gmail.com>
1 parent e5c7bc6 commit 6168de9

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

CMakeLists.txt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ add_subdirectory(external)
3737

3838

3939
# Find the QtWidgets library
40-
find_package(Qt6
40+
find_package(Qt6 QUIET
4141
COMPONENTS
4242
Core
4343
Widgets
@@ -46,7 +46,7 @@ find_package(Qt6
4646
)
4747

4848
if (NOT Qt6_FOUND)
49-
find_package(Qt5 5.13
49+
find_package(Qt5 QUIET
5050
COMPONENTS
5151
Core
5252
Widgets
@@ -59,8 +59,13 @@ if (NOT (Qt6_FOUND OR Qt5_FOUND))
5959
message(FATAL_ERRROR "Qt libraries were not found.")
6060
endif()
6161

62-
63-
qt_add_resources(RESOURCES ./resources/resources.qrc)
62+
if (Qt6_FOUND)
63+
qt_add_resources(RESOURCES ./resources/resources.qrc)
64+
set(Qt Qt)
65+
else()
66+
qt5_add_resources(RESOURCES ./resources/resources.qrc)
67+
set(Qt Qt5)
68+
endif()
6469

6570
# Unfortunately, as we have a split include/src, AUTOMOC doesn't work.
6671
# We'll have to manually specify some files
@@ -109,10 +114,10 @@ target_include_directories(nodes
109114

110115
target_link_libraries(nodes
111116
PUBLIC
112-
Qt::Core
113-
Qt::Widgets
114-
Qt::Gui
115-
Qt::OpenGL
117+
${Qt}::Core
118+
${Qt}::Widgets
119+
${Qt}::Gui
120+
${Qt}::OpenGL
116121
)
117122

118123
target_compile_definitions(nodes
@@ -155,11 +160,19 @@ set_target_properties(nodes
155160

156161
file(GLOB_RECURSE HEADERS_TO_MOC include/nodes/internal/*.hpp)
157162

158-
qt_wrap_cpp(nodes_moc
159-
${HEADERS_TO_MOC}
163+
if (Qt6_FOUND)
164+
qt_wrap_cpp(nodes_moc
165+
${HEADERS_TO_MOC}
166+
TARGET nodes
167+
OPTIONS --no-notes # Don't display a note for the headers which don't produce a moc_*.cpp
168+
)
169+
else()
170+
qt5_wrap_cpp(nodes_moc
171+
${HEADERS_TO_MOC}
160172
TARGET nodes
161173
OPTIONS --no-notes # Don't display a note for the headers which don't produce a moc_*.cpp
162-
)
174+
)
175+
endif()
163176

164177
target_sources(nodes PRIVATE ${nodes_moc})
165178

test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ find_package(Catch2 2.3.0 REQUIRED)
22

33
if (Qt6_FOUND)
44
find_package(Qt6 COMPONENTS Test)
5+
set(Qt Qt)
56
else()
67
find_package(Qt5 COMPONENTS Test)
8+
set(Qt Qt5)
79
endif()
810

911
add_executable(test_nodes
@@ -25,7 +27,7 @@ target_link_libraries(test_nodes
2527
PRIVATE
2628
NodeEditor::nodes
2729
Catch2::Catch2
28-
Qt::Test
30+
${Qt}::Test
2931
)
3032

3133
add_test(

0 commit comments

Comments
 (0)