alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | # 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 | |
| 20 | # 1. We should be cross-compiling (non-native target) |
| 21 | if (TARGET_PLATFORM STREQUAL native) |
| 22 | message(FATAL_ERROR "No CMSIS-DSP support for native target.") |
| 23 | endif() |
| 24 | |
| 25 | # 2. Check if CMSIS sources have been defined |
| 26 | if (NOT DEFINED CMSIS_SRC_PATH) |
| 27 | message(FATAL_ERROR "CMSIS path should be defined for CMSIS-DSP library to be built") |
| 28 | endif() |
| 29 | |
| 30 | # 3. Form a list of all the sources we need in CSMS-DSP library |
| 31 | set(CMSIS_DSP_PATH_SUFFIX "CMSIS/DSP") |
| 32 | set(CMSIS_CORE_PATH_SUFFIX "CMSIS/Core") |
| 33 | set(CMSIS_DSP_SRC_DIR "${CMSIS_SRC_PATH}/${CMSIS_DSP_PATH_SUFFIX}/Source") |
| 34 | set(CMSIS_DSP_INC_DIR "${CMSIS_SRC_PATH}/${CMSIS_DSP_PATH_SUFFIX}/Include") |
| 35 | set(CMSIS_DSP_PRI_INC_DIR "${CMSIS_SRC_PATH}/${CMSIS_DSP_PATH_SUFFIX}/PrivateInclude") |
| 36 | set(CMSIS_CORE_INC_DIR "${CMSIS_SRC_PATH}/${CMSIS_CORE_PATH_SUFFIX}/Include") |
| 37 | |
| 38 | file(GLOB_RECURSE |
| 39 | CMSIS_DSP_SRC |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 40 | |
| 41 | "${CMSIS_DSP_SRC_DIR}/BasicMathFunctions/arm_*.c" |
| 42 | "${CMSIS_DSP_SRC_DIR}/FastMathFunctions/arm_*.c" |
| 43 | "${CMSIS_DSP_SRC_DIR}/CommonTables/arm_*.c" |
| 44 | "${CMSIS_DSP_SRC_DIR}/TransformFunctions/arm_*.c" |
| 45 | "${CMSIS_DSP_SRC_DIR}/StatisticsFunctions/arm_*.c" |
| 46 | |
| 47 | # Issue with q15 and q31 functions with Arm GNU toolchain, we only |
| 48 | # need f32 functions. |
| 49 | "${CMSIS_DSP_SRC_DIR}/ComplexMathFunctions/arm_*f32.c") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 50 | |
| 51 | # 4. Create static library |
| 52 | set(CMSIS_DSP_TARGET cmsis-dsp) |
| 53 | |
| 54 | add_library(${CMSIS_DSP_TARGET} STATIC ${CMSIS_DSP_SRC}) |
| 55 | |
| 56 | target_include_directories(${CMSIS_DSP_TARGET} PUBLIC |
| 57 | ${CMSIS_DSP_INC_DIR} |
| 58 | ${CMSIS_CORE_INC_DIR}) |
| 59 | target_include_directories(${CMSIS_DSP_TARGET} PRIVATE |
| 60 | ${CMSIS_DSP_PRI_INC_DIR}) |
| 61 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 62 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 63 | target_compile_options(${CMSIS_DSP_TARGET} PUBLIC -flax-vector-conversions) |
| 64 | |
| 65 | # There is a known issue with -O0 optimisation option that affects |
| 66 | # FFT functions from CMSIS-DSP when compiling with Arm GNU embedded |
| 67 | # toolchain version 10.2.1 |
| 68 | if (CMAKE_BUILD_TYPE STREQUAL Debug) |
| 69 | message(WARNING "There are known issues with CMSIS-DSP builds using " |
| 70 | "MVE extension without optimisation. Forcing -O3 " |
| 71 | "optimisation level") |
| 72 | target_compile_options(${CMSIS_DSP_TARGET} PUBLIC -O3) |
| 73 | endif() |
| 74 | endif () |
| 75 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 76 | # 5. Add any custom/conditional flags for compilation or linkage |
| 77 | if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL cortex-m55) |
| 78 | target_compile_definitions(${CMSIS_DSP_TARGET} PUBLIC |
| 79 | ARM_MATH_MVEI |
| 80 | ARM_MATH_DSP |
| 81 | ARM_MATH_LOOPUNROLL) |
| 82 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL cortex-m33) |
| 83 | # Placeholder, if building with Cortex-M33 |
| 84 | endif() |
| 85 | |
| 86 | |
| 87 | # 6. Provide the library path for the top level CMake to use: |
| 88 | set(CMSIS_DSP_LIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${CMSIS_DSP_TARGET}.a") |
| 89 | message(STATUS "CMSIS_DSP_LIB set to be generated here: ${CMSIS_DSP_LIB}") |
| 90 | |
| 91 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) |
| 92 | message(STATUS "*******************************************************") |
| 93 | message(STATUS "Library : " ${CMSIS_DSP_TARGET}) |
| 94 | message(STATUS "Build type : " ${CMAKE_BUILD_TYPE}) |
| 95 | message(STATUS "TARGET_PLATFORM : " ${TARGET_PLATFORM}) |
| 96 | message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) |
| 97 | message(STATUS "*******************************************************") |