blob: 2dc093d424f459e0d1f2b9c02ef52f8c62f51d5d [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
Richard Burtonf32a86a2022-11-15 11:46:11 +00002# SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
alexander3c798932021-03-26 21:42:19 +00003# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#----------------------------------------------------------------------------
17
18# CMSIS-DSP library CMake helper script.
19
alexander31ae9f02022-02-10 16:15:54 +000020# Check if CMSIS sources have been defined
Maksims Svecovs254853c2022-08-30 12:58:02 +010021if (NOT DEFINED CMSIS_DSP_SRC_PATH)
22 message(FATAL_ERROR "CMSIS-DSP path should be defined for CMSIS-DSP library to be built")
23endif()
alexander3c798932021-03-26 21:42:19 +000024if (NOT DEFINED CMSIS_SRC_PATH)
Maksims Svecovs254853c2022-08-30 12:58:02 +010025 message(FATAL_ERROR "CMSIS-5 path should be defined to include CMSIS-CORE")
alexander3c798932021-03-26 21:42:19 +000026endif()
27
28# 3. Form a list of all the sources we need in CSMS-DSP library
Maksims Svecovs254853c2022-08-30 12:58:02 +010029set(CMSIS_DSP_SRC_DIR "${CMSIS_DSP_SRC_PATH}/Source")
30set(CMSIS_DSP_INC_DIR "${CMSIS_DSP_SRC_PATH}/Include")
31set(CMSIS_DSP_PRI_INC_DIR "${CMSIS_DSP_SRC_PATH}/PrivateInclude")
32set(CMSIS_CORE_INC_DIR "${CMSIS_SRC_PATH}/CMSIS/Core/Include")
alexander3c798932021-03-26 21:42:19 +000033
34file(GLOB_RECURSE
35 CMSIS_DSP_SRC
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010036
37 "${CMSIS_DSP_SRC_DIR}/BasicMathFunctions/arm_*.c"
38 "${CMSIS_DSP_SRC_DIR}/FastMathFunctions/arm_*.c"
39 "${CMSIS_DSP_SRC_DIR}/CommonTables/arm_*.c"
40 "${CMSIS_DSP_SRC_DIR}/TransformFunctions/arm_*.c"
41 "${CMSIS_DSP_SRC_DIR}/StatisticsFunctions/arm_*.c"
42
43 # Issue with q15 and q31 functions with Arm GNU toolchain, we only
44 # need f32 functions.
45 "${CMSIS_DSP_SRC_DIR}/ComplexMathFunctions/arm_*f32.c")
alexander3c798932021-03-26 21:42:19 +000046
47# 4. Create static library
48set(CMSIS_DSP_TARGET cmsis-dsp)
49
50add_library(${CMSIS_DSP_TARGET} STATIC ${CMSIS_DSP_SRC})
51
52target_include_directories(${CMSIS_DSP_TARGET} PUBLIC
53 ${CMSIS_DSP_INC_DIR}
54 ${CMSIS_CORE_INC_DIR})
55target_include_directories(${CMSIS_DSP_TARGET} PRIVATE
56 ${CMSIS_DSP_PRI_INC_DIR})
57
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010058if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
59 target_compile_options(${CMSIS_DSP_TARGET} PUBLIC -flax-vector-conversions)
60
61 # There is a known issue with -O0 optimisation option that affects
62 # FFT functions from CMSIS-DSP when compiling with Arm GNU embedded
Isabella Gottardi5c0ce542021-10-05 11:12:11 +010063 # toolchain version 10.2.1 or 10.3-2021.07
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010064 if (CMAKE_BUILD_TYPE STREQUAL Debug)
65 message(WARNING "There are known issues with CMSIS-DSP builds using "
66 "MVE extension without optimisation. Forcing -O3 "
67 "optimisation level")
68 target_compile_options(${CMSIS_DSP_TARGET} PUBLIC -O3)
69 endif()
70endif ()
71
Kshitij Sisodia9c6f9f82022-05-20 14:30:02 +010072# 5. General compile definitions
73target_compile_definitions(${CMSIS_DSP_TARGET} PUBLIC ARM_MATH_LOOPUNROLL)
alexander3c798932021-03-26 21:42:19 +000074
75# 6. Provide the library path for the top level CMake to use:
76set(CMSIS_DSP_LIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${CMSIS_DSP_TARGET}.a")
77message(STATUS "CMSIS_DSP_LIB set to be generated here: ${CMSIS_DSP_LIB}")
78
79message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
80message(STATUS "*******************************************************")
81message(STATUS "Library : " ${CMSIS_DSP_TARGET})
82message(STATUS "Build type : " ${CMAKE_BUILD_TYPE})
83message(STATUS "TARGET_PLATFORM : " ${TARGET_PLATFORM})
84message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR})
85message(STATUS "*******************************************************")