2026-03-25 9:07 PM
My STM32cube IDE project has a pre-build command:
${ProjDirPath}\Middlewares\Third_Party\nanopb\generator\protoc --nanopb_out=${ProjDirPath}\Application\cm4_interface --proto_path=${ProjDirPath}\Application\cm4_interface ${ProjDirPath}\Application\cm4_interface\cm4-interface.proto
The json that's generated doesn't correctly escape the '\' characters, which results in an error...
2026-03-26 1:14 AM
could you please attach the original project or an example to reproduce the issue
2026-03-26 2:08 AM
Hi @Robert-Helps,
Regardless of the JSON format issue, which will be fixed in a future bundle release, pre-build commands are not natively supported by CMake - only post-build commands are.
However, some tips exist; you can define a custom target that runs the command and add this custom target as a build dependency of the main target:
# 1. Custom target that runs your script/command
add_custom_target(prebuild_step
COMMAND ${CMAKE_COMMAND} -E echo "Running prebuild_step"
# You can add more commands here
BYPRODUCTS ${CMAKE_BINARY_DIR}/generated_file.h
COMMENT "Executing pre-build custom step"
)
# 2. Your main target
add_executable(MyApp main.cpp)
# 3. Ensure prebuild_step runs before MyApp is built
add_dependencies(MyApp prebuild_step)
As stated here, waiting for a release, you can fix your JSON file, and call the converter manually:
cube ide-project-convert --bypass-converter <path_to_stm32cubeide-export.json> --source-format stm32cubeide --destination <cmake_project_location> --format cmakeHTH.