|
| 1 | +# Copyright (C) 2024 by Skyward |
| 2 | +# |
| 3 | +# This program is free software; you can redistribute it and/or |
| 4 | +# it under the terms of the GNU General Public License as published |
| 5 | +# the Free Software Foundation; either version 2 of the License, or |
| 6 | +# (at your option) any later version. |
| 7 | +# |
| 8 | +# This program is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +# GNU General Public License for more details. |
| 12 | +# |
| 13 | +# As a special exception, if other files instantiate templates or use |
| 14 | +# macros or inline functions from this file, or you compile this file |
| 15 | +# and link it with other works to produce a work based on this file, |
| 16 | +# this file does not by itself cause the resulting work to be covered |
| 17 | +# by the GNU General Public License. However the source code for this |
| 18 | +# file must still be made available in accordance with the GNU |
| 19 | +# Public License. This exception does not invalidate any other |
| 20 | +# why a work based on this file might be covered by the GNU General |
| 21 | +# Public License. |
| 22 | +# |
| 23 | +# You should have received a copy of the GNU General Public License |
| 24 | +# along with this program; if not, see <http://www.gnu.org/licenses/> |
| 25 | + |
| 26 | +# Add the miosix/cmake path to find the Miosix.cmake platform file |
| 27 | +# that defines the Miosix system name |
| 28 | +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/..) |
| 29 | + |
| 30 | +# Tell CMake that we are building for an embedded ARM system |
| 31 | +set(CMAKE_SYSTEM_NAME Miosix) |
| 32 | + |
| 33 | +# Names of the compiler and other tools |
| 34 | +set(CMAKE_ASM_COMPILER clang) |
| 35 | +set(CMAKE_C_COMPILER clang) |
| 36 | +set(CMAKE_CXX_COMPILER clang++) |
| 37 | +set(CMAKE_AR llvm-ar) |
| 38 | +set(CMAKE_OBJCOPY llvm-objcopy) |
| 39 | +set(CMAKE_OBJDUMP llvm-objdump) |
| 40 | +set(CMAKE_SIZE llvm-size) |
| 41 | + |
| 42 | +# Optimization flags for each language and build configuration |
| 43 | +set(CMAKE_ASM_FLAGS_DEBUG "") |
| 44 | +set(CMAKE_C_FLAGS_DEBUG "-Og -g") |
| 45 | +set(CMAKE_CXX_FLAGS_DEBUG "-Og -g") |
| 46 | +set(CMAKE_ASM_FLAGS_RELEASE "") |
| 47 | +set(CMAKE_C_FLAGS_RELEASE "-O2") |
| 48 | +set(CMAKE_CXX_FLAGS_RELEASE "-O2") |
| 49 | +set(CMAKE_ASM_FLAGS_RELWITHDEBINFO "") |
| 50 | +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g") |
| 51 | +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") |
| 52 | +set(CMAKE_ASM_FLAGS_MINSIZEREL "") |
| 53 | +set(CMAKE_C_FLAGS_MINSIZEREL "-Os") |
| 54 | +set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os") |
| 55 | + |
| 56 | +# Setting the target for crosscompilation |
| 57 | +# https://stackoverflow.com/questions/54539682/how-to-set-up-cmake-to-cross-compile-with-clang-for-arm-embedded-on-windows |
| 58 | +set(CLANG_TARGET_TRIPLE arm-none-eabi) |
| 59 | +set(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET_TRIPLE}) |
| 60 | +set(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET_TRIPLE}) |
| 61 | +set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET_TRIPLE}) |
| 62 | + |
| 63 | +# Setting the include paths for system libraries |
| 64 | +include_directories(SYSTEM |
| 65 | + "/opt/arm-miosix-eabi/arm-miosix-eabi/include/c++/9.2.0/arm-miosix-eabi" |
| 66 | + "/opt/arm-miosix-eabi/arm-miosix-eabi/include/c++/9.2.0" |
| 67 | + "/opt/arm-miosix-eabi/arm-miosix-eabi/include" |
| 68 | +) |
| 69 | + |
| 70 | +# We want to test for a static library and not an executable |
| 71 | +# reference: https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program |
| 72 | +set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") |
| 73 | + |
| 74 | +# Defines used by the Miosix patches to the libraries/opt/arm-miosix-eabi/arm-miosix-eabi/lib/thumb/cm4/hardfp/fpv4sp |
| 75 | +add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:__GXX_TYPEINFO_EQUALITY_INLINE=0>) |
| 76 | +add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_MIOSIX>) |
| 77 | +add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_MIOSIX_GCC_PATCH_MAJOR=3>) |
| 78 | +add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_MIOSIX_GCC_PATCH_MINOR=1>) |
| 79 | + |
| 80 | +link_directories(SYSTEM |
| 81 | + # /opt/arm-miosix-eabi/arm-miosix-eabi/lib/thumb/cm4/hardfp/fpv4sp |
| 82 | + /opt/arm-miosix-eabi/lib/gcc/arm-miosix-eabi/9.2.0/thumb/cm4/hardfp/fpv4sp |
| 83 | +) |
| 84 | +set(CMAKE_SYSROOT |
| 85 | + /opt/arm-miosix-eabi/arm-miosix-eabi |
| 86 | +# # /opt/arm-miosix-eabi/lib/gcc/arm-miosix-eabi/9.2.0 |
| 87 | +) |
| 88 | +# add_link_options("-fuse-ld=/usr/bin/arm-miosix-eabi-ld") |
0 commit comments