summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-05-04 16:38:06 +0700
committerhathach <[email protected]>2023-05-04 16:38:06 +0700
commit629717cd13730fa5f7543ce414ff11b5c175add0 (patch)
tree694d373cb088a5d589fac90946128a0114fb7f56 /examples
parent5e023fa2ca4c20f06b6e0dc12f6f044a7d4e14bd (diff)
fix cmake build
Diffstat (limited to 'examples')
-rw-r--r--examples/cmake/cpu/cortex-m7.cmake6
-rw-r--r--examples/cmake/toolchain/arm_gcc.cmake54
-rw-r--r--examples/cmake/toolchain/set_flags.cmake20
3 files changed, 80 insertions, 0 deletions
diff --git a/examples/cmake/cpu/cortex-m7.cmake b/examples/cmake/cpu/cortex-m7.cmake
new file mode 100644
index 000000000..2b258726f
--- /dev/null
+++ b/examples/cmake/cpu/cortex-m7.cmake
@@ -0,0 +1,6 @@
+set(TOOLCHAIN_COMMON_FLAGS
+ -mthumb
+ -mcpu=cortex-m7
+ -mfloat-abi=hard
+ -mfpu=fpv5-d16
+ )
diff --git a/examples/cmake/toolchain/arm_gcc.cmake b/examples/cmake/toolchain/arm_gcc.cmake
new file mode 100644
index 000000000..c5937192e
--- /dev/null
+++ b/examples/cmake/toolchain/arm_gcc.cmake
@@ -0,0 +1,54 @@
+set(CMAKE_SYSTEM_NAME Generic)
+
+set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc")
+set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
+set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
+set(GCC_ELF2BIN "arm-none-eabi-objcopy")
+set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
+
+# Look for includes and libraries only in the target system prefix.
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+# pass TOOLCHAIN_CPU to
+set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_SYSTEM_PROCESSOR)
+
+include(${CMAKE_CURRENT_LIST_DIR}/../cpu/${CMAKE_SYSTEM_PROCESSOR}.cmake)
+
+# enable all possible warnings for building examples
+list(APPEND TOOLCHAIN_COMMON_FLAGS
+ -fdata-sections
+ -ffunction-sections
+ -fsingle-precision-constant
+ -fno-strict-aliasing
+ )
+
+set(TOOLCHAIN_WARNING_FLAGS
+ -Wall
+ -Wextra
+ -Werror
+ -Wfatal-errors
+ -Wdouble-promotion
+ -Wstrict-prototypes
+ -Wstrict-overflow
+ -Werror-implicit-function-declaration
+ -Wfloat-equal
+ -Wundef
+ -Wshadow
+ -Wwrite-strings
+ -Wsign-compare
+ -Wmissing-format-attribute
+ -Wunreachable-code
+ -Wcast-align
+ -Wcast-function-type
+ -Wcast-qual
+ -Wnull-dereference
+ -Wuninitialized
+ -Wunused
+ -Wreturn-type
+ -Wredundant-decls
+ )
+
+include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)
diff --git a/examples/cmake/toolchain/set_flags.cmake b/examples/cmake/toolchain/set_flags.cmake
new file mode 100644
index 000000000..da381c254
--- /dev/null
+++ b/examples/cmake/toolchain/set_flags.cmake
@@ -0,0 +1,20 @@
+include(CMakePrintHelpers)
+foreach(LANG IN ITEMS C CXX ASM)
+ # join the toolchain flags into a single string
+ list(APPEND TOOLCHAIN_${LANG}_FLAGS ${TOOLCHAIN_COMMON_FLAGS})
+ list(JOIN TOOLCHAIN_${LANG}_FLAGS " " TOOLCHAIN_${LANG}_FLAGS)
+ set(CMAKE_${LANG}_FLAGS_INIT "${TOOLCHAIN_${LANG}_FLAGS}")
+
+ #cmake_print_variables(CMAKE_${LANG}_FLAGS_INIT)
+
+ # optimization flags
+ set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-Og")
+endforeach()
+
+# try_compile is cmake test compiling its own example,
+# pass -nostdlib to skip stdlib linking
+get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
+if(IS_IN_TRY_COMPILE)
+ set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -nostdlib")
+ set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib")
+endif()