Skip to content

Commit

Permalink
cmake: Simplify Qt5/Qt6 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lnjX committed Feb 26, 2021
1 parent fbd0f24 commit 9a1134a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 28 deletions.
14 changes: 2 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules")

# prefer Qt6
find_package(Qt6 QUIET COMPONENTS Core Network Xml)
if(NOT Qt6_FOUND)
find_package(Qt5 5.7.0 REQUIRED COMPONENTS Core Network Xml)
endif()

# target names have changed from Qt5::Core -> Qt::Core
if(Qt6_FOUND)
set(QT_TARGET Qt)
else()
set(QT_TARGET Qt5)
endif()
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Xml)
find_package(Qt${QT_VERSION_MAJOR} 5.7.0 REQUIRED COMPONENTS Core Network Xml)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
Expand Down
7 changes: 2 additions & 5 deletions examples/example_9_vCard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
find_package(Qt6 QUIET COMPONENTS Gui)
if(NOT Qt6_FOUND)
find_package(Qt5 REQUIRED Gui)
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui)

add_executable(9_vCard example_9_vCard.cpp)
target_link_libraries(9_vCard ${QT_TARGET}::Gui qxmpp)
target_link_libraries(9_vCard Qt${QT_VERSION_MAJOR}::Gui qxmpp)
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ target_include_directories(qxmpp

target_link_libraries(qxmpp
PUBLIC
${QT_TARGET}::Core
${QT_TARGET}::Network
${QT_TARGET}::Xml
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Xml
)

if(WITH_GSTREAMER)
Expand Down
7 changes: 2 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
include_directories(.)

find_package(Qt6 QUIET COMPONENTS Test)
if(NOT Qt6_FOUND)
find_package(Qt5 REQUIRED COMPONENTS Test)
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test)

macro(add_simple_test TEST_NAME)
add_executable(tst_${TEST_NAME} ${TEST_NAME}/tst_${TEST_NAME}.cpp)
add_test(tst_${TEST_NAME} tst_${TEST_NAME})
target_link_libraries(tst_${TEST_NAME} ${QT_TARGET}::Test qxmpp)
target_link_libraries(tst_${TEST_NAME} Qt${QT_VERSION_MAJOR}::Test qxmpp)
endmacro()

include_directories(${PROJECT_SOURCE_DIR}/src/base)
Expand Down
2 changes: 1 addition & 1 deletion tests/qxmpptransfermanager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(tst_qxmpptransfermanager tst_qxmpptransfermanager.cpp tst_qxmpptransfermanager.qrc)
add_test(tst_qxmpptransfermanager tst_qxmpptransfermanager)
target_link_libraries(tst_qxmpptransfermanager ${QT_TARGET}::Test qxmpp)
target_link_libraries(tst_qxmpptransfermanager Qt${QT_VERSION_MAJOR}::Test qxmpp)
2 changes: 1 addition & 1 deletion tests/qxmppuploadrequestmanager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(tst_qxmppuploadrequestmanager tst_qxmppuploadrequestmanager.cpp tst_qxmppuploadrequestmanager.qrc)
add_test(tst_qxmppuploadrequestmanager tst_qxmppuploadrequestmanager)
target_link_libraries(tst_qxmppuploadrequestmanager ${QT_TARGET}::Test qxmpp)
target_link_libraries(tst_qxmppuploadrequestmanager Qt${QT_VERSION_MAJOR}::Test qxmpp)
2 changes: 1 addition & 1 deletion tests/qxmpputils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(tst_qxmpputils tst_qxmpputils.cpp tst_qxmpputils.qrc)
add_test(tst_qxmpputils tst_qxmpputils)
target_link_libraries(tst_qxmpputils ${QT_TARGET}::Test qxmpp)
target_link_libraries(tst_qxmpputils Qt${QT_VERSION_MAJOR}::Test qxmpp)

0 comments on commit 9a1134a

Please sign in to comment.