Elffuss BraidHub

kikocis/kleidiai public

main · 2.7 KiBRawPermalink
1#
2# SPDX-FileCopyrightText: Copyright 2025-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3#
4# SPDX-License-Identifier: Apache-2.0
5#
6
7# -------------------------------------------------------------------------------------------------
8
9# TODO:
10#
11# * Add sanity checks for combinations of flags, e.g. enable Android and bare metal?
12# * Add sanity checks for C/C++ standard
13
14# Cycle-timing only works in non-threaded mode and can't be used with cycle profiling
15if(KLEIDIAI_OPS_ENABLE_CYCLE_TIMING)
16 if(KLEIDIAI_OPS_ENABLE_THREADS)
17 message(FATAL_ERROR "Cannot enable cycle timing with threads enabled")
18 endif()
19 if(KLEIDIAI_OPS_ENABLE_CYCLE_PROFILING)
20 message(FATAL_ERROR "Cannot enable cycle profiling with cycle timing enabled")
21 endif()
22endif()
23
24# Thread binding requires threads
25if(KLEIDIAI_OPS_ENABLE_BIND_THREADS AND NOT KLEIDIAI_OPS_ENABLE_THREADS)
26 message(FATAL_ERROR "Cannot enable thread binding without enabling threads")
27endif()
28
29# Only allow cycle profiling if this is the top-level project
30if(KLEIDIAI_OPS_ENABLE_CYCLE_PROFILING)
31 if(PROJECT_IS_TOP_LEVEL)
32 message(
33 STATUS
34 "Cycle profiling enabled (this feature should only be enabled by ${PROJECT_NAME} developers)"
35 )
36 else()
37 message(FATAL_ERROR "Can't enable cycle profiling when project is not top-level")
38 endif()
39endif()
40
41# Helper function to ensure the given flags are only enabled on certain platforms
42function(allow_flags_only_on_platforms PLATFORM_REGEX)
43 foreach(FLAG IN LISTS ARGN)
44 if(${FLAG} AND NOT CMAKE_SYSTEM_NAME MATCHES "${PLATFORM_REGEX}")
45 message(FATAL_ERROR "Can only enable ${FLAG} on systems matching '${PLATFORM_REGEX}'. "
46 "You're on ${CMAKE_SYSTEM_NAME}.")
47 endif()
48 endforeach()
49endfunction()
50
51# Helper function to ensure the given flags are NOT enabled on certain platforms
52function(disallow_flags_on_platforms PLATFORM_REGEX)
53 foreach(FLAG IN LISTS ARGN)
54 if(${FLAG} AND CMAKE_SYSTEM_NAME MATCHES "${PLATFORM_REGEX}")
55 message(FATAL_ERROR "Cannot enable ${FLAG} on systems matching '${PLATFORM_REGEX}'. "
56 "You're on ${CMAKE_SYSTEM_NAME}.")
57 endif()
58 endforeach()
59endfunction()
60
61# We'll only disallow threading on bare-metal for now
62disallow_flags_on_platforms("Generic" KLEIDIAI_OPS_ENABLE_THREADS)
63
64# Thread binding uses a Linux-specific API, so it only works on Linux/Android
65allow_flags_only_on_platforms("Linux|Android" KLEIDIAI_OPS_ENABLE_BIND_THREADS)
66
67# Cycle timing/profiling is only supported on Linux
68allow_flags_only_on_platforms("Linux" KLEIDIAI_OPS_ENABLE_CYCLE_TIMING)
69
70# -------------------------------------------------------------------------------------------------