cancel
Showing results for 
Search instead for 
Did you mean: 

CMAKE_BUILD_TYPE not passed to CMakeLists.txt for the generated project via STM32CubeMX

hakeila
Associate

Hi,

I have setup and configured an STM32H5-based MCU via STM32CubeMX and with cmake as build system.

 

I managed to build it successfully using Ninja generator. However, I can't change the configuration to Release and it is always Debug even though I used -DCMAKE_BUILD_TYPE=Release. 

 

I tried this in command line and using STM32 VSCODE Extension and all with the same results. 

 

I even tried to pass -DCMAKE_CONFIGURATION_TYPES="Debug;Release".

 

Here is my build script:

 

@echo off

set TargetBuild=%1

:CHECK_INPUT

IF [%TargetBuild%] == [] GOTO :ERROR

:PROCESS

cd ../ &

rm -rf Secure/build &

rm -rf NonSecure/build &

rm -rf build

mkdir build &

cd build &

cmake -DCMAKE_CONFIGURATION_TYPES=%TargetBuild% -DCMAKE_BUILD_TYPE=%TargetBuild% -DCMAKE_TOOLCHAIN_FILE=gcc-arm-none-eabi.cmake -B%TargetBuild% -G Ninja -S../  &

cd %TargetBuild% &

ninja

goto :eof

:ERROR

echo "Error: No target build given"

echo "Usage Example:""

echo "_build.cmd Release"

goto :eof

Cheers,
Hani
1 REPLY 1
Ghofrane GSOURI
ST Employee

Hello @hakeila 

Before reconfiguring, make sure to clean any previous build artifacts. You can do this by removing the build directory entirely:

rm -rf build
mkdir build
cd build

Visual Studio Code Settings:
If you're using Visual Studio Code with the STM32 extension, ensure that your tasks and launch configurations are set up correctly to reflect the desired build type.

Example Build Script Adjustment

Here’s a refined version of your batch script that includes checks and ensures proper handling of the build type:

@echo off

set TargetBuild=%1

:CHECK_INPUT

IF [%TargetBuild%] == [] GOTO :ERROR

:PROCESS

cd ..\ &

rm -rf Secure\build & rm -rf NonSecure\build & rm -rf build 

mkdir build & cd build &

cmake -DCMAKE_CONFIGURATION_TYPES="%TargetBuild%" -DCMAKE_BUILD_TYPE="%TargetBuild%" -DCMAKE_TOOLCHAIN_FILE=gcc-arm-none-eabi.cmake -G Ninja -S .. &

cd %TargetBuild% & ninja

goto :eof

:ERROR

echo "Error: No target build given"
echo "Usage Example:"
echo "_build.cmd Release"

goto :eof
  • After running CMake, check the output logs for any warnings or messages related to configuration.
  • Run ninja clean before building again to ensure no stale objects are present.