| 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 | |
|---|
| 19 | MACRO(DETERMINE_VERSION _name _file) |
|---|
| 20 | FILE(READ ${_file} _file_content) |
|---|
| 21 | IF(_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(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) |
|---|
| 43 | ENDIF(_file_content) |
|---|
| 44 | ENDMACRO(DETERMINE_VERSION) |
|---|