Skip to content

Commit

Permalink
Project: Explicit cmake qt major version option
Browse files Browse the repository at this point in the history
  • Loading branch information
jdupak committed Jul 12, 2024
1 parent 0280e9e commit 5995b0e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ set(PACKAGE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/pkg"
CACHE STRING "Absolute path to place generated package files.")
set(FORCE_COLORED_OUTPUT false CACHE BOOL "Always produce ANSI-colored output (GNU/Clang only).")
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker. Leave empty for system default; alternatives are 'gold', 'lld', 'bfd', 'mold'")
set(QT_VERSION_MAJOR "auto" CACHE STRING "Qt major version to use. 5|6|auto")

# =============================================================================
# Generated variables
# =============================================================================

if (NOT "${QT_VERSION_MAJOR}" MATCHES "5|6|auto")
message(FATAL_ERROR "Invalid value for QT_VERSION_MAJOR: ${QT_VERSION_MAJOR} (expected 5, 6 or auto)")
endif ()

if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set(WASM true)
else ()
Expand Down Expand Up @@ -241,7 +246,10 @@ endif ()
# Based on article https://www.steinzone.de/wordpress/how-to-support-both-qt5-and-qt6-using-cmake/
# Cannot use version-less approach due to Qt 5.9.5 support constraint.

find_package(QT NAMES Qt5 Qt6 COMPONENTS Core REQUIRED)
if ("${QT_VERSION_MAJOR}" STREQUAL "auto")
find_package(QT NAMES Qt5 Qt6 COMPONENTS Core REQUIRED)
endif ()

# Normally, we would use variable Qt5 or Qt6 to reference the Qt library. Here we do that through
# this variable based on detected version major of Qt.
set(QtLib "Qt${QT_VERSION_MAJOR}")
Expand Down

0 comments on commit 5995b0e

Please sign in to comment.