Salome HOME
Merge branch 'agr/medcoupling_tool'
[tools/medcoupling.git] / cmake_files / MEDCouplingMacros.cmake
1 # Copyright (C) 2015  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17
18 ####################################################################
19 # _TOHEXA()
20 # Convert a number (smaller than 16) into hexadecimal representation
21 # with a leading 0.
22 MACRO(_TOHEXA num result)
23   SET(_hexa_map a b c d e f)
24   IF(${num} LESS 10)
25     SET(${result} "0${num}")
26   ELSE()
27     MATH(EXPR _res "${num}-10" )
28     LIST(GET _hexa_map ${_res} _out)
29     SET(${result} "0${_out}")
30   ENDIF()
31 ENDMACRO(_TOHEXA)
32
33 ####################################################################
34 # MEDCOUPLING_XVERSION()
35 #
36 # Computes hexadecimal version of MEDCOUPLING package
37 #
38 # USAGE: MEDCOUPLING_XVERSION(package)
39 #
40 # ARGUMENTS:
41 #
42 # package: IN: MEDCOUPLING package name
43 #
44 # The macro reads MEDCOUPLING package version from PACKAGE_VERSION variable
45 # (note package name are uppercase);
46 # hexadecimal version value in form 0xAABBCC (where AA, BB and CC are
47 # major, minor and maintenance components of package version in
48 # hexadecimal form) is put to the PACKAGE_XVERSION variable
49 MACRO(MEDCOUPLING_XVERSION pkg)
50   STRING(TOUPPER ${pkg} _pkg_UC)
51   IF(${_pkg_UC}_VERSION)
52     SET(_major)
53     SET(_minor)
54     SET(_patch)
55     _TOHEXA(${${_pkg_UC}_MAJOR_VERSION} _major)
56     _TOHEXA(${${_pkg_UC}_MINOR_VERSION} _minor)
57     _TOHEXA(${${_pkg_UC}_PATCH_VERSION} _patch)
58     SET(${_pkg_UC}_XVERSION "0x${_major}${_minor}${_patch}")
59   ENDIF()
60 ENDMACRO(MEDCOUPLING_XVERSION)