View previous topic :: View next topic |
Author |
Message |
Tom-H-PIC
Joined: 08 Sep 2003 Posts: 105 Location: New Castle, DE
|
Variable that is incremented each time the source is compile |
Posted: Wed Feb 15, 2017 7:38 pm |
|
|
The question is there a way to increment a variable in the source each time the source is compiled? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Feb 16, 2017 4:35 am |
|
|
If you are using the CCS IDE then yes there is. I am not sure if this will work with MPLab or the command line tools.
Code: |
int16 My_Build_Number = __BUILDCOUNT__;
|
__BUILDCOUNT__ is defined by the IDE and incremented at every compile by the CCS IDE, but ONLY if global defines are enabled in the project options.
The value is part of the IDE's project file, so if the project is compiled on different PCs, each will have a different build number. As MPLab uses it's own project file, I think this probably won't work in MPLab. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Thu Feb 16, 2017 4:20 pm |
|
|
Compiler: 5.026
Device: PIC24EP512GP806
That's actually something I've always wanted to have but never got to the point of asking for it....
I've opened-up Project > Project Options > Global Defines then I have an 'Enabled' checkbox, a Load, Save and Clear button.
So now how does this thing work? How do you add the __BUILDCOUNT__ define in here?
Providing the necessarry steps in order to accomplish this would be greatly appreciated!
Thanks!
Ben |
|
|
Tom-H-PIC
Joined: 08 Sep 2003 Posts: 105 Location: New Castle, DE
|
|
Posted: Thu Feb 16, 2017 8:01 pm |
|
|
First thank you RF_Developer
All I did was to enable the Global Defines in Project Options > Global Defines and save.
Then I put RF_Developer code in my h file close to the top.
Compiled and programed the PIC and looked at variable by output it to the serial port.
Work like a champ. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Feb 17, 2017 2:05 am |
|
|
benoitstjean wrote: | Compiler: 5.026
Device: PIC24EP512GP806
That's actually something I've always wanted to have but never got to the point of asking for it....
I've opened-up Project > Project Options > Global Defines then I have an 'Enabled' checkbox, a Load, Save and Clear button.
So now how does this thing work? How do you add the __BUILDCOUNT__ define in here?
Providing the necessarry steps in order to accomplish this would be greatly appreciated!
Thanks!
Ben |
__BUILDCOUNT__ is a compiler defined 'define'.
The Global Defines option allows the defines in the table below _and some the compiler automatically generates_ to automatically be added to the project. BUILDCOUNT is one of the latter.
So you need do nothing else than have the option enabled.
It's actually being generated by the compiler (not the IDE). If you compile from the command line it also works, provided you have the +G option in the command line. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri Feb 17, 2017 5:09 am |
|
|
Ttelmah wrote: |
__BUILDCOUNT__ is a compiler defined 'define'.
It's actually being generated by the compiler (not the IDE). If you compile from the command line it also works, provided you have the +G option in the command line. |
Unfortunately I doubt that will work as people might be expecting. Yes, __BUILDCOUNT__ is defined by the compiler, but the value is managed, and presumably incremented by the IDE. It is certainly stored in the IDE ccspjt file:
Code: |
[defines]
buildcount=588
enabled=1
chip=1
D1=
V1=
|
It also turns out that this value is the next one to be used, i.e. it has been incremented from the last compile. I.e. my last build was 587.
The value has to be stored somewhere. There has to be some file with it in so that it can be incremented. That file appears to be the ccspjt file, and as far as I understand it, that's not involved in command line compilation. I suspect you'll get the same value for every command line compile as there is no way of stroing it from one compile to the next. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Fri Mar 03, 2017 7:45 am |
|
|
Compiler: 5.026
Device: PIC24EP512GP806
Guys,
So if there's one for build count, is there one also for the date and time?
Or how would I go about having incremental versions everytime I compile, other than only the buildcount, without having to do it manually?
Otherwise I could always use the buildcount only.
Thanks,
Ben
[EDIT] I enabled global defines in PROJECT->PROJECT OPTIONS and simply hit APPLY. When I compile with an extra printf statement so that I see the buildcount, I get *** Error 12 [filename] Line 302(122,132): Undefined identifier buildcount
Then I went back in the options and just for the kick, I added __BUILDCOUNT__ as an 'identifier' and hit APPLY. This time, it is telling me *** Error 116 [filename] Line 302(120,121): Printf variable count (%) does not match actual count ::
Inside the ccspjt file, it is called <buildcount> rather than __BUILDCOUNT__ so I tried that as well and same problems.
So how to you actually use this?
Last edited by benoitstjean on Fri Mar 03, 2017 7:58 am; edited 1 time in total |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Fri Mar 03, 2017 7:52 am |
|
|
There are lots of predefined constants and macros for those type of things. Off the top of my head, I want to say __DATE__ and __TIME__, but check the compiler manual. It lists them all. I definitely recommend taking some time and reviewing it. You may find features you need that you didn't know you had available. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Mar 03, 2017 7:53 am |
|
|
Maybe this can be used, from the manual?
...
This pre-processor identifier is replaced at compile time with the time of the compile in the form: "hh:mm:ss"
printf("Software was compiled on ");
printf(__TIME__);
...
There's also one for __DATE__
Jay |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Fri Mar 03, 2017 8:01 am |
|
|
This is my line:
fprintf( SERIAL_MONITOR, "\n\r[Starting -- build no. %lu on %lu %lu]", __BUILDCOUNT__, __DATE__, __TIME__ );
Ben
[EDIT] Just realized that __DATE__ and __TIME__ are strings. That works. But buildcount still isn't recognized. Is it supported in 5.026? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Mar 03, 2017 9:07 am |
|
|
from the net....somewhere...
5.027 Added __BUILDCOUNT__ id when global defines are enabled
maybe time to contact CCS ??
Jay |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Fri Mar 03, 2017 9:10 am |
|
|
hehe... well I have compiler 5.069 but for the last week, until I reverted back to 5.026, I had just problems after problems.
Maybe I will re-install and try it again.
Thanks!
Benoit |
|
|
|