Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake module to find STM32 Discovery library files #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions cmake/FindSTM32Discovery.cmake
Original file line number Diff line number Diff line change
@@ -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)