Warning, /frameworks/extra-cmake-modules/kde-modules/KDEMetaInfoPlatformCheck.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2022 Albert Astals Cid <aacid@kde.org>
0002 #
0003 # SPDX-License-Identifier: BSD-3-Clause
0004 
0005 #[=======================================================================[.rst:
0006 KDEMetaInfoPlatformCheck
0007 ------------------------
0008 
0009 By including this module there will be an automatic check between the supported
0010 platforms listed in the metainfo.yaml file and the current platform
0011 that is the target of the build
0012 
0013 If the current platform that is the target of the build is not supported
0014 a CMake ``FATAL_ERROR`` will be issued
0015 
0016 The check can be ignored by setting ``KF_IGNORE_PLATFORM_CHECK`` to ``ON``.
0017 
0018 Since 5.93
0019 #]=======================================================================]
0020 
0021 option(KF_IGNORE_PLATFORM_CHECK "Ignore the supported platform check against metainfo.yaml" OFF)
0022 if ("$ENV{KF_IGNORE_PLATFORM_CHECK}" STREQUAL "ON")
0023     message(WARNING "KF_IGNORE_PLATFORM_CHECK set to ON from the environment")
0024     set(KF_IGNORE_PLATFORM_CHECK ON)
0025 endif()
0026 
0027 if (NOT "${KF_IGNORE_PLATFORM_CHECK}")
0028     file(STRINGS metainfo.yaml MetaInfoContents)
0029     set(_MetainfoParserInPlatforms false)
0030     set(_MetainfoFoundSupportedPlatform false)
0031     set(_MetainfoSupportedPlatforms "")
0032     foreach(MetaInfoString IN LISTS MetaInfoContents)
0033         if ("${MetaInfoString}" STREQUAL "platforms:")
0034             set(_MetainfoParserInPlatforms true)
0035         elseif(_MetainfoParserInPlatforms AND "${MetaInfoString}" MATCHES ".*name:[ \t\r\n]*(.*)")
0036             list(APPEND _MetainfoSupportedPlatforms ${CMAKE_MATCH_1})
0037             if (${CMAKE_MATCH_1} STREQUAL "Linux")
0038                 if (CMAKE_SYSTEM_NAME MATCHES "Linux")
0039                     set(_MetainfoFoundSupportedPlatform true)
0040                 endif()
0041             elseif (${CMAKE_MATCH_1} STREQUAL "FreeBSD")
0042                 if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
0043                     set(_MetainfoFoundSupportedPlatform true)
0044                 endif()
0045             elseif (${CMAKE_MATCH_1} STREQUAL "OpenBSD")
0046                 if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
0047                     set(_MetainfoFoundSupportedPlatform true)
0048                 endif()
0049             elseif (${CMAKE_MATCH_1} STREQUAL "Windows")
0050                 if (WIN32)
0051                     set(_MetainfoFoundSupportedPlatform true)
0052                 endif()
0053             elseif (${CMAKE_MATCH_1} STREQUAL "macOS")
0054                 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
0055                     set(_MetainfoFoundSupportedPlatform true)
0056                 endif()
0057             elseif (${CMAKE_MATCH_1} STREQUAL "Android")
0058                 if (ANDROID)
0059                     set(_MetainfoFoundSupportedPlatform true)
0060                 endif()
0061             elseif (${CMAKE_MATCH_1} STREQUAL "iOS")
0062                 if (IOS)
0063                     set(_MetainfoFoundSupportedPlatform true)
0064                 endif()
0065             elseif (${CMAKE_MATCH_1} STREQUAL "All")
0066                 set(_MetainfoFoundSupportedPlatform true)
0067             else()
0068                 list(POP_BACK _MetainfoSupportedPlatforms)
0069                 message(WARNING "Found platform not recognized by the metainfo platform parser: ${CMAKE_MATCH_1}")
0070             endif()
0071         elseif("${MetaInfoString}" MATCHES "^[A-Za-z0-9_]+:")
0072             set(_MetainfoParserInPlatforms false)
0073         endif()
0074     endforeach()
0075 
0076     if (NOT _MetainfoFoundSupportedPlatform)
0077         message(FATAL_ERROR "Your current platform '${CMAKE_SYSTEM_NAME}' is not supported. The list of supported platorms is '${_MetainfoSupportedPlatforms}'.If you think this is a mistake or you are working on enabling the platform please build with the KF_IGNORE_PLATFORM_CHECK variable set to true")
0078     endif()
0079 endif()