cancel
Showing results for 
Search instead for 
Did you mean: 

Bug: STM32MX useless CMake C standards check

SteveM732
Visitor

When STM32MX (6.12.1) is used to generate a CMake project it puts the following logic into cmake/stm32cubemx/CMakeLists.txt:

 

# Validate that STM32CubeMX code is compatible with C standard
if(CMAKE_C_STANDARD LESS 11)
    message(ERROR "Generated code requires C11 or higher")
endif()

 

 

At present the valid values for CMAKE_C_STANDARD are 90, 99, 11, 17, and 23. Therefore this comparison will always resolve to true and the message will not be printed if C90 or C99 are being used which is no doubt the intent. The following conditional is guaranteed to work until at least 2099:

 

if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))

 

 

1 REPLY 1
liaifat85
Senior III

The current conditional statement in STM32CubeMX (version 6.12.1) doesn't enforce the requirement for C11 or a higher standard. CMAKE_C_STANDARD LESS 11 will always return false with valid values (90, 99, 11, 17, 23). Therefore, the message(ERROR "Generated code requires C11 or higher") would indeed not trigger even if the project used an earlier standard like C90 or C99.

Using the alternative conditional you suggested would effectively catch C90 or C99 standards and ensure the intended check is applied.

You can edit it this way

 

# Validate that STM32CubeMX code is compatible with C standard
if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
    message(ERROR "Generated code requires C11 or higher")
endif()