53
53
# This macro will try to find a third party library on Windows.
54
# The parameters must be given the arguments using the following pattern:
55
# PARAM_NAME1 param_value1 PARAM_NAME2 param_value1 param_value2 ...
56
# This macro will further call PARSE_ARGUMENTS to parse it's arguments.
57
# In the patter above, PARAM_NAME1 will go in the single value parameter pool
58
# while PARAM_NAME2 will go in the multiple value parameter pool.
60
# Therefore the following parameter names must be provided to this macro:
55
# NAME - the XXX in the FindXXX.cmake that is used for search
56
# e.g.: "ICU" when trying to find ICU with FindICU.cmake
57
# FOUND_VAR - the variable the FindXXX.cmake module sets if the library is found
58
# e.g.: "XERCESC_FOUND" when trying to find XercesC
59
# SEARCH_NAMES - a list of possible directory name fragments that this library can have
60
# e.g.: "icu;i_c_u;uci"
63
# - mandatory, single value
64
# - the value following it will be used to build the CMake module file name.
65
# - e.g.: providing NAME "ICU" as parameters, FindICU.cmake will be used for the search.
67
# - mandatory, single value
68
# - the variable that the FindXXX.cmake module sets if the library is found
69
# - e.g.: FOUND_VAR "XERCESC_FOUND" when trying to find XercesC
71
# - mandatory, multiple value
72
# - the possible directory name fragments that this library can have
73
# - e.g.: SEARCH_NAMES "icu" "i_c_u" "uci"
75
# - optional, multiple value
62
77
# Once done this will define:
63
# FOUND_LOCATION - The directory where the library was found
78
# FOUND_LOCATION - The directory where the library was found
65
80
MACRO (FIND_PACKAGE_WIN32)
66
PARSE_ARGUMENTS(MODULE "SEARCH_NAMES;COMPONENTS" "NAME;FOUND_VAR" "TEST_ONLY" ${ARGN})
69
MESSAGE(FATAL_ERROR "This macro is intended only for Windows platforms.")
83
MESSAGE (FATAL_ERROR "This macro is intended only for Windows platforms.")
86
PARSE_ARGUMENTS(MODULE "SEARCH_NAMES;COMPONENTS" "NAME;FOUND_VAR" "" ${ARGN})
72
88
IF(NOT MODULE_NAME)
73
89
MESSAGE (FATAL_ERROR "'NAME' argument is required")
74
90
ENDIF(NOT MODULE_NAME)
185
201
ENDMACRO (FIND_PACKAGE_WIN32)
188
MACRO(FIND_PACKAGE_DLLS_WIN32 LIBRARY_LOCATION DLL_NAMES)
191
MESSAGE(FATAL_ERROR "This macro is intended only for Windows platforms.")
204
# This macro will search for a DLL in the given library location using extra
205
# arguments as alternative names of the DLL. The first DLL found with that name
206
# is considered. This is useful for some libraries that come with different DLL
207
# names depending on the library version. For example, cURL library might
208
# distribute it's main DLL with two different names: "libcurl.dll" or "curllib.dll"
210
# If the DLL is found it's full path will be added to ZORBA_REQUIRED_DLLS and
211
# it's location to the ZORBA_REQUIRED_DLL_PATHS variable. These will be later
212
# used when installing zorba.
214
MACRO (FIND_PACKAGE_DLL_WIN32 LIBRARY_LOCATION)
217
MESSAGE (FATAL_ERROR "This macro is intended only for Windows platforms.")
220
# get the current DLLs and their paths
221
SET (dlls "${ZORBA_REQUIRED_DLLS}")
222
SET (paths "${ZORBA_REQUIRED_DLL_PATHS}")
224
FOREACH (NAME ${ARGN})
226
# first delete the cache entry used during FIND_FILE to make sure the correct file is chosen
227
UNSET (TMP_DLL_VAR CACHE)
233
PATHS "${LIBRARY_LOCATION}"
234
PATH_SUFFIXES "bin" "bin/Release"
240
LIST (APPEND dlls "${TMP_DLL_VAR}")
241
STRING (REPLACE "/${NAME}.dll" "" PATH "${TMP_DLL_VAR}")
242
FILE (TO_NATIVE_PATH ${PATH} NATIVE_PATH)
243
LIST (APPEND paths "${NATIVE_PATH}")
244
MESSAGE (STATUS "Added dll to ZORBA_REQUIRED_DLLS cache variable: ${TMP_DLL_VAR}")
246
IF (NOT ${PROJECT_NAME} STREQUAL "zorba")
247
STRING (REPLACE "-" "_" component_name ${PROJECT_NAME})
248
INSTALL (PROGRAMS ${TMP_DLL_VAR} DESTINATION bin COMPONENT ${component_name})
249
ENDIF (NOT ${PROJECT_NAME} STREQUAL "zorba")
251
# we break the loop if we found one DLL
258
# we report a warning if the DLL could not be found
260
MESSAGE (WARNING "None of the names provided (${ARGN}) points to a DLL in: ${LIBRARY_LOCATION}. Zorba will not run properly unless you have it in the path.")
261
ENDIF (NOT TMP_DLL_VAR)
263
# make sure we don't leave garbage in the cache and don't influence other logic with this
264
UNSET (TMP_DLL_VAR CACHE)
266
# remove duplicates from the path list
267
LIST (LENGTH paths LEN)
268
IF (${LEN} GREATER 0)
269
LIST (REMOVE_DUPLICATES paths)
270
ENDIF (${LEN} GREATER 0)
272
# make sure we don't leave garbage in the cache and don't influence other logic with this
273
SET (TMP_DLL_VAR TMP_DLL_VAR-NOTFOUND CACHE FILEPATH "Path to a file." FORCE)
275
IF (${PROJECT_NAME} STREQUAL "zorba")
276
# set the current DLLs and their paths in a variable
277
SET (ZORBA_REQUIRED_DLLS "${dlls}"
278
CACHE STRING "List of DLLs that must be installed" FORCE
280
SET (ZORBA_REQUIRED_DLL_PATHS "${paths}"
281
CACHE STRING "List of paths executable require in order to find the required DLLs" FORCE
283
ENDIF (${PROJECT_NAME} STREQUAL "zorba")
285
ENDMACRO (FIND_PACKAGE_DLL_WIN32)
288
MACRO (FIND_PACKAGE_DLLS_WIN32 LIBRARY_LOCATION DLL_NAMES)
291
MESSAGE (FATAL_ERROR "This macro is intended only for Windows platforms.")
193
294
# get the current DLLs and their paths
194
295
SET (dlls "${ZORBA_REQUIRED_DLLS}")
195
296
SET (paths "${ZORBA_REQUIRED_DLL_PATHS}")
197
298
FOREACH (NAME ${DLL_NAMES})
199
# first delete the cache entry for DLL to make sure the correct one is chosen
300
# first delete the cache entry used during FIND_FILE to make sure the correct file is chosen
200
301
UNSET (TMP_DLL_VAR CACHE)
202
303
# find now the DLL
212
313
LIST (APPEND dlls "${TMP_DLL_VAR}")
213
314
STRING (REPLACE "/${NAME}" "" PATH "${TMP_DLL_VAR}")
214
FILE(TO_NATIVE_PATH ${PATH} NATIVE_PATH)
315
FILE (TO_NATIVE_PATH ${PATH} NATIVE_PATH)
215
316
LIST (APPEND paths "${NATIVE_PATH}")
216
MESSAGE(STATUS "Added dll to ZORBA_REQUIRED_DLLS cache variable: ${TMP_DLL_VAR}")
218
IF(NOT ${PROJECT_NAME} STREQUAL "zorba")
219
STRING(REPLACE "-" "_" component_name ${PROJECT_NAME})
220
INSTALL(PROGRAMS ${TMP_DLL_VAR} DESTINATION bin COMPONENT ${component_name})
221
ENDIF(NOT ${PROJECT_NAME} STREQUAL "zorba")
317
MESSAGE (STATUS "Added dll to ZORBA_REQUIRED_DLLS cache variable: ${TMP_DLL_VAR}")
319
IF (NOT ${PROJECT_NAME} STREQUAL "zorba")
320
STRING (REPLACE "-" "_" component_name ${PROJECT_NAME})
321
INSTALL (PROGRAMS ${TMP_DLL_VAR} DESTINATION bin COMPONENT ${component_name})
322
ENDIF (NOT ${PROJECT_NAME} STREQUAL "zorba")
224
324
ELSE (TMP_DLL_VAR)
225
MESSAGE (WARNING "${NAME} was not found in: ${LIBRARY_LOCATION}. Zorba will not run unless you have it in the path.")
325
MESSAGE (WARNING "${NAME} was not found in: ${LIBRARY_LOCATION}. Zorba will not run properly unless you have it in the path.")
226
326
ENDIF (TMP_DLL_VAR)
228
328
ENDFOREACH (NAME)
230
330
# make sure we don't leave garbage in the cache and don't influence other logic with this
231
331
UNSET (TMP_DLL_VAR CACHE)
233
LIST(LENGTH paths LEN)
333
# remove duplicates from the path list
334
LIST (LENGTH paths LEN)
234
335
IF (${LEN} GREATER 0)
235
LIST(REMOVE_DUPLICATES paths)
336
LIST (REMOVE_DUPLICATES paths)
236
337
ENDIF (${LEN} GREATER 0)
238
339
# make sure we don't leave garbage in the cache and don't influence other logic with this
239
340
SET (TMP_DLL_VAR TMP_DLL_VAR-NOTFOUND CACHE FILEPATH "Path to a file." FORCE)
241
IF(${PROJECT_NAME} STREQUAL "zorba")
342
IF (${PROJECT_NAME} STREQUAL "zorba")
242
343
# set the current DLLs and their paths in a variable
243
344
SET (ZORBA_REQUIRED_DLLS "${dlls}"
244
345
CACHE STRING "List of DLLs that must be installed" FORCE