aboutsummaryrefslogtreecommitdiff
path: root/cmake/mcu-stm32/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/mcu-stm32/CMakeLists.txt')
-rw-r--r--cmake/mcu-stm32/CMakeLists.txt76
1 files changed, 76 insertions, 0 deletions
diff --git a/cmake/mcu-stm32/CMakeLists.txt b/cmake/mcu-stm32/CMakeLists.txt
new file mode 100644
index 0000000..424d3ab
--- /dev/null
+++ b/cmake/mcu-stm32/CMakeLists.txt
@@ -0,0 +1,76 @@
+set(MCU_BASEDIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "foo" FORCE)
+
+if (POLICY CMP0057)
+ cmake_policy(SET CMP0057 NEW)
+else ()
+ # We need IN_LIST
+ message(FATAL_ERROR "CMake 3.3+ is required")
+endif ()
+
+function(mcu_stm32_add_library)
+ set(options)
+ set(oneValueArgs TARGET DEVICE DEFAULT_ASSERT_PARAM DEFINES_VAR)
+ set(multiValueArgs PARTS)
+ cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ # TODO: validate the device
+
+ add_library(${ARG_TARGET}
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/CoreSupport/core_cm3.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/misc.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c
+ )
+ list(REMOVE_ITEM ARG_PARTS RCC)
+
+ set(EXPORT_DEFINES ${ARG_DEVICE}
+ USE_STDPERIPH_DRIVER)
+
+ target_include_directories(${ARG_TARGET} PUBLIC
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/CoreSupport
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/inc
+ )
+
+ if (NOT DEFINED ARG_DEFAULT_ASSERT_PARAM)
+ set(ARG_DEFAULT_ASSERT_PARAM TRUE)
+ endif ()
+
+ if (ARG_DEFAULT_ASSERT_PARAM)
+ target_include_directories(${ARG_TARGET} PUBLIC ${MCU_BASEDIR}/conf)
+ endif ()
+
+ if (DMA IN_LIST ARG_PARTS)
+ list(REMOVE_ITEM ARG_PARTS DMA)
+ target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c)
+ endif ()
+
+ if (GPIO IN_LIST ARG_PARTS)
+ list(REMOVE_ITEM ARG_PARTS GPIO)
+ target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c)
+ endif ()
+
+ if (SPI IN_LIST ARG_PARTS)
+ list(REMOVE_ITEM ARG_PARTS SPI)
+ target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c)
+ endif ()
+
+ if (USART IN_LIST ARG_PARTS)
+ list(REMOVE_ITEM ARG_PARTS USART)
+ target_sources(${ARG_TARGET} PRIVATE ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c)
+ endif ()
+
+ list(LENGTH ARG_PARTS l)
+ if (${l} GREATER 0)
+ message(FATAL_ERROR "Unknown parts: ${ARG_PARTS}")
+ endif ()
+
+ if (DEFINES_VAR)
+ set(" ${DEFINES_FROM_MCU_STM32} " ${EXPORT_DEFINES} PARENT_SCOPE)
+ endif ()
+
+ # Set all the defines we want the consumers to use on these objects too
+ target_compile_definitions(${ARG_TARGET} PUBLIC
+ ${EXPORT_DEFINES})
+
+endfunction()