2026-01-07 3:57 AM
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
2026-01-07 4:01 AM
Is it a source code library (.c and .h files), or a precompiled binary library (.a) ?
From your post, it sounds like the former?
2026-01-07 4:13 AM
Thanks for reply
it is source code but there are multiple .h and .c files in multiple folders
2026-01-07 4:30 AM
So the question is really just, "how to add multiple .h and .c files in multiple folders?"
2026-01-07 4:35 AM
This is my library
2026-01-07 4:44 AM - edited 2026-01-07 4:45 AM
./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