Skip to main content
RAltm
Senior
February 13, 2021
Solved

[solved] CubeIDE: using __date__/__time__ macros & force rebuild of files using them

  • February 13, 2021
  • 4 replies
  • 4321 views

Hello,

I'm using the __date__/__time__ macros. Their values are only updated if the file using them is re-compiled. Cleaning up before building forces the values to be updated, but this is not feasible on bigger projects.

Is there a way to tell CubeIDE that a specific file always has to be rebuild? I only found solutions for makefiles, but CubeIDE is not using makefiles.

Regards

Best answer by KnarfB

You can add a pre-build step in the C/C++ Build Settings. The pre-build step can be any command like touch or a shell script generating a version file etc..

4 replies

Pavel A.
Super User
February 13, 2021

>  but CubeIDE is not using makefiles

Nevertheless if you touch a source file, eclipse usually recompiles it.

-- pa

KnarfB
KnarfBBest answer
Super User
February 13, 2021

You can add a pre-build step in the C/C++ Build Settings. The pre-build step can be any command like touch or a shell script generating a version file etc..

RAltm
RAltmAuthor
Senior
February 14, 2021

Hello Pavel & KnarfB,

okay, I'll check those ways. I'll have to figure out if Windows has a function similar to the touch command on Linux.

Thank you.

Regards

KnarfB
Super User
February 14, 2021

Hi RAltm,

copy/b test.txt +,,

does the trick in Windows. A real "touch" comes with the STM32CubeIDE plugins like:

C:\ST\STM32CubeIDE\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.make.win32_1.5.0.202011040924\tools\bin\busybox.exe touch test.txt

Your path may vary

hth

KnarfB

Pavel A.
Super User
February 14, 2021

Actually much easier. Just make a small change in the file, undo, save. Or, delete corresponding object files.

-- pa

robmilne
Associate II
December 13, 2024

As in previous replies, touching the file will force a recompile of the file.  In my case I need to recompile a version.c file to capture __date__ and __time__ for every build and was able to do so with the following line as the pre-build step command.  The path refers to the directory structure within the build directory.

if [ -f path/to/version.o ]; then rm path/to/version.o; fi


-rob