From fcf83f3e36d98c0f896704424622809bddf3d53c Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Thu, 28 Oct 2021 23:38:08 +0300 Subject: [PATCH] Use QT_DEFAULT_MAJOR_VERSION --- .github/workflows/build.yml | 2 +- CMakeLists.txt | 20 +++++++++++--------- HotkeyTest/CMakeLists.txt | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 91171e8..7affb86 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: platform: [ubuntu-20.04, windows-latest, macos-latest] include: - qt_version: 6.2.0 - additional_arguments: -D QT_MAJOR=6 + additional_arguments: -D QT_DEFAULT_MAJOR_VERSION=6 - platform: ubuntu-20.04 make: make CXXFLAGS: -Wall -Wextra -pedantic -Werror diff --git a/CMakeLists.txt b/CMakeLists.txt index 57880a7..641aafc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,18 +8,20 @@ option(QHOTKEY_INSTALL "Enable install rule" ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_AUTOMOC ON) -set(QT_MAJOR 5 CACHE STRING "Qt major version to use") +if(NOT QT_DEFAULT_MAJOR_VERSION) + set(QT_DEFAULT_MAJOR_VERSION 5 CACHE STRING "Qt version to use (5 or 6), defaults to 5") +endif() -if(QT_MAJOR EQUAL 6) - find_package(Qt${QT_MAJOR} 6.2.0 COMPONENTS Core Gui REQUIRED) +if(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + find_package(Qt${QT_DEFAULT_MAJOR_VERSION} 6.2.0 COMPONENTS Core Gui REQUIRED) else() - find_package(Qt${QT_MAJOR} COMPONENTS Core Gui REQUIRED) + find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS Core Gui REQUIRED) endif() add_library(qhotkey QHotkey/qhotkey.cpp) add_library(QHotkey::QHotkey ALIAS qhotkey) -target_link_libraries(qhotkey PUBLIC Qt${QT_MAJOR}::Core) -target_link_libraries(qhotkey PRIVATE Qt${QT_MAJOR}::Gui) +target_link_libraries(qhotkey PUBLIC Qt${QT_DEFAULT_MAJOR_VERSION}::Core) +target_link_libraries(qhotkey PRIVATE Qt${QT_DEFAULT_MAJOR_VERSION}::Gui) if(BUILD_SHARED_LIBS) target_compile_definitions(qhotkey PRIVATE QHOTKEY_LIBRARY) @@ -36,14 +38,14 @@ elseif(WIN32) target_sources(qhotkey PRIVATE QHotkey/qhotkey_win.cpp) else() find_package(X11 REQUIRED) - if(QT_MAJOR GREATER_EQUAL 6) + if(QT_DEFAULT_MAJOR_VERSION GREATER_EQUAL 6) target_link_libraries(qhotkey PRIVATE ${X11_LIBRARIES}) else() - find_package(Qt${QT_MAJOR} COMPONENTS X11Extras REQUIRED) + find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS X11Extras REQUIRED) target_link_libraries(qhotkey PRIVATE ${X11_LIBRARIES} - Qt${QT_MAJOR}::X11Extras) + Qt${QT_DEFAULT_MAJOR_VERSION}::X11Extras) endif() include_directories(${X11_INCLUDE_DIR}) diff --git a/HotkeyTest/CMakeLists.txt b/HotkeyTest/CMakeLists.txt index 17d3f2e..714585d 100644 --- a/HotkeyTest/CMakeLists.txt +++ b/HotkeyTest/CMakeLists.txt @@ -7,5 +7,5 @@ add_executable(HotkeyTest hottestwidget.cpp hottestwidget.ui) -find_package(Qt${QT_MAJOR} COMPONENTS Widgets REQUIRED) -target_link_libraries(HotkeyTest Qt${QT_MAJOR}::Widgets QHotkey::QHotkey) +find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS Widgets REQUIRED) +target_link_libraries(HotkeyTest Qt${QT_DEFAULT_MAJOR_VERSION}::Widgets QHotkey::QHotkey)