[CMake] convert variable from hex to integer
Eric Noulard
eric.noulard at gmail.com
Fri Sep 19 09:02:46 EDT 2008
2008/9/19 Olaf Peter <ope-devel at gmx.de>:
> Hi,
>
> for a generated version header I need to convert a given hex to an integer.
> I've wrote:
>
> set(RELEASE_LEVEL_ALPHA 0xA) # For internal use
> set(RELEASE_LEVEL_BETA 0xB) # For internal use
> set(RELEASE_LEVEL_GAMMA 0xC) # For release candidates
> set(RELEASE_LEVEL_FINAL 0xF) # For final release
>
> set(VERSION_MAJOR 0)
> set(VERSION_MINOR 1)
> set(VERSION_MICRO 0)
> set(RELEASE_LEVEL ${RELEASE_LEVEL_ALPHA})
> set(RELEASE_SERIAL 0)
>
> in CMakeLists.txt and in version.h.cmake:
>
> enum {
> MAJOR = (@VERSION_MAJOR@ << 24),
> MINOR = (@VERSION_MINOR@ << 16),
> MICRO = (@VERSION_MICRO@ << 8),
> RELEASE_LEVEL = (@RELEASE_LEVEL@ << 4),
> RELEASE_SERIAL = (@RELEASE_SERIAL@ << 0),
> VERSION = MAJOR | MINOR | MICRO | RELEASE_LEVEL |
> RELEASE_SERIAL
> };
>
> which results into:
>
> enum {
> MAJOR = (0 << 24),
> MINOR = (1 << 16),
> MICRO = (0 << 8),
> RELEASE_LEVEL = (0xA << 4),
> RELEASE_SERIAL = (0 << 0),
> VERSION = MAJOR | MINOR | MICRO | RELEASE_LEVEL |
> RELEASE_SERIAL
> };
>
> The 0xA doesn't compile.
Do you mean that the generated enum does compile with your compiler?
Which error do get?
gcc / g++ 4.1.2
do compile the preceding enum definition without trouble?
--
Erk
More information about the CMake
mailing list