-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake: promote recommended good practices #649
Comments
@massonal |
Sure can do ;) remove redundant variablesSeveral items are defined as variables first, and then used exactly once in a target configuration function call. It would be better to not define the variable at all and call the function directly (to improve readability and robustness, mostly) set(INC_PATHS
".../RTE/Device/STM32U585AIIx"
".../cmsis/CMSIS/Core/Include"
".../stm32u5xx/Include"
".../targets/B-U585I-IOT02A"
)
# possibly
# lots
# of stuff
# in between
target_include_directories(${TARGET} PUBLIC ${INC_PATHS}) into that target_include_directories(${TARGET} PUBLIC
".../RTE/Device/STM32U585AIIx"
".../cmsis/CMSIS/Core/Include"
".../stm32u5xx/Include"
".../targets/B-U585I-IOT02A"
) This way everything is in one place! An even worse example is the use standard variables and notationsSome variables are defined that seem to have the same role as variables defined and standardized by CMake (cmake-variables.7).
Also, to ease portability, CMake has the absolute pathsThe point is already being discussed in the issues I liked in my first post (#221 #314). set(CC_SRC_FILES
"C:/Users/massonal/path/to/hal/repository/drivers/stm32u5xx_hal/Src/stm32u5xx_hal.c"
"C:/Users/massonal/path/to/hal/repository/drivers/stm32u5xx_hal/Src/stm32u5xx_hal_pwr.c"
"C:/Users/massonal/path/to/hal/repository/drivers/stm32u5xx_hal/Src/stm32u5xx_hal_pwr_ex.c"
"C:/Users/massonal/path/to/hal/repository/drivers/stm32u5xx_hal/Src/stm32u5xx_hal_rcc.c"
"C:/Users/massonal/path/to/hal/repository/drivers/stm32u5xx_hal/Src/stm32u5xx_hal_rcc_ex.c"
"C:/Users/massonal/path/to/hal/repository/drivers/stm32u5xx_hal/Src/stm32u5xx_hal_uart.c"
"C:/Users/massonal/path/to/hal/repository/drivers/stm32u5xx_hal/Src/stm32u5xx_hal_uart_ex.c"
"C:/Users/massonal/path/to/project/workspace/my/project/main.c"
) (Source files, and include paths, and linker scripts, ...) This has several drawbacks:
Now, I can give some technical hints to help replace absolute paths with relative ones:
do not rely on "magic" internal variablesThis is close to the point I made earlier about A related point can be made about |
@massonal Thanks for the explanations.
Unfortunately CMake does not offer the same for compiler and assembler, do you know more on this matter?
It seems CMake always generates full path for object files, independently of source paths being relative. From CMAKE_OBJECT_PATH_MAX:
This is a conceptual difference. Currently generated CMakeLists.txt are not the root of CMSIS projects. It is an intermediate file exclusively for the building scope.
This can be a complex matter, it has been discussed several times. I would recommend to read about CMSIS Pack features to understand why a CMSIS Pack is different from a CMake based library.
Explained in #648
It is actually less predictable than the Please feel free to take part in Open-CMSIS-Pack meetings, good suggestions are always welcomed. |
Linked to #648
Hello,
I have been studying the CMake files generated to build to build code with cbuild (CMakeLists.txt + GCC/IAR/AC6.cmake). I have found several anti-patterns there, that I think both obfuscate the file and potentially trigger bugs (cf. below for an actual example).
I would do the following to improve the quality of the CMake files:
If any of these limitations is due to an actual technical limitation and can't be fixed, I think this should be documented in the file, in order not to confuse future readers.
The text was updated successfully, but these errors were encountered: