Page 1 of 1

Appending version number to project bin file

Posted: Sun Jan 31, 2021 10:46 am
by alsaleem00
I managed to set app version number to project using PROJECT_VER in "CMakeLists.txt".

If I compile the project, it will produce {projectname}.bin.
I can read the version using code. However, all versions have same bin name.

Is there a config variable i can use to make build produces distinctive bin name based on PROJECT_VER and/or other variable ?
Something like {projectname}_{othervar}_{PROJECT_VER}.bin

Thanks.

Re: Appending version number to project bin file

Posted: Mon Feb 01, 2021 7:39 am
by chegewara
How about this:

Code: Select all

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(PROJECT_VER "1.0.0")
project(projectname_${PROJECT_VER})
Only thing is that PROJECT_VER is stripped after first dot which will result:

Code: Select all

-- App "projectname_1.0.0" version: 1.0.0
...
build/projectname_1.bin


Maybe @Angus can help with that.

Re: Appending version number to project bin file

Posted: Mon Feb 01, 2021 11:49 am
by alsaleem00
Hi @chegewara,
this is smart approach.
Indeed, it will produce {projectname}_1.bin for (1.0.1) PROJECT_VER.

I tried to concat the two strings out side like

set(PROJECT_VER "3.0.1")
set(PROJECT_PREF "myproject")
set(PROJECT_BIN "${PROJECT_PREF}_${PROJECT_VER}")

project(${PROJECT_BIN})
but same result. It looks that dot is prohibited?

can you help @Angus ?

thanks.

Re: Appending version number to project bin file

Posted: Mon Feb 01, 2021 12:25 pm
by alsaleem00
It looks that this is a problem with cmake.
If i replace dots with underscore 1_0_1, it works.
.map & .elf files are produced correctly (with dots)

Any further suggestion?

Thanks.

Re: Appending version number to project bin file

Posted: Mon Feb 01, 2021 5:22 pm
by alsaleem00
I came up with a compromise solution:

Code: Select all

set(PROJECT_VER "4.0.1")
set(PROJECT_VERU ${PROJECT_VER})
set(PROJECT_PREF "myproject")

string (REPLACE "\." "_" PROJECT_VERU ${PROJECT_VERU})
set(PROJECT_BIN "${PROJECT_PREF}_${PROJECT_VERU}")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

project("${PROJECT_BIN}")
This way i keep the version number inside with "dot" and produce bin file that shows version with underscore.

Thanks.