Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem2/cmake/DetermineVersion.cmake @ 2577

Last change on this file since 2577 was 2577, checked in by rgrieder, 16 years ago

Improved DetermineVersion.cmake

File size: 1.9 KB
RevLine 
[2573]1#    DetermineVersion.cmake - CMake Module to get the version of a library from
2#                             a header file.
3#    Author: Reto '1337' Grieder (2009)
4#
5#    This program is free software; you can redistribute it and/or modify
6#    it under the terms of the GNU General Public License as published by
7#    the Free Software Foundation; either version 2 of the License, or
8#    (at your option) any later version.
9#
10#    This program is distributed in the hope that it will be useful,
11#    but WITHOUT ANY WARRANTY; without even the implied warranty of
12#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#    GNU General Public License for more details.
14#
15#    You should have received a copy of the GNU General Public License
16#    along with this program; if not, write to the Free Software
17#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18
[2577]19MACRO(DetermineVersion _name _file)
[2573]20  FILE(READ ${_file} _file_content)
21  IF(_file_content)
[2577]22    SET(_parts ${ARGN})
23    LIST(LENGTH _parts _parts_length)
24    IF(NOT ${_parts_length} EQUAL 3)
25      SET(_parts MAJOR MINOR PATCH)
26    ENDIF(NOT ${_parts_length} EQUAL 3)
27
28    FOREACH(_part ${_parts})
29      STRING(REGEX MATCH "${_name}_VERSION_${_part} +([0-9]+)" _match ${_file_content})
30      IF(_match)
31        SET(${_name}_VERSION_${_part} ${CMAKE_MATCH_1} CACHE STRING "")
32      ELSE(_match)
33        SET(${_name}_VERSION_${_part} "0" CACHE STRING "")
34      ENDIF(_match)
35      MARK_AS_ADVANCED(${_name}_VERSION_${_part})
36      IF("${_parts}" MATCHES "^${_part}") # First?
37        SET(${_name}_VERSION "${${_name}_VERSION_${_part}}" CACHE STRING "" FORCE)
38      ELSE("${_parts}" MATCHES "^${_part}")
39        SET(${_name}_VERSION "${${_name}_VERSION}.${${_name}_VERSION_${_part}}" CACHE STRING "" FORCE)
40      ENDIF("${_parts}" MATCHES "^${_part}")
41    ENDFOREACH(_part)
42    MARK_AS_ADVANCED(${_name}_VERSION)
[2573]43  ENDIF(_file_content)
44ENDMACRO(DetermineVersion)
Note: See TracBrowser for help on using the repository browser.