Skip to content

Commit dad977b

Browse files
committed
Find Qt5 or Qt6 based on the QT_VERSION variable passed
1 parent 0fa067a commit dad977b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

CMakeLists.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ set(CMAKE_CXX_STANDARD 11)
1111
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1212

1313
# Find Qt
14-
find_package(Qt6 COMPONENTS Core Gui Network SerialPort Widgets REQUIRED)
15-
find_package(Qt5 COMPONENTS Core Gui Network SerialPort Widgets)
16-
17-
if(Qt6_FOUND)
18-
set(QT_VERSION 6)
19-
message(STATUS "Using Qt 6")
14+
if(QT_VERSION EQUAL 6)
15+
find_package(Qt6 COMPONENTS Core Gui Network SerialPort Widgets)
2016
set(QT_LIBS Qt6::Core Qt6::Gui Qt6::Network Qt6::SerialPort Qt6::Widgets)
21-
else()
22-
set(QT_VERSION 5)
23-
message(STATUS "Using Qt 5")
17+
message(STATUS "Using Qt 6")
18+
elseif(QT_VERSION EQUAL 5)
19+
find_package(Qt5 COMPONENTS Core Gui Network SerialPort Widgets)
2420
set(QT_LIBS Qt5::Core Qt5::Gui Qt5::Network Qt5::SerialPort Qt5::Widgets)
21+
message(STATUS "Using Qt 5")
22+
else()
23+
message(FATAL_ERROR "QT_VERSION not specified or invalid. Use -DQT_VERSION=5 or -DQT_VERSION=6")
2524
endif()
2625

2726
# Add source files

0 commit comments

Comments
 (0)