-
Notifications
You must be signed in to change notification settings - Fork 0
/
ivy.cmake
391 lines (300 loc) · 12.6 KB
/
ivy.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# NOTE:
# ====
# This code moved to a new project: https://github.com/daniperez/CMakeLists.txt
#
# The MIT License
#
# Copyright (c) 2011 Daniel Perez (daniperez)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
############################################################################
# parse_arguments.cmake belongs to Cmake authors. See
#
# http://www.cmake.org/Wiki/CMakeMacroParseArguments
#
include ( parse_arguments )
############################################################################
############################################################################
############################################################################
set ( IVY_TAR_NAME "apache-ivy-2.2.0-bin.tar.gz"
CACHE STRING "Tarball name of Apache Ivy binary distribution" )
############################################################################
set ( IVY_DOWNLOAD_URL "http://www.apache.org/dist/ant/ivy/2.2.0/${IVY_TAR_NAME}"
CACHE STRING "URL of Apache Ivy binary distribution" )
############################################################################
set ( IVY_JAR_NAME "apache-ivy-2.2.0/ivy-2.2.0.jar"
CACHE STRING "Jar name of Apache Ivy binary distribution" )
############################################################################
set ( IVY_TMP_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/tmp"
CACHE STRING "Path to put downloaded artifacts and tarballs" )
############################################################################
############################################################################
macro ( cygpath INPUT OUTPUT )
execute_process (
COMMAND cygpath -u ${INPUT}
OUTPUT_VARIABLE ${OUTPUT}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endmacro()
macro ( cygpath_win INPUT OUTPUT )
execute_process (
COMMAND cygpath -m ${INPUT}
OUTPUT_VARIABLE ${OUTPUT}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endmacro()
#
# init_ivy - Sets up the environment to use Ivy. It downloads Ivy.
# It defines IVY_INIT_DONE to true if the setup was successful.
#
# init_ivy ( [REQUIRED] )
#
# REQUIRED makes the macro to abort the execution if Ivy cannot be properly
# set up.
#
macro ( init_ivy )
init_ivy_process_parameters ( _IVY_INIT ${ARGN} )
download ( "${IVY_DOWNLOAD_URL}" "${IVY_TMP_FOLDER}/${IVY_TAR_NAME}" "${_IVY_INIT_REQUIRED}" )
untar ( "${IVY_TMP_FOLDER}/${IVY_TAR_NAME}" )
set ( CACHE INTERNAL IVY_INIT_DONE true "If Ivy was correctly set up" )
endmacro ()
#
# get_ivy_artifact - Retrieves the given file from the given artifact
# or module.
#
# macro get_ivy_artifact ( file
# ORGANIZATION organization
# MODULE_NAME module_name
# REVISION revision
# MODULE_FILE module_file
# [CONFIG_FILE config_file] )
#
# file will be set by the macro to the file extracted from the jar.
# ORGANIZATION is the organization used in the module's ivy.xml descriptor.
# MODULE_NAME is the name of the module or artifact as per the ivy.xml.
# REVISION is the version to retrieve. MODULE_FILE is the file to extract
# from the moduleeither a comma-separated or a GLOB pattern.
# The optional argument CONFIG_FILE points to the ivysettings.xml
# file with the settings for the resolvers, caches and so on (see
# http://ant.apache.org/ivy/history/latest-milestone/settings.html ).
#
macro ( get_ivy_artifact file )
get_ivy_artifact_process_parameters ( _IVY_GET ${ARGN} )
if ( EXISTS "${IVY_TMP_FOLDER}/${_IVY_GET_MODULE_FILE}" )
set ( ${file} "${IVY_TMP_FOLDER}/${_IVY_GET_MODULE_FILE}" )
message ( STATUS "CMAKE-IVY: ${${file}} already exists. Lazyness is a gift: perseverance is overrated." )
else ()
if ( CYGWIN )
cygpath_win ( "${IVY_TMP_FOLDER}" IVY_TMP_FOLDER )
cygpath_win ( "${_IVY_GET_CONFIG_FILE}" _IVY_GET_CONFIG_FILE )
set ( _CACHE_PATTERN "${IVY_TMP_FOLDER}/[module]-[type].jar" )
elseif ( WIN32 )
set ( _CACHE_PATTERN "Z://${IVY_TMP_FOLDER}/[module]-[type].jar" )
else ()
set ( _CACHE_PATTERN "${IVY_TMP_FOLDER}/[module]-[type].jar" )
endif ()
ivy_resolve ( CWD ${IVY_TMP_FOLDER}
JAVA ${java}
IVYJAR ${IVY_TMP_FOLDER}/${IVY_JAR_NAME}
PKG_ORG ${_IVY_GET_ORGANIZATION}
PKG_NAME ${_IVY_GET_MODULE_NAME}
PKG_REV ${_IVY_GET_REVISION}
CACHE_PATTERN ${_CACHE_PATTERN}
CONFIG_FILE ${_IVY_GET_CONFIG_FILE} )
unjar (
JAR ${jar}
JARFILE ${IVY_TMP_FOLDER}/${_IVY_GET_MODULE_NAME}-jar.jar
FILE ${_IVY_GET_MODULE_FILE}
UNJARRED_FILE ${file}
CWD ${IVY_TMP_FOLDER} )
if ( CYGWIN )
cygpath_win ( "${${file}}" ${file} )
endif()
message ( STATUS "CMAKE-IVY: '${${file}}' extracted" )
endif ()
endmacro ()
#
# init_ivy_process_parameters - Processes the arguments for init_ivy.
# Private method, not meant to be used by final user.
#
# init_ivy_process_parameters ( PREFIX [parameters...] )
#
# It will process any PARAMETERS passed to the macro and it will set
# some variables prefixed by PREFIX.
#
macro ( init_ivy_process_parameters PREFIX )
parse_arguments ( ${PREFIX} "" "REQUIRED" ${ARGN} )
if ( 0 )
message ( "${PREFIX}_REQUIRED = ${${PREFIX}_REQUIRED}" )
endif ()
if ( _IVY_CONFIG_FILE )
if ( NOT EXISTS ${_IVY_CONFIG_FILE} )
message ( FATAL_ERROR "CMAKE-IVY: File ${_IVY_CONFIG_FILE} doesn't exist" )
endif ()
endif ()
if ( WIN32 )
set ( java "${JAVA_HOME}/bin/java.exe" CACHE STRING "java binary" )
set ( jar "${JAVA_HOME}/bin/jar.exe" CACHE STRING "jar binary" )
else ()
set ( java "${JAVA_HOME}/bin/java" CACHE STRING "java binary" )
set ( jar "${JAVA_HOME}/bin/jar" CACHE STRING "jar binary" )
endif ()
if ( NOT EXISTS "${java}" )
message ( FATAL_ERROR "CMAKE-IVY: A proper Java JDK was not found. Did you set JAVA_HOME?" )
endif ()
endmacro ()
#
# get_ivy_artifact_process_parameters - Parses the arguments for get_ivy_artifact.
# Private method, not meant to be used by final user.
#
# get_ivy_artifact_process_parameters ( PREFIX [parameters...] )
#
# It will process any PARAMETERS passed to the macro and it will set
# some variables prefixed by PREFIX.
#
macro ( get_ivy_artifact_process_parameters PREFIX )
if ( IVY_INIT_DONE )
message ( FATAL_ERROR "CMAKE-IVY: Call 'init_ivy' macro first" )
endif ()
parse_arguments ( ${PREFIX} "ORGANIZATION;MODULE_NAME;REVISION;MODULE_FILE;CONFIG_FILE" "" ${ARGN} )
if ( 0 )
message ( "${PREFIX}_ORGANIZATION = ${${PREFIX}_ORGANIZATION}" )
message ( "${PREFIX}_MODULE_NAME = ${${PREFIX}_MODULE_NAME}" )
message ( "${PREFIX}_REVISION = ${${PREFIX}_REVISION}" )
message ( "${PREFIX}_MODULE_FILE = ${${PREFIX}_MODULE_FILE}" )
message ( "${PREFIX}_CONFIG_FILE = ${${PREFIX}_CONFIG_FILE}" )
endif ()
endmacro ()
#
# ivy_resolve - Resolves a package accoring to the parameters.
# Private method, not meant to be used by final user.
#
# ivy_resolve ( CWD cwd
# JAVA java
# IVYJAR ivyjar
# PKG_ORG organization
# PKG_NAME name
# PKG_REV revision
# CACHE_PATTERN pattern
# [CONFIG_FILE config] )
#
#
macro ( ivy_resolve )
parse_arguments ( _IVY_RES "CWD;JAVA;IVYJAR;PKG_ORG;PKG_NAME;PKG_REV;CACHE_PATTERN;CONFIG_FILE" "" ${ARGN} )
if ( EXISTS "${IVY_TMP_FOLDER}/${_IVY_GET_MODULE_NAME}.jar" )
message ( STATUS "CMAKE-IVY: Skipping resolve, ${_IVY_RES_PKG_ORG}.${_IVY_RES_PKG_NAME}-${_IVY_RES_PKG_REV} is already there, I'm lazy enough to not downloading it twice." )
else ()
message ( STATUS "CMAKE-IVY: ======================= Ivy output =======================")
if ( _IVY_RES_CONFIG_FILE )
# NOTE: -cache/-retrieve flags might be dismissed if CONFIG_FILE is passed and it defines its own caches.
jexecute ( ${_IVY_RES_CWD} ${_IVY_RES_JAVA} "-jar;${_IVY_RES_IVYJAR};-warn;-cache;${_IVY_RES_CWD};-dependency;${_IVY_RES_PKG_ORG};${_IVY_RES_PKG_NAME};${_IVY_RES_PKG_REV};-notransitive;-settings;${_IVY_RES_CONFIG_FILE};-retrieve;${_IVY_RES_CACHE_PATTERN}" )
else ()
jexecute ( ${_IVY_RES_CWD} ${_IVY_RES_JAVA} "-jar;${_IVY_RES_IVYJAR};-warn;-cache;${_IVY_RES_CWD};-dependency;${_IVY_RES_PKG_ORG};${_IVY_RES_PKG_NAME};${_IVY_RES_PKG_REV};-notransitive;-retrieve;${_IVY_RES_CACHE_PATTERN}" )
endif ()
message ( STATUS "CMAKE-IVY: ===================== End Ivy output =====================")
endif ()
endmacro ()
# unjar - unjars the given file from the given jar file.
# Private method, not meant to be used by final user.
#
# unjar ( JAR jar
# JARFILE jarfile
# FILE file
# UNJARRED_FILE unjarredfile
# CWD cwd )
#
macro ( unjar JAR jar JARFILE jarfile FILE file UNJARRED_FILE unjarredfile CWD cwd )
if ( NOT EXISTS "${cwd}/${file}" )
jexecute ( ${cwd} ${jar} "-xf;${jarfile};${file}" )
endif ()
set ( ${unjarredfile} "${cwd}/${file}" )
endmacro ()
#
# untar - Untars the given tarball.
# Private method, not meant to be used by final user.
#
# untar ( TARGZ )
#
# TARGZ points to the tarball to decompress.
#
macro ( untar TARGZ )
execute_process ( COMMAND ${CMAKE_COMMAND} -E tar xfz ${TARGZ}
RESULT_VARIABLE _status
ERROR_VARIABLE _status_message
WORKING_DIRECTORY ${IVY_TMP_FOLDER} )
if ( NOT ${_status} EQUAL 0 )
message ( FATAL_ERROR "CMAKE-IVY: '${filename}' could not be extracted from '${TARGZ}': ${_status_message}" )
else ()
message ( STATUS "CMAKE-IVY: '${TARGZ}' extracted successfully" )
endif ()
endmacro ()
#
# download - Downloads the file pointed by the given URL to the given
# FILENAME.
# Private method, not meant to be used by final user.
#
# download ( URL FILENAME REQUIRED )
#
# URL points to a file to download. File is stored in FILENAME.
# If REQUIRED is passed, the macro will exit with a FATAL_ERROR.
#
#
macro ( download URL FILENAME )
set ( REQUIRED ${ARGV2} )
if ( NOT EXISTS "${FILENAME}" )
file ( DOWNLOAD "${URL}" "${FILENAME}" STATUS status )
list(GET status 0 _status )
list(GET status 1 _status_message )
if ( NOT ${_status} EQUAL 0 )
set ( error "I couldn't download ${URL}: ${_status_message}" )
if ( REQUIRED )
message ( FATAL_ERROR "CMAKE-IVY: ${error}" )
else ()
message ( STATUS "CMAKE-IVY: ${error}" )
endif ()
else ()
message ( STATUS "CMAKE-IVY: '${URL}' successfully downloaded to '${FILENAME}'" )
endif ()
else ()
message ( STATUS "CMAKE-IVY: '${URL}' already downloaded to '${FILENAME}'. I'm too lazy to do it again." )
endif ()
endmacro ()
#
# jexecute - Executesv the provided jvm executable with the given parameters.
# Private method, not meant to be used by final user.
#
# jexecute ( JAVA_CMD [parameters...] )
#
# JAVA_CMD points to a java or java.exe executable, or any other executable. PARAMETERS
# will be appended to the call to JAVA_CMD.
# COMMAND_INTERPRETER is used to execute win32 binaries in a cross-compiling environment.
#
macro ( jexecute CWD JAVA_CMD )
message ( STATUS "CMAKE-IVY: Executing '${JAVA_CMD} ${ARGN}'" )
execute_process (
COMMAND ${COMMAND_INTERPRETER} ${JAVA_CMD} ${ARGN}
RESULT_VARIABLE result
ERROR_VARIABLE error
WORKING_DIRECTORY ${CWD}
)
if ( NOT ${result} EQUAL 0 )
message ( FATAL_ERROR "CMAKE-IVY: Error executing: ${error}" )
endif ()
endmacro ()