From b6b9b0eed534c8ca1e3579b051a0b83e9764077d Mon Sep 17 00:00:00 2001 From: Alex Hoffman Date: Tue, 23 Jun 2020 12:07:01 +0200 Subject: [PATCH] Cmake module to find STM32 Discovery library files --- cmake/FindSTM32Discovery.cmake | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cmake/FindSTM32Discovery.cmake diff --git a/cmake/FindSTM32Discovery.cmake b/cmake/FindSTM32Discovery.cmake new file mode 100644 index 00000000..5cb1faa9 --- /dev/null +++ b/cmake/FindSTM32Discovery.cmake @@ -0,0 +1,52 @@ +SET(DISCOVERY_COMPONENTS i2c_ee ioe l3gd20 lcd sdram) + +IF(NOT STM32Discovery_FIND_COMPONENTS) + SET(STM32Discovery_FIND_COMPONENTS ${DISCOVERY_COMPONENTS}) + MESSAGE(STATUS "No STM32 Discovery components selected, using all: ${DISCOVERY_COMPONENTS}") +ENDIF() + +SET(DISC_PREFIX stm32f429i_discovery) + +SET(DISC_HEADERS + ${DISC_PREFIX}.h + ) + +SET(DISC_SRCS + ${DISC_PREFIX}.c + ) + +FOREACH(cmp ${STM32Discovery_FIND_COMPONENTS}) + LIST(FIND DISCOVERY_COMPONENTS ${cmp} DISC_FOUND_INDEX) + IF(${DISC_FOUND_INDEX} LESS 0) + MESSAGE(FATAL_ERROR "Unknown STM32 Discovery component: ${cmp}. Available components: ${DISCOVERY_COMPONENTS}") + ELSE() + LIST(APPEND DISC_HEADERS ${DISC_PREFIX}_${cmp}.h) + LIST(APPEND DISC_SRCS ${DISC_PREFIX}_${cmp}.c) + ENDIF() +ENDFOREACH() + +LIST(REMOVE_DUPLICATES DISC_HEADERS) +LIST(REMOVE_DUPLICATES DISC_SRCS) + +FOREACH(HEADER ${DISC_HEADERS}) + FIND_PATH(STM32Discovery_INCLUDE_DIR ${DISC_HEADERS} + PATH_SUFFIXES Utilities + HINTS ${STM32Discovery_DIR}/Utilities/STM32F429I-Discovery + CMAKE_FIND_ROOT_PATH_BOTH + ) +ENDFOREACH() + +FOREACH(DISC_SRC ${DISC_SRCS}) + STRING(MAKE_C_IDENTIFIER "${DISC_SRC}" DISC_SRC_CLEAN) + SET(DISC_${DISC_SRC_CLEAN}_FILE DISC_SRC_FILE-NOTFOUND) + FIND_FILE(DISC_${DISC_SRC_CLEAN}_FILE ${DISC_SRC} + PATH_SUFFIXES Utilities STM32F429I-Discovery + HINTS ${STM32Discovery_DIR}/Utilities/STM32F429I-Discovery + CMAKE_FIND_ROOT_PATH_BOTH + ) + LIST(APPEND STM32Discovery_SOURCES ${DISC_${DISC_SRC_CLEAN}_FILE}) +ENDFOREACH() + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(STM32Discovery DEFAULT_MSG STM32Discovery_INCLUDE_DIR STM32Discovery_SOURCES)