myx/MyxCMake/lib/macro/FindQt.cmake

41 lines
1.0 KiB
CMake

include_guard(GLOBAL)
macro(myx_find_qt)
set(options REQUIRED)
set(oneValueArgs VERSION)
set(multiValueArgs COMPONENTS PRIVATE)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_VERSION)
set(ARG_VERSION "5")
if(QT_DEFAULT_MAJOR_VERSION)
set(ARG_VERSION "${QT_DEFAULT_MAJOR_VERSION}")
endif()
endif()
if(ARG_REQUIRED)
set(ARG_REQUIRED "REQUIRED")
endif()
if(NOT (ARG_VERSION STREQUAL "5" OR ARG_VERSION STREQUAL "6"))
message(FATAL_ERROR "Supported Qt versions are 5 and 6")
endif()
foreach(iter ${ARG_COMPONENTS})
find_package(Qt${ARG_VERSION} COMPONENTS ${iter} ${ARG_REQUIRED})
endforeach()
foreach(iter ${ARG_PRIVATE})
find_package("Qt${ARG_VERSION}${iter}" COMPONENTS Private ${ARG_REQUIRED})
endforeach()
foreach(iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()