2
# Copyright 2009-2010 Jakob Westhoff. All rights reserved.
2
# Copyright (C) 2014 Raster Software Vigo
3
# Autovala is free software: you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License as published by the
5
# Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# Autovala is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
# See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
16
# Copyright (C) 2013, Valama development team
18
# Copyright 2009-2010 Jakob Westhoff All rights reserved.
4
20
# Redistribution and use in source and binary forms, with or without
5
21
# modification, are permitted provided that the following conditions are met:
7
# 1. Redistributions of source code must retain the above copyright notice,
8
# this list of conditions and the following disclaimer.
23
# 1. Redistributions of source code must retain the above copyright notice,
24
# this list of conditions and the following disclaimer.
10
# 2. Redistributions in binary form must reproduce the above copyright notice,
11
# this list of conditions and the following disclaimer in the documentation
12
# and/or other materials provided with the distribution.
26
# 2. Redistributions in binary form must reproduce the above copyright notice,
27
# this list of conditions and the following disclaimer in the documentation
28
# and/or other materials provided with the distribution.
14
30
# THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR
15
31
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
52
68
# If no option is specified the version will be treated as a minimal version.
54
macro(ensure_vala_version version)
55
parse_arguments(ARGS "" "MINIMUM;MAXIMUM;EXACT" ${ARGN})
56
set(compare_message "")
59
set(compare_message "a minimum ")
60
set(error_message "or greater ")
62
set(compare_message "a maximum ")
63
set(error_message "or less ")
67
"checking for ${compare_message}Vala version of ${version}"
70
unset(version_accepted)
72
# MINIMUM is the default if no option is specified
74
if(${VALA_VERSION} VERSION_EQUAL ${version} )
75
set(version_accepted TRUE)
76
endif(${VALA_VERSION} VERSION_EQUAL ${version})
78
if(${VALA_VERSION} VERSION_LESS ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version})
79
set(version_accepted TRUE)
80
endif(${VALA_VERSION} VERSION_LESS ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version})
82
if(${VALA_VERSION} VERSION_GREATER ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version})
83
set(version_accepted TRUE)
84
endif(${VALA_VERSION} VERSION_GREATER ${version} OR ${VALA_VERSION} VERSION_EQUAL ${version})
87
if (NOT version_accepted)
89
"Vala version ${version} ${error_message}is required."
70
macro(ensure_vala_version ensure_version)
73
message(STATUS "Forced use of vala binary ${USE_VALA_BINARY}")
74
set(VALA_EXECUTABLE ${USE_VALA_BINARY})
75
else (USE_VALA_BINARY)
77
message(STATUS "checking for Vala version of valac-${ensure_version}")
79
unset(version_accepted)
80
execute_process(COMMAND "valac-${ensure_version}" "--version"
81
OUTPUT_VARIABLE "VALA_VERSION" OUTPUT_STRIP_TRAILING_WHITESPACE)
84
find_program(VALA_EXECUTABLE "valac")
86
# If the specific version asked for this project is not found,
87
# try to use the one pointed by the valac link
89
parse_arguments(ARGS "" "MINIMUM;MAXIMUM;EXACT" ${ARGN})
90
set(compare_message "")
93
set(compare_message "a minimum ")
94
set(error_message "or greater ")
96
set(compare_message "a maximum ")
97
set(error_message "or less ")
100
message(STATUS "checking for ${compare_message}Vala version of ${ensure_version}" )
102
execute_process(COMMAND ${VALA_EXECUTABLE} "--version"
103
OUTPUT_VARIABLE "VALA_VERSION" OUTPUT_STRIP_TRAILING_WHITESPACE)
104
else(NOT VALA_VERSION)
105
set(VALA_EXECUTABLE "valac-${ensure_version}")
106
endif(NOT VALA_VERSION)
108
# this code allows to identify development versions as the right version
109
# e.g. 0.19.1 -> 0.20 ; 0.20.1 -> 0.20 ; 0.24.0.2-2235 -> 0.26
110
# Thanks to Yannick Inizan
111
string(REPLACE "Vala" "" "VALA_VERSION" ${VALA_VERSION})
112
string(STRIP ${VALA_VERSION} "VALA_VERSION")
113
string(REPLACE "." ";" VALA_LIST "${VALA_VERSION}")
114
list(GET VALA_LIST 0 maj_ver)
115
list(GET VALA_LIST 1 min_ver)
116
list(GET VALA_LIST 2 rev_ver)
117
math(EXPR is_odd "${min_ver} % 2")
118
list(LENGTH VALA_LIST len)
119
if((${is_odd} EQUAL 1))
120
math(EXPR min_ver "${min_ver} + 1")
121
elseif(len GREATER 3)
122
math(EXPR min_ver "${min_ver} + 2")
125
set(VALA_SVERSION "${maj_ver}.${min_ver}" CACHE INTERNAL "")
127
# MINIMUM is the default if no option is specified
129
if(${VALA_SVERSION} VERSION_EQUAL ${ensure_version} )
130
set(version_accepted TRUE)
131
endif(${VALA_SVERSION} VERSION_EQUAL ${ensure_version})
133
if(${VALA_SVERSION} VERSION_LESS ${ensure_version} OR ${VALA_SVERSION} VERSION_EQUAL ${ensure_version})
134
set(version_accepted TRUE)
135
endif(${VALA_SVERSION} VERSION_LESS ${ensure_version} OR ${VALA_SVERSION} VERSION_EQUAL ${ensure_version})
137
if(${VALA_SVERSION} VERSION_GREATER ${ensure_version} OR ${VALA_SVERSION} VERSION_EQUAL ${ensure_version})
138
set(version_accepted TRUE)
139
endif(${VALA_SVERSION} VERSION_GREATER ${ensure_version} OR ${VALA_SVERSION} VERSION_EQUAL ${ensure_version})
142
if (NOT version_accepted)
144
"Vala version ${ensure_version} ${error_message}is required."
146
endif(NOT version_accepted)
149
" found Vala, version ${VALA_SVERSION}"
91
endif(NOT version_accepted)
94
" found Vala, version ${VALA_VERSION}"
151
endif(USE_VALA_BINARY)
96
152
endmacro(ensure_vala_version)