Skip to content

Add CMake Support #316

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

Open
arms-spageddie opened this issue May 7, 2025 · 1 comment · May be fixed by #317
Open

Add CMake Support #316

arms-spageddie opened this issue May 7, 2025 · 1 comment · May be fixed by #317
Assignees
Labels
enhancement New feature or request projects Projects-related (demos, applications, examples) issue or pull-request.

Comments

@arms-spageddie
Copy link

Overview

I’d like to contribute CMake integration for this repository, enabling projects that use CMake to easily consume it as a dependency.

Proposal

Find Package Support

Add support to allow this repository to be discovered via CMake’s find_package() command. This involves providing a Find<package>.cmake module file, where <package> is a name representing this repository.

For example: FindSTM32CubeH7.cmake.

Usage

Fetching the Repository

Consuming projects would include the following in their CMake configuration:

FetchContent_Declare(
    stm32cubeH7
    GIT_REPOSITORY git@github.com:STMicroelectronics/STM32CubeH7.git
    GIT_TAG v1.12.1
    GIT_SUBMODULES_RECURSE TRUE
    GIT_PROGRESS TRUE
)

FetchContent_MakeAvailable(stm32cubeH7)

list(APPEND CMAKE_MODULE_PATH ${stm32cubeH7_SOURCE_DIR})

This fetches the repository (including submodules) into the CMake build directory.

The CMAKE_MODULE_PATH is then updated to include the repository path, so CMake can find the custom FindSTM32CubeH7.cmake file during find_package() calls.

Finding the Package

Once fetched, the consuming project would locate and request specific components using:

find_package(
    STM32CubeH7
    COMPONENTS
        rcc
        gpio
        i2c
        usb_hid_device
    REQUIRED
)

This locates FindSTM32CubeH7.cmake and triggers additional includes for CMake files within this repository that manage locating source files for the requested components.

In the example above, the consuming project requests the rcc, gpio, i2c, and usb_hid_device drivers. The added CMake support will identify the relevant source files and configure them into a library for the consuming project.

Linking

Finally, the consuming project would link against the created library using:

target_link_libraries(<target> PRIVATE stm32cubeh7)

Where <target> is the name of the executable or library target defined by the consuming project via add_executable() or add_library().

Summary

This proposal improves CMake interoperability for this repository, making it easier to integrate into modern, CMake-based embedded projects via standard tooling like FetchContent and find_package().

@arms-spageddie
Copy link
Author

Here is a high-level overview of the CMake infrastructure being considered:

Image

This may change slightly as it's being implemented, but I don't expect it to change too much. Any suggestions or concerns are welcome!

The priority would be to get CMake support implemented for CMSIS and HAL elements as those are necessary for starting a new project with this firmware package, along with a test project to ensure functionality. Afterwards, the priority would shift to the BSP and Components elements, then finally for Middleware elements.

Let me know if anyone has any questions, comments, or concerns. Thank you.

@ALABSTM ALABSTM added enhancement New feature or request projects Projects-related (demos, applications, examples) issue or pull-request. labels May 9, 2025
@arms-spageddie arms-spageddie linked a pull request May 26, 2025 that will close this issue
@ALABSTM ALABSTM linked a pull request May 28, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request projects Projects-related (demos, applications, examples) issue or pull-request.
Projects
Development

Successfully merging a pull request may close this issue.

3 participants