Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2624 was 2624, checked in by rgrieder, 15 years ago

Replaced most of the ELSE(…) and ENDIF(…) with ELSE() and ENDIF(). Kept the shorter and the spreaded ones for better clarity since that's what it originally was thought for. But I can really pollute the code when having long conditions and lots of IFs.

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
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
19FUNCTION(DETERMINE_VERSION _name _file)
20  IF(EXISTS ${_file})
21    FILE(READ ${_file} _file_content)
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()
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})
32        SET(${_name}_VERSION_${_part} ${CMAKE_MATCH_1} PARENT_SCOPE)
33      ELSE()
34        SET(${_name}_VERSION_${_part} "0")
35        SET(${_name}_VERSION_${_part} "0" PARENT_SCOPE)
36      ENDIF()
37      IF("${_parts}" MATCHES "^${_part}") # First?
38        SET(${_name}_VERSION "${${_name}_VERSION_${_part}}")
39      ELSE()
40        SET(${_name}_VERSION "${${_name}_VERSION}.${${_name}_VERSION_${_part}}")
41      ENDIF()
42    ENDFOREACH(_part)
43    SET(${_name}_VERSION "${${_name}_VERSION}" PARENT_SCOPE)
44  ENDIF(EXISTS ${_file})
45ENDFUNCTION(DETERMINE_VERSION)
Note: See TracBrowser for help on using the repository browser.