bmd-studio / stm32-for-vscode

STM32 extension for working with STM32 and CubeMX in VSCode
MIT License
195 stars 27 forks source link

Different optimization on some files. #154

Open ARNik opened 1 year ago

ARNik commented 1 year ago

Hello! I would like to have size optimization -Os enabled globally exept one file (that I am currently debugging - Og) Is it possible to make such settings?

I can't just use -Og for the project due to the lack of flash memory.

jortbmd commented 1 year ago

Thanks for opening up an issue again. I really do appreciate it. It sounds like an interesting thing to do. Unfortunately it is not something that is directly supported. What you could possibly do is make several post build rules which compiles the specific file with the -Og flag and then relinks it. Which is a bit of a tedious work around. Another option would be to copy the STM32Make.make file and adapt it to do what you want and call it with the make -f YOURMAKEFILENAME.mk -j 16. Let me know if that works for you now. I don't know if you have experience with other IDE's or solutions that allow you to do it. If so let me know and I will check it out how they solved this issue.

ARNik commented 1 year ago

Almost any IDE let to set different settings to any file. But them build makefiles themself. For example in STM32CubeIDE you can right-click on single file -> Properties and just make changes in the settings. image

After that you can see this file marked as having different settings from the project.

ARNik commented 1 year ago

Thank you for your ideas. What if I make changes to the original Makefile? Will the extention copy them?

jortbmd commented 1 year ago

Thanks for the screenshot of the feature!

And as far as the original makefile goes it does copy some changes, but not all the changes. It looks for variables like C_DEFS and copies those over but it does not copy makefile rules for example. Currently this is the list it copies over (right hand side of the array)

const makeInfoKeysToMakefileKeys: [keyof CubeMXMakefile, string][] = [
  ['cDefs', 'C_DEFS'],
  ['asDefs', 'AS_DEFS'],
  ['cIncludes', 'C_INCLUDES'],
  ['cSources', 'C_SOURCES'],
  ['asmSources', 'ASM_SOURCES'],
  ['libdir', 'LIBDIR'],
  ['libs', 'LIBS'],
  ['target', 'TARGET'],
  ['cpu', 'CPU'],
  ['fpu', 'FPU'],
  ['floatAbi', 'FLOAT-ABI'],
  ['ldscript', 'LDSCRIPT'],
  ['optimization', 'OPT'],
  ['mcu', 'MCU']
];

I think that changing the original makefile would be able to help you in this specific case. But if you think of a solution definitely let me know.