Skip to main content
Visitor II
January 7, 2026
Question

How to add external libraries in my project using Vscode and CMake

  • January 7, 2026
  • 2 replies
  • 89 views

Hi for all,

I use Cube MX to generate code with CMake and then use Vscode with needed extension to compile my code.

My question is : i want to use library that contain multiple folders to drive stepper motor, how to add this library to my project.

best regard for all 

thanks for any reply 

    This topic has been closed for replies.

    2 replies

    Super User
    January 7, 2026

    Is it a source code library (.c and .h files), or a precompiled binary library (.a) ?

    From your post, it sounds like the former?

    EliteAuthor
    Visitor II
    January 7, 2026

    Thanks for reply

    it is source code but there are multiple .h and .c files in multiple folders   

    Super User
    January 7, 2026

    So the question is really just, "how to add multiple .h and .c files in multiple folders?"

    Graduate II
    January 7, 2026

    ./CMakeLists.txt:

    ...

    # Link directories setup
    target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined library search paths
    )

    # Add sources to executable
    target_sources(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user sources here
    STM32Step/src/stepper/GPIOStepper.cpp
    # etc.
    )

    # Add include paths
    target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined include paths
    STM32Step/src
    STM32Step/src/timer
    # etc.
    )

    target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user compile definitions here
    )

    # Add linked libraries
    target_link_libraries(${CMAKE_PROJECT_NAME}
    stm32cubemx
    # Add user defined libraries
    )

    ...

     

    I wrote a guide for more advanced modifications: https://community.st.com/t5/stm32cubemx-mcus/how-to-customize-your-stm32cubemx-generated-cmake-project/td-p/857290