From 935c2abff7bf531a9758bf2fbdc6b0d8abe636e8 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 16 Feb 2022 14:06:56 +0100 Subject: Check that you're building the framework in a supported platform --- kde-modules/KDEFrameworkCompilerSettings.cmake | 3 ++ kde-modules/KDEMetaInfoPlatformCheck.cmake | 71 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 kde-modules/KDEMetaInfoPlatformCheck.cmake diff --git a/kde-modules/KDEFrameworkCompilerSettings.cmake b/kde-modules/KDEFrameworkCompilerSettings.cmake index de700d7e..3eb640ef 100644 --- a/kde-modules/KDEFrameworkCompilerSettings.cmake +++ b/kde-modules/KDEFrameworkCompilerSettings.cmake @@ -66,3 +66,6 @@ add_definitions( include(KDEClangFormat) file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) + +# add the metainfo platform check +include(KDEMetaInfoPlatformCheck) diff --git a/kde-modules/KDEMetaInfoPlatformCheck.cmake b/kde-modules/KDEMetaInfoPlatformCheck.cmake new file mode 100644 index 00000000..7efcdb7c --- /dev/null +++ b/kde-modules/KDEMetaInfoPlatformCheck.cmake @@ -0,0 +1,71 @@ +# SPDX-FileCopyrightText: 2022 Albert Astals Cid +# +# SPDX-License-Identifier: BSD-3-Clause + +#[=======================================================================[.rst: +KDEMetaInfoPlatformCheck +-------------------- + +By including this module there will be an automatic check between the supported +platforms listed in the metainfo.yaml file and the current platform +that is the target of the build + +If the current platform that is the target of the build is not supported +a cmake FATAL_ERROR will be issued + +The check can be ignored by setting KF_IGNORE_PLATFORM_CHECK to ON + +Since 5.93 +#]=======================================================================] + +option(KF_IGNORE_PLATFORM_CHECK "Ignore the supported platform check against metainfo.yaml" OFF) + +if (NOT "${KF_IGNORE_PLATFORM_CHECK}") + file(STRINGS metainfo.yaml MetaInfoContents) + set(_MetainfoParserInPlatforms false) + set(_MetainfoFoundSupportedPlatform false) + set(_MetainfoSupportedPlatforms "") + foreach(MetaInfoString IN LISTS MetaInfoContents) + if ("${MetaInfoString}" STREQUAL "platforms:") + set(_MetainfoParserInPlatforms true) + elseif(_MetainfoParserInPlatforms AND "${MetaInfoString}" MATCHES ".*name:[ \t\r\n]*(.*)") + list(APPEND _MetainfoSupportedPlatforms ${CMAKE_MATCH_1}) + if (${CMAKE_MATCH_1} STREQUAL "Linux") + if (CMAKE_SYSTEM_NAME MATCHES "Linux") + set(_MetainfoFoundSupportedPlatform true) + endif() + elseif (${CMAKE_MATCH_1} STREQUAL "FreeBSD") + if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + set(_MetainfoFoundSupportedPlatform true) + endif() + elseif (${CMAKE_MATCH_1} STREQUAL "Windows") + if (WIN32) + set(_MetainfoFoundSupportedPlatform true) + endif() + elseif (${CMAKE_MATCH_1} STREQUAL "macOS") + if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(_MetainfoFoundSupportedPlatform true) + endif() + elseif (${CMAKE_MATCH_1} STREQUAL "Android") + if (ANDROID) + set(_MetainfoFoundSupportedPlatform true) + endif() + elseif (${CMAKE_MATCH_1} STREQUAL "iOS") + if (IOS) + set(_MetainfoFoundSupportedPlatform true) + endif() + elseif (${CMAKE_MATCH_1} STREQUAL "All") + set(_MetainfoFoundSupportedPlatform true) + else() + list(POP_BACK _MetainfoSupportedPlatforms) + message(WARNING "Found platform not recognized by the metainfo platform parser: ${CMAKE_MATCH_1}") + endif() + elseif("${MetaInfoString}" MATCHES "^[A-Za-z0-9_]+:") + set(_MetainfoParserInPlatforms false) + endif() + endforeach() + + if (NOT _MetainfoFoundSupportedPlatform) + 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") + endif() +endif() -- cgit v1.2.1