~davidagraf/zorba/allow_c_files

« back to all changes in this revision

Viewing changes to cmake_modules/Windows/ProxyFindModule.cmake

  • Committer: Tarmac
  • Author(s): Gabriel Petrovay
  • Date: 2011-09-28 12:19:24 UTC
  • mfrom: (10469.2.1 fixcurl)
  • Revision ID: tarmac-20110928121924-ywd0sf3g9hsevv3o
Fixing the wrong fix in FindCURL.cmake introduced in:

revno: 10390
svn revno: 11875 (on /trunk/zorba)

This fix adds a new macro to the cmake_modules/Windows/ProxyFindModule.cmake module (FIND_PACKAGE_DLL_WIN32) that allows you to search for ONLY ONE DLL but using alternate names. cURL, for example, needs this because some versions distribute curllib.dll, while others libcurl.dll. Approved: Daniel Turcanu

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
 
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.
 
59
#
 
60
# Therefore the following parameter names must be provided to this macro:
54
61
# Parameters:
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"
 
62
#   NAME
 
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.
 
66
#   FOUND_VAR
 
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
 
70
#   SEARCH_NAMES
 
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"
 
74
#   COMPONENTS
 
75
#     - optional, multiple value
61
76
#
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
64
79
#
65
80
MACRO (FIND_PACKAGE_WIN32)
66
 
  PARSE_ARGUMENTS(MODULE "SEARCH_NAMES;COMPONENTS" "NAME;FOUND_VAR" "TEST_ONLY" ${ARGN})
67
 
  
 
81
 
68
82
  IF (NOT WIN32)
69
 
    MESSAGE(FATAL_ERROR "This macro is intended only for Windows platforms.")
 
83
    MESSAGE (FATAL_ERROR "This macro is intended only for Windows platforms.")
70
84
  ENDIF (NOT WIN32)
71
85
 
 
86
  PARSE_ARGUMENTS(MODULE "SEARCH_NAMES;COMPONENTS" "NAME;FOUND_VAR" "" ${ARGN})
 
87
  
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)
186
202
 
187
203
 
188
 
MACRO(FIND_PACKAGE_DLLS_WIN32 LIBRARY_LOCATION DLL_NAMES)
189
 
 
190
 
  IF (NOT WIN32)
191
 
    MESSAGE(FATAL_ERROR "This macro is intended only for Windows platforms.")
192
 
  ENDIF (NOT WIN32)
 
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"
 
209
#
 
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.
 
213
#
 
214
MACRO (FIND_PACKAGE_DLL_WIN32 LIBRARY_LOCATION)
 
215
 
 
216
  IF (NOT WIN32)
 
217
    MESSAGE (FATAL_ERROR "This macro is intended only for Windows platforms.")
 
218
  ENDIF (NOT WIN32)
 
219
 
 
220
  # get the current DLLs and their paths
 
221
  SET (dlls "${ZORBA_REQUIRED_DLLS}")
 
222
  SET (paths "${ZORBA_REQUIRED_DLL_PATHS}")
 
223
 
 
224
  FOREACH (NAME ${ARGN})
 
225
 
 
226
    # first delete the cache entry used during FIND_FILE to make sure the correct file is chosen
 
227
    UNSET (TMP_DLL_VAR CACHE)
 
228
 
 
229
    # find now the DLL
 
230
    FIND_FILE (
 
231
      TMP_DLL_VAR
 
232
      "${NAME}.dll"
 
233
      PATHS "${LIBRARY_LOCATION}"
 
234
      PATH_SUFFIXES "bin" "bin/Release" 
 
235
      NO_DEFAULT_PATH
 
236
    )
 
237
 
 
238
    IF (TMP_DLL_VAR)
 
239
 
 
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}")
 
245
 
 
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")
 
250
 
 
251
      # we break the loop if we found one DLL
 
252
      BREAK ()
 
253
 
 
254
    ENDIF (TMP_DLL_VAR)
 
255
 
 
256
  ENDFOREACH (NAME)
 
257
 
 
258
  # we report a warning if the DLL could not be found
 
259
  IF (NOT TMP_DLL_VAR)
 
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)
 
262
 
 
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)
 
265
 
 
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)
 
271
 
 
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)
 
274
 
 
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
 
279
    )
 
280
    SET (ZORBA_REQUIRED_DLL_PATHS "${paths}"
 
281
      CACHE STRING "List of paths executable require in order to find the required DLLs" FORCE
 
282
    )
 
283
  ENDIF (${PROJECT_NAME} STREQUAL  "zorba")
 
284
 
 
285
ENDMACRO (FIND_PACKAGE_DLL_WIN32)
 
286
 
 
287
 
 
288
MACRO (FIND_PACKAGE_DLLS_WIN32 LIBRARY_LOCATION DLL_NAMES)
 
289
 
 
290
  IF (NOT WIN32)
 
291
    MESSAGE (FATAL_ERROR "This macro is intended only for Windows platforms.")
 
292
  ENDIF (NOT WIN32)
 
293
 
193
294
  # get the current DLLs and their paths
194
295
  SET (dlls "${ZORBA_REQUIRED_DLLS}")
195
296
  SET (paths "${ZORBA_REQUIRED_DLL_PATHS}")
196
297
 
197
298
  FOREACH (NAME ${DLL_NAMES})
198
299
 
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)
201
302
 
202
303
    # find now the DLL
211
312
    IF (TMP_DLL_VAR)
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}")
217
 
      
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")
222
 
     
223
 
      
 
317
      MESSAGE (STATUS "Added dll to ZORBA_REQUIRED_DLLS cache variable: ${TMP_DLL_VAR}")
 
318
 
 
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")
 
323
 
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)
227
 
    
 
327
 
228
328
  ENDFOREACH (NAME)
229
329
 
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)
232
332
 
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)
237
338
 
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)
240
341
 
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
246
347
    SET (ZORBA_REQUIRED_DLL_PATHS "${paths}"
247
348
      CACHE STRING "List of paths executable require in order to find the required DLLs" FORCE
248
349
    )
249
 
  ENDIF(${PROJECT_NAME} STREQUAL  "zorba")
 
350
  ENDIF (${PROJECT_NAME} STREQUAL  "zorba")
250
351
 
251
 
ENDMACRO(FIND_PACKAGE_DLLS_WIN32)
 
352
ENDMACRO (FIND_PACKAGE_DLLS_WIN32)
252
353
 
253
354
 
254
355
MACRO (FIND_DLL_WIN32 DLL_NAME)
293
394
  # make sure we don't leave garbage in the cache and don't influence other logic with this
294
395
  UNSET (TMP_DLL_VAR CACHE)
295
396
 
 
397
  # remove duplicates from the path list
 
398
  LIST (LENGTH paths LEN)
 
399
  IF (${LEN} GREATER 0)
 
400
    LIST (REMOVE_DUPLICATES paths)
 
401
  ENDIF (${LEN} GREATER 0)
 
402
 
296
403
  # set the current DLLs and their paths in a variable
297
404
  SET (ZORBA_REQUIRED_DLLS "${dlls}"
298
405
    CACHE STRING "List of DLLs that must be installed" FORCE
307
414
MACRO (ADD_DLL_WIN32 DLL_PATH DLL_NAME)
308
415
 
309
416
  IF (NOT WIN32)
310
 
    MESSAGE(FATAL_ERROR "This macro is intended only for Windows platforms.")
 
417
    MESSAGE (FATAL_ERROR "This macro is intended only for Windows platforms.")
311
418
  ENDIF (NOT WIN32)
312
419
 
313
420
  # get the current DLLs and their paths