myx/MyxCMake/lib/macro/FindQt.cmake

41 lines
1.0 KiB
CMake
Raw Normal View History

2023-08-01 08:21:33 +00:00
include_guard(GLOBAL)
macro(myx_find_qt)
2023-08-01 08:42:24 +00:00
set(options REQUIRED)
2023-08-01 08:21:33 +00:00
set(oneValueArgs VERSION)
set(multiValueArgs COMPONENTS PRIVATE)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
2023-08-01 08:42:24 +00:00
if(NOT ARG_VERSION)
set(ARG_VERSION "5")
2023-08-01 08:21:33 +00:00
if(QT_DEFAULT_MAJOR_VERSION)
2023-08-01 08:42:24 +00:00
set(ARG_VERSION "${QT_DEFAULT_MAJOR_VERSION}")
2023-08-01 08:21:33 +00:00
endif()
endif()
2023-08-01 08:42:24 +00:00
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")
2023-08-01 08:21:33 +00:00
endif()
foreach(iter ${ARG_COMPONENTS})
2023-08-01 08:42:24 +00:00
find_package(Qt${ARG_VERSION} COMPONENTS ${iter} ${ARG_REQUIRED})
2023-08-01 08:21:33 +00:00
endforeach()
foreach(iter ${ARG_PRIVATE})
2023-08-01 08:42:24 +00:00
find_package("Qt${ARG_VERSION}${iter}" COMPONENTS Private ${ARG_REQUIRED})
2023-08-01 08:21:33 +00:00
endforeach()
foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${__iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()