do not raise notice for objects in HH\array_mark_legacy()
[hiphop-php.git] / CMake / HHVMExtensionConfig.cmake
blob445c703022ce640496b8ce2046441a1843540eca
1 # This file holds the configuration mechanism for extensions.
3 # Now, the structure of the globals this uses.
5 # HHVM_EXTENSION_COUNT: <int>
6 # An integer representing the number of extensions that have
7 # been defined.
9 # HHVM_EXTENSIONS_REQUIRED_LIBRARIES: <list of paths>
10 # A list of the additional libraries that need to be linked
11 # against for the enabled extensions.
13 # HHVM_EXTENSIONS_REQUIRED_INCLUDE_DIRS: <list of paths>
14 # A list of the additional include paths that need to be used
15 # in order to compile the enabled extensions.
17 # HHVM_EXTENSIONS_REQUIRED_DEFINES: <list of strings>
18 # A list of the additional defines that need to be used in order
19 # to compile the enabled extensions.
22 # The extensions' internal info is stored in globals, prefixed by
23 # HHVM_EXTENSION_#_ where # represents a number between 0 and
24 # HHVM_EXTENSION_COUNT.
26 # HHVM_EXTENSION_#_NAME: <string>
27 # The name of extension.
29 # HHVM_EXTENSION_#_PRETTY_NAME: <string>
30 # The name of the extension to use in messages.
32 # HHVM_EXTENSION_#_REQUIRED: <ON/OFF>
33 # If ON, then the extension is integral to the function
34 # of HHVM itself, so failing to build it is not an option,
35 # and a FATAL_ERROR should be triggered if dependencies
36 # fail.
38 # HHVM_EXTENSION_#_ROOT_DIR: <string>
39 # The root directory to which all file paths
40 # referenced by the extension are relative to.
42 # HHVM_EXTENSION_#_ENABLED_STATE: <int {0, 1, 2, 3, 4}>
43 # The state of an extension's enabling. If this is 0, then the extension
44 # may be enabled once dependency calculation is performed. If this is 1,
45 # then the extension is enabled, and if it is 2, then it is disabled.
46 # If this is 3, then the extension has been forcefully enabled, and its
47 # dependencies should be checked. If this is 4, then the extension is a
48 # 'wanted' extension, and we should error if dependencies for it can't
49 # be resolved, unless the dependency that fails is an os* or var* dependency,
50 # in which case, we don't error, but just disable the extension.
52 # HHVM_EXTENSION_#_SOURCE_FILES: <list>
53 # The list of files to compile for the extension.
55 # HHVM_EXTENSION_#_HEADER_FILES: <list>
56 # The list of header files that make up this extension.
58 # HHVM_EXTENSION_#_SYSTEMLIB: <list>
59 # The list of php files that make up this extension's own systemlib.
61 # HHVM_EXTENSION_#_DEPENDENCIES: <list>
62 # The list of dependencies of this extension. For details on the specifics
63 # of values in this list, see the documentation of the DEPENDS parameter
64 # of HHVM_DEFINE_EXTENSION.
66 # HHVM_EXTENSION_#_DEPENDENCIES_OPTIONAL: <list>
67 # A list of ON/OFF values mapping to the values in HHVM_EXTENSION_#_DEPENDENCIES.
68 # If the value is ON, then the dependency is optional, and the build should
69 # not fail if the dependency can't be resolved.
71 include(CheckFunctionExists)
72 include(HPHPFunctions)
73 include(Options)
75 # function HHVM_DEFINE_EXTENSION:
76 # This is the function that each individual extension will call. It
77 # defines everything about the extension.
79 # Note that HRE_CURRENT_EXT_PATH should have been defined before calling this,
80 # and it should be set to the root directory to which all paths passed to this
81 # function are relative to.
83 # Parameters:
85 # NAME
86 # The name of the extension. This name will be used in the variable names,
87 # so spaces are not allowed.
89 # [REQUIRED]
90 # This extension is integral to the functioning of HHVM, and
91 # can not be disabled via `-DENABLE_EXTENSION_FOO=Off`.
92 # A FATAL_ERROR will be triggered if dependencies fail to resolve.
94 # [IMPLICIT]
95 # If the library dependencies for this extension fail to resolve,
96 # and it has not be explicitly enabled via `-DENABLE_EXTENSION_FOO=On`,
97 # then it will be implicitly disabled by the build system.
99 # [WANTED] (default)
100 # If the library dependencies for this extension fail to resolve,
101 # and it has not been explicitly disabled with `-DENABLE_EXTENSION_FOO=Off`
102 # a FATAL_ERROR will be triggered, unless the dependency that fails is
103 # an os* or var* dependency, in which case the extension will be implicitly
104 # disabled by the build system.
106 # Note that it does not make sense to specify more than one of the above
107 # three settings as the behavior they imply is mutually exclusive.
108 # Using more than one will result in undefined behavior.
110 # [PRETTY_NAME string]
111 # If passed, use this name when naming the extension in mesages. If this is
112 # not passed, default to NAME.
114 # [IS_ENABLED VARNAME]
115 # If the parameter passed is defined, and has a trueish value,
116 # then the extension will be enabled. This is only used to maintain
117 # backwards compatibility with existing options. All other
118 # extensions can be enabled or disabled with ENABLE_EXTENSION_*.
119 # The ENABLE_EXTENSION_* variables will also be defined for the source
120 # code so that fallbacks may be used where needed.
122 # [SOURCES ...]
123 # The source files of the extension
125 # [HEADERS ...]
126 # The header files of the extension
128 # [SYSTEMLIB ...]
129 # The PHP API of the extension.
131 # [DEPENDS ...]
132 # The dependencies of the extension. Extensions are prefixed
133 # with "ext_", and external libaries with "lib".
134 # "systemlib" is a special dependency that represents the
135 # systemlib header.
137 # A dependency may optionally be followed by "OPTIONAL", which
138 # means that the build won't fail if the dependency is not found.
140 # Dependencies prefixed with "os" represent the OS required to
141 # build the extension. The only valid value for this currently
142 # is osPosix, which represents everything with a valid posix
143 # API, which is most everything except for Windows.
145 # Dependencies prefixed with "var" represent a CMake variable
146 # which must evaluate to a trueish value for the extension to
147 # be enabled. If the value isn't defined, it is assumed to be
148 # false.
150 # If there is a space in an argument with a string in it, and
151 # the argument is a library, the exact version of the library
152 # required is expected to be the second part of the string.
153 # For example, "libFribidi 0.19.6" would require the Fribidi
154 # package to be exactly version 0.19.6.
156 # For libBoost, a single component is expected to be specified
157 # by appending a -componentName to the value, for example
158 # libBoost-variant would require the variant component of libBoost.
159 # This is only required if a library needs to be linked against.
160 # If a boost component is a headers-only library, libBoost is
161 # enough of a dependency.
163 # Note that libFolly is currently a dependency of everything
164 # for the sanity of the Windows port.
165 function(HHVM_DEFINE_EXTENSION extNameIn)
166   if (NOT DEFINED HHVM_EXTENSION_COUNT)
167     set(HHVM_EXTENSION_COUNT 0)
168   endif()
170   set(extensionName "")
171   set(extensionPrettyName "")
172   set(extensionRequired OFF)
173   # If WANTED is specified, then the extension must be explicitly disabled
174   # If IMPLICIT is specified, then the extension will be implicitly disabled
175   # when the dependencies are not found
176   # If neither is specified, we default to WANTED anyway
177   set(extensionEnabledState 4)
178   set(extensionSources)
179   set(extensionHeaders)
180   set(extensionLibrary)
181   set(extensionDependencies)
182   set(extensionDependenciesOptional)
184   # Make sure there are no spaces.
185   string(FIND ${extNameIn} " " extNameSpace)
186   if (NOT ${extNameSpace} EQUAL -1)
187     message(FATAL_ERROR "An extension name cannot have a space in it! Got name '${extNameIn}'.")
188   endif()
190   # Make sure another extension with the same hasn't already
191   # been defined.
192   set(i 0)
193   while (i LESS HHVM_EXTENSION_COUNT)
194     if (${HHVM_EXTENSION_${i}_NAME} STREQUAL ${extNameIn})
195       message(FATAL_ERROR "An extension with the name '${extNameIn}' has already been defined!")
196     endif()
197     math(EXPR i "${i} + 1")
198   endwhile()
199   set(extensionName ${extNameIn})
200   set(extensionPrettyName ${extensionName})
202   set(argumentState 0)
203   foreach (arg ${ARGN})
204     if ("x${arg}" STREQUAL "xPRETTY_NAME")
205       set(argumentState 1)
206     elseif ("x${arg}" STREQUAL "xIS_ENABLED")
207       set(argumentState 2)
208     elseif ("x${arg}" STREQUAL "xSOURCES")
209       set(argumentState 3)
210     elseif ("x${arg}" STREQUAL "xHEADERS")
211       set(argumentState 4)
212     elseif ("x${arg}" STREQUAL "xSYSTEMLIB")
213       set(argumentState 5)
214     elseif ("x${arg}" STREQUAL "xDEPENDS")
215       set(argumentState 7)
216     elseif ("x${arg}" STREQUAL "xREQUIRED")
217       if (NOT ${argumentState} EQUAL 0)
218         message(FATAL_ERROR "The REQUIRED modifier should only be placed immediately after the extension's name! (while processing the '${extensionPrettyName}' extension)")
219       endif()
220       set(extensionRequired ON)
221     elseif ("x${arg}" STREQUAL "xIMPLICIT")
222       if (NOT ${argumentState} EQUAL 0)
223         message(FATAL_ERROR "The IMPLICIT modifier should only be placed immediately after the extension's name! (while processing the '${extensionPrettyName}' extension)")
224       endif()
225       set(extensionEnabledState 0)
226     elseif ("x${arg}" STREQUAL "xWANTED")
227       if (NOT ${argumentState} EQUAL 0)
228         message(FATAL_ERROR "The WANTED modifier should only be placed immediately after the extension's name! (while processing the '${extensionPrettyName}' extension)")
229       endif()
230       set(extensionEnabledState 4)
231     elseif ("x${arg}" STREQUAL "xOPTIONAL")
232       if (${argumentState} EQUAL 7)
233         list(LENGTH extensionDependenciesOptional optDepLen)
234         math(EXPR optDepLen "${optDepLen} - 1")
235         list(REMOVE_AT extensionDependenciesOptional ${optDepLen})
236         list(APPEND extensionDependenciesOptional ON)
237       else()
238         message(FATAL_ERROR "The OPTIONAL modifier is only currently valid in the DEPENDS section of extension '${extensionPrettyName}'!")
239       endif()
240     elseif (${argumentState} EQUAL 0)
241       message(FATAL_ERROR "Unknown argument '${arg}' while processing extension '${extensionPrettyName}'!")
242     elseif (${argumentState} EQUAL 1)
243       # PRETTY_NAME
244       set(extensionPrettyName ${arg})
245       set(argumentState 0)
246     elseif (${argumentState} EQUAL 2)
247       # IS_ENABLED
248       if (DEFINED ${arg})
249         if (${${arg}})
250           set(extensionEnabledState 3)
251         else()
252           set(extensionEnabledState 2)
253         endif()
254       endif()
255       set(argumentState 0)
256     elseif (${argumentState} EQUAL 3)
257       # SOURCES
258       list(FIND extensionSources ${arg} listIDX)
259       if (NOT ${listIDX} EQUAL -1)
260         message(FATAL_ERROR "The file '${arg}' was already specified as a source of '${extensionPrettyName}'!")
261       endif()
262       list(APPEND extensionSources ${arg})
263     elseif (${argumentState} EQUAL 4)
264       # HEADERS
265       list(FIND extensionHeaders ${arg} listIDX)
266       if (NOT ${listIDX} EQUAL -1)
267         message(FATAL_ERROR "The file '${arg}' was already specified as a header of '${extensionPrettyName}'!")
268       endif()
269       list(APPEND extensionHeaders ${arg})
270     elseif (${argumentState} EQUAL 5)
271       # SYSTEMLIB
272       list(FIND extensionLibrary ${arg} listIDX)
273       if (NOT ${listIDX} EQUAL -1)
274         message(FATAL_ERROR "The file '${arg}' was already specified as part of the library of '${extensionPrettyName}'!")
275       endif()
276       list(APPEND extensionLibrary ${arg})
277     elseif (${argumentState} EQUAL 7)
278       # DEPENDS
279       list(FIND extensionDependencies ${arg} listIDX)
280       if (NOT ${listIDX} EQUAL -1)
281         message(FATAL_ERROR "'${arg}' was already specified as a dependency of '${extensionPrettyName}'!")
282       endif()
283       list(APPEND extensionDependencies ${arg})
284       list(APPEND extensionDependenciesOptional OFF)
285     else()
286       message(FATAL_ERROR "An error occurred while processing the arguments of the '${extensionPrettyName}' extension!")
287     endif()
288   endforeach()
290   # Check if the extension has been explicitly enabled or disabled.
291   string(TOUPPER ${extensionName} upperExtName)
292   if (DEFINED ENABLE_EXTENSION_${upperExtName})
293     if (${ENABLE_EXTENSION_${upperExtName}})
294       set(extensionEnabledState 3)
295     elseif (${extensionRequired})
296       message(WARNING "Attempt to explicitly disable the required extension '${extensionPrettyName}' by setting 'ENABLE_EXTENSION_${upperExtName}' was ignored.")
297     else()
298       set(extensionEnabledState 2)
299     endif()
300   endif()
302   # Increment the extension count.
303   set(extensionID ${HHVM_EXTENSION_COUNT})
304   math(EXPR newCount "${HHVM_EXTENSION_COUNT} + 1")
305   set(HHVM_EXTENSION_COUNT ${newCount} PARENT_SCOPE)
307   # And lastly, export the globals.
308   # We put these in the cache to make debugging easier.
309   # The only one that absolutely has to be in the cache is
310   # the ENABLED_STATE, due to it's modification from fairly
311   # arbitrary scope depths. HHVM_EXTENSION_COUNT must NEVER
312   # be in the cache, otherwise this will break.
313   set(HHVM_EXTENSION_${extensionID}_NAME ${extensionName} CACHE INTERNAL "" FORCE)
314   set(HHVM_EXTENSION_${extensionID}_PRETTY_NAME ${extensionPrettyName} CACHE INTERNAL "" FORCE)
315   set(HHVM_EXTENSION_${extensionID}_REQUIRED ${extensionRequired} CACHE INTERNAL "" FORCE)
316   set(HHVM_EXTENSION_${extensionID}_ROOT_DIR ${HRE_CURRENT_EXT_PATH} CACHE INTERNAL "" FORCE)
317   set(HHVM_EXTENSION_${extensionID}_ENABLED_STATE ${extensionEnabledState} CACHE INTERNAL "" FORCE)
318   set(HHVM_EXTENSION_${extensionID}_SOURCE_FILES ${extensionSources} CACHE INTERNAL "" FORCE)
319   set(HHVM_EXTENSION_${extensionID}_HEADER_FILES ${extensionHeaders} CACHE INTERNAL "" FORCE)
320   set(HHVM_EXTENSION_${extensionID}_SYSTEMLIB ${extensionLibrary} CACHE INTERNAL "" FORCE)
321   set(HHVM_EXTENSION_${extensionID}_DEPENDENCIES ${extensionDependencies} CACHE INTERNAL "" FORCE)
322   set(HHVM_EXTENSION_${extensionID}_DEPENDENCIES_OPTIONAL ${extensionDependenciesOptional} CACHE INTERNAL "" FORCE)
323 endfunction()
325 # Call after all of the calls to HHVM_DEFINE_EXTENSION are complete.
327 # This will also add the appropriate libraries, include directories, and
328 # defines for the enabled extensions' dependencies.
329 function(HHVM_EXTENSION_RESOLVE_DEPENDENCIES)
330   set(HHVM_EXTENSIONS_REQUIRED_LIBRARIES "" CACHE INTERNAL "" FORCE)
331   set(HHVM_EXTENSIONS_REQUIRED_INCLUDE_DIRS "" CACHE INTERNAL "" FORCE)
332   set(HHVM_EXTENSIONS_REQUIRED_DEFINES "" CACHE INTERNAL "" FORCE)
333   set(i 0)
334   while (i LESS HHVM_EXTENSION_COUNT)
335     HHVM_EXTENSION_INTERNAL_RESOLVE_DEPENDENCIES_OF_EXTENSION(wasResolved ${i} " ")
336     string(TOUPPER ${HHVM_EXTENSION_${i}_NAME} upperExtName)
337     if (${wasResolved} EQUAL 1)
338       message(STATUS "Building the ${HHVM_EXTENSION_${i}_PRETTY_NAME} extension.")
340       # Now we need to make sure the dependencies are included and linked in
341       # correctly.
342       set(i2 0)
343       list(LENGTH HHVM_EXTENSION_${i}_DEPENDENCIES depCount)
344       while (i2 LESS depCount)
345         list(GET HHVM_EXTENSION_${i}_DEPENDENCIES ${i2} currentDependency)
346         string(FIND ${currentDependency} "lib" libIdx)
347         if (${libIdx} EQUAL 0)
348           HHVM_EXTENSION_INTERNAL_HANDLE_LIBRARY_DEPENDENCY(${i} ${currentDependency} ON)
349         endif()
350         math(EXPR i2 "${i2} + 1")
351       endwhile()
353       if (HHVM_EXTENSION_${i}_REQUIRED)
354         set(ENABLE_EXTENSION_${upperExtName} ON CACHE INTERNAL "Enable the ${HHVM_EXTENSION_${i}_PRETTY_NAME} extension.")
355       else()
356         set(ENABLE_EXTENSION_${upperExtName} ON CACHE BOOL "Enable the ${HHVM_EXTENSION_${i}_PRETTY_NAME} extension.")
357       endif()
358     else()
359       if (HHVM_EXTENSION_${i}_REQUIRED)
360         message(FATAL_ERROR "Failed to resolve a dependency of the ${HHVM_EXTENSION_${i}_PRETTY_NAME} extension, which is a required extension!")
361       endif()
362       message("Not building the ${HHVM_EXTENSION_${i}_PRETTY_NAME} extension.")
363       set(ENABLE_EXTENSION_${upperExtName} OFF CACHE BOOL "Enable the ${HHVM_EXTENSION_${i}_PRETTY_NAME} extension.")
364     endif()
365     math(EXPR i "${i} + 1")
366   endwhile()
367 endfunction()
369 # This will append the files of the enabled extensions to the following variables:
370 # C_SOURCES: C Source Files
371 # CXX_SOURCES: C++ Source Files
372 # HEADER_SOURCES: C/C++ Header Files
373 # ASM_SOURCES: asm source files appropriate for the current compiler.
374 # PHP_SOURCES: PHP files representing the various extensions' systemlib.
375 function (HHVM_EXTENSION_BUILD_SOURCE_LISTS)
376   set(i 0)
377   while (i LESS HHVM_EXTENSION_COUNT)
378     if (${HHVM_EXTENSION_${i}_ENABLED_STATE} EQUAL 1)
379       HHVM_EXTENSION_INTERNAL_SORT_OUT_SOURCES(${HHVM_EXTENSION_${i}_ROOT_DIR}
380         ${HHVM_EXTENSION_${i}_SOURCE_FILES}
381         ${HHVM_EXTENSION_${i}_HEADER_FILES}
382         ${HHVM_EXTENSION_${i}_SYSTEMLIB}
383       )
384     endif()
385     math(EXPR i "${i} + 1")
386   endwhile()
388   # Propagate the extra files to the parent scope.
389   set(C_SOURCES ${C_SOURCES} PARENT_SCOPE)
390   set(CXX_SOURCES ${CXX_SOURCES} PARENT_SCOPE)
391   set(HEADER_SOURCES ${HEADER_SOURCES} PARENT_SCOPE)
392   set(ASM_SOURCES ${ASM_SOURCES} PARENT_SCOPE)
393   set(PHP_SOURCES ${PHP_SOURCES} PARENT_SCOPE)
394 endfunction()
396 # Sort out all the files into their appropriate variable, as well as transform the paths
397 # to their fully-resolved forms.
398 function (HHVM_EXTENSION_INTERNAL_SORT_OUT_SOURCES rootDir)
399   foreach (fileName ${ARGN})
400     string(LENGTH ${fileName} fileNameLength)
401     string(FIND ${fileName} "." dotPos REVERSE)
402     if (${dotPos} EQUAL -1)
403       message(FATAL_ERROR "No extension on file '${fileName}'!")
404     endif()
405     math(EXPR endPos "${fileNameLength} - ${dotPos}")
406     string(SUBSTRING ${fileName} ${dotPos} ${endPos} fileExtension)
407     string(TOLOWER ${fileExtension} fileExtension)
408     if (${fileExtension} STREQUAL ".c")
409       list(APPEND C_SOURCES "${rootDir}/${fileName}")
410     elseif (${fileExtension} STREQUAL ".cpp" OR ${fileExtension} STREQUAL ".cxx" OR ${fileExtension} STREQUAL ".cc")
411       list(APPEND CXX_SOURCES "${rootDir}/${fileName}")
412     elseif (${fileExtension} STREQUAL ".h" OR ${fileExtension} STREQUAL ".hpp")
413       list(APPEND HEADER_SOURCES "${rootDir}/${fileName}")
414     elseif (${fileExtension} STREQUAL ".s")
415       # AT&T syntax, MSVC doesn't like.
416       if (NOT MSVC)
417         list(APPEND ASM_SOURCES "${rootDir}/${fileName}")
418       endif()
419     elseif (${fileExtension} STREQUAL ".asm")
420       # MASM syntax. MSVC only.
421       if (MSVC)
422         list(APPEND ASM_SOURCES "${rootDir}/${fileName}")
423       endif()
424     elseif (${fileExtension} STREQUAL ".php")
425       list(APPEND PHP_SOURCES "${rootDir}/${fileName}")
426     else()
427       message(FATAL_ERROR "Unknown file extension '${fileExtension}'!")
428     endif()
429   endforeach()
430   set(C_SOURCES ${C_SOURCES} PARENT_SCOPE)
431   set(CXX_SOURCES ${CXX_SOURCES} PARENT_SCOPE)
432   set(HEADER_SOURCES ${HEADER_SOURCES} PARENT_SCOPE)
433   set(ASM_SOURCES ${ASM_SOURCES} PARENT_SCOPE)
434   set(PHP_SOURCES ${PHP_SOURCES} PARENT_SCOPE)
435 endfunction()
437 # Configure the specified target so that it can compile when
438 # linked against the enabled extensions.
439 function(HHVM_CONFIGURE_TARGET_FOR_EXTENSION_DEPENDENCIES targetName)
440   target_link_libraries(${targetName} ${HHVM_EXTENSIONS_REQUIRED_LIBRARIES})
441   target_include_directories(${targetName} PUBLIC ${HHVM_EXTENSIONS_REQUIRED_INCLUDE_DIRS})
442   target_compile_definitions(${targetName} PUBLIC ${HHVM_EXTENSIONS_REQUIRED_DEFINES})
443 endfunction()
446 # Resolve the dependencies of the specified extension, and update it's enabled state.
447 function(HHVM_EXTENSION_INTERNAL_RESOLVE_DEPENDENCIES_OF_EXTENSION resolvedDestVar extensionID)
448   # If already resolved, return that state.
449   if (NOT HHVM_EXTENSION_${extensionID}_ENABLED_STATE EQUAL 0 AND
450       NOT HHVM_EXTENSION_${extensionID}_ENABLED_STATE EQUAL 3 AND
451       NOT HHVM_EXTENSION_${extensionID}_ENABLED_STATE EQUAL 4)
452     set(${resolvedDestVar} ${HHVM_EXTENSION_${extensionID}_ENABLED_STATE} PARENT_SCOPE)
453     return()
454   endif()
456   # If already in resolution stack, it's a circular dependency,
457   # assume for now that it's enabled.
458   list(FIND HHVM_EXTENSION_RESOLUTION_STACK ${HHVM_EXTENSION_${extensionID}_NAME} resIDX)
459   if (NOT ${resIDX} EQUAL -1)
460     set(${resolvedDestVar} 1 PARENT_SCOPE)
461     return()
462   endif()
464   # Go through the dependencies, checking each one recursively in turn.
465   list(LENGTH HHVM_EXTENSION_${extensionID}_DEPENDENCIES depCount)
466   set(i 0)
467   while (i LESS depCount)
468     list(GET HHVM_EXTENSION_${extensionID}_DEPENDENCIES ${i} currentDependency)
470     string(FIND ${currentDependency} "lib" listIDX)
471     if (${listIDX} EQUAL 0)
472       # Library Dependency
473       HHVM_EXTENSION_INTERNAL_HANDLE_LIBRARY_DEPENDENCY(${extensionID} ${currentDependency} OFF)
474       if (HHVM_EXTENSION_${extensionID}_ENABLED_STATE EQUAL 2)
475         break()
476       endif()
477     else()
478       string(FIND ${currentDependency} "var" listIDX)
479       if (${listIDX} EQUAL 0)
480         # CMake Variable Dependency
481         string(LENGTH ${currentDependency} depLength)
482         math(EXPR depLength "${depLength} - 3")
483         string(SUBSTRING ${currentDependency} 3 ${depLength} varName)
484         if (DEFINED ${varName})
485           if (NOT ${${varName}})
486             HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${currentDependency} ON)
487             break()
488           endif()
489         else()
490           HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${currentDependency} ON)
491           break()
492         endif()
493       else()
494         string(FIND ${currentDependency} "os" listIDX)
495         if (${listIDX} EQUAL 0)
496           # OS Dependency
497           if (${currentDependency} STREQUAL "osPosix")
498             if (MSVC)
499               HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${currentDependency} ON)
500               break()
501             endif()
502           else()
503             message(FATAL_ERROR "The only OS restriction that is currently valid is 'osPosix', got '${currentDependency}'!")
504           endif()
505         elseif (${currentDependency} STREQUAL "systemlib")
506           # TODO: Mark this somehow?
507         else()
508           message(FATAL_ERROR "Unknown dependency '${currentDependency}' for extension '${HHVM_EXTENSION_${extensionID}_PRETTY_NAME}'!")
509         endif()
510       endif()
511     endif()
513     math(EXPR i "${i} + 1")
514   endwhile()
516   if (HHVM_EXTENSION_${extensionID}_ENABLED_STATE EQUAL 0 OR
517       HHVM_EXTENSION_${extensionID}_ENABLED_STATE EQUAL 3 OR
518       HHVM_EXTENSION_${extensionID}_ENABLED_STATE EQUAL 4)
519     set(HHVM_EXTENSION_${extensionID}_ENABLED_STATE 1 CACHE INTERNAL "" FORCE)
520   endif()
521   set(${resolvedDestVar} ${HHVM_EXTENSION_${extensionID}_ENABLED_STATE} PARENT_SCOPE)
522 endfunction()
524 # Set that an extension was disabled because of the specified dependency not being
525 # possible to resolve.
526 # This optionally takes a third BOOL parameter that should be set to ON only if the
527 # dependency that failed to resolve is an os* or var* dependency.
528 function(HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY extensionID failedDependency)
529   list(FIND HHVM_EXTENSION_${extensionID}_DEPENDENCIES ${failedDependency} depIdx)
530   if (depIdx EQUAL -1)
531     message(FATAL_ERROR "An issue occured while processing the '${failedDependency}' dependency of the ${HHVM_EXTENSION_${extensionID}_PRETTY_NAME} extension!")
532   endif()
533   list(GET HHVM_EXTENSION_${extensionID}_DEPENDENCIES_OPTIONAL ${depIdx} isOptional)
535   if (NOT ${isOptional})
536     if (${HHVM_EXTENSION_${extensionID}_ENABLED_STATE} EQUAL 4 AND (NOT ${ARGC} EQUAL 3 OR NOT "${ARGV2}" STREQUAL "ON"))
537       message(FATAL_ERROR "The ${HHVM_EXTENSION_${extensionID}_PRETTY_NAME} extension is an extension you probably want, but resolving the dependency '${failedDependency}' failed!")
538     elseif (${HHVM_EXTENSION_${extensionID}_ENABLED_STATE} EQUAL 3)
539       message(FATAL_ERROR "The ${HHVM_EXTENSION_${extensionID}_PRETTY_NAME} extension was forcefully enabled, but resolving the dependency '${failedDependency}' failed!")
540     elseif (${HHVM_EXTENSION_${extensionID}_ENABLED_STATE} EQUAL 1)
541       # Currently only triggers for issues with find_package when applying the library dependencies.
542       message(FATAL_ERROR "An error occurred while applying the '${failedDependency}' dependency of the ${HHVM_EXTENSION_${extensionID}_PRETTY_NAME} extension!")
543     endif()
544     message(STATUS "The ${HHVM_EXTENSION_${extensionID}_PRETTY_NAME} extension was disabled because resolving the dependency '${failedDependency}' failed.")
545     set(HHVM_EXTENSION_${extensionID}_ENABLED_STATE 2 CACHE INTERNAL "" FORCE)
546   endif()
547 endfunction()
549 # Add a set of libraries to link against.
550 function(HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES)
551   set(reqLibs ${HHVM_EXTENSIONS_REQUIRED_LIBRARIES})
552   foreach (lib ${ARGN})
553     list(APPEND reqLibs ${lib})
554   endforeach()
555   set(HHVM_EXTENSIONS_REQUIRED_LIBRARIES ${reqLibs} CACHE INTERNAL "" FORCE)
556 endfunction()
558 # Add a set of include directories to use.
559 function(HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS)
560   set(incDirs ${HHVM_EXTENSIONS_REQUIRED_INCLUDE_DIRS})
561   foreach (inc ${ARGN})
562     list(APPEND incDirs ${inc})
563   endforeach()
564   set(HHVM_EXTENSIONS_REQUIRED_INCLUDE_DIRS ${incDirs} CACHE INTERNAL "" FORCE)
565 endfunction()
567 # Add a set of defines to use when compiling.
568 function(HHVM_EXTENSION_INTERNAL_ADD_DEFINES)
569   set(defs ${HHVM_EXTENSIONS_REQUIRED_DEFINES})
570   foreach (def ${ARGN})
571     list(APPEND defs ${def})
572   endforeach()
573   set(HHVM_EXTENSIONS_REQUIRED_DEFINES ${defs} CACHE INTERNAL "" FORCE)
574 endfunction()
576 # This handles all the library dependencies, and determines if the libraries are present.
577 function (HHVM_EXTENSION_INTERNAL_HANDLE_LIBRARY_DEPENDENCY extensionID dependencyName addPaths)
578   string(FIND ${dependencyName} "lib" libIdx)
579   if (NOT libIdx EQUAL 0)
580     message(FATAL_ERROR "Non-library dependency '${dependencyName}' passed to HHVM_EXTENSION_INTERNAL_HANDLE_LIBRARY_DEPENDENCY!")
581   endif()
583   set(requiredVersion)
584   string(LENGTH ${dependencyName} depLength)
585   math(EXPR depLength "${depLength} - 3")
586   string(SUBSTRING ${dependencyName} 3 ${depLength} originalLibraryName)
587   string(FIND ${originalLibraryName} " " spaceIDX)
588   if (NOT ${spaceIDX} EQUAL -1)
589     math(EXPR spaceIDX "${spaceIDX} + 1")
590     string(LENGTH ${originalLibraryName} libNameLength)
591     math(EXPR libNameLength "${libNameLength} - ${spaceIDX}")
592     string(SUBSTRING ${originalLibraryName} ${spaceIDX} ${libNameLength} requiredVersion)
593     math(EXPR spaceIDX "${spaceIDX} - 1")
594     string(SUBSTRING ${originalLibraryName} 0 ${spaceIDX} originalLibraryName)
595   endif()
596   string(TOLOWER ${originalLibraryName} libraryName)
598   # This first check is for libraries that are used by default
599   # Keep these in alphabetical order.
600   if (
601     ${libraryName} STREQUAL "boost" OR
602     ${libraryName} STREQUAL "editline" OR
603     ${libraryName} STREQUAL "fastlz" OR
604     ${libraryName} STREQUAL "folly" OR
605     ${libraryName} STREQUAL "lz4" OR
606     ${libraryName} STREQUAL "mbfl" OR
607     ${libraryName} STREQUAL "mcrouter" OR
608     ${libraryName} STREQUAL "oniguruma" OR
609     ${libraryName} STREQUAL "openssl" OR
610     ${libraryName} STREQUAL "pcre" OR
611     ${libraryName} STREQUAL "readline" OR
612     ${libraryName} STREQUAL "sqlite" OR
613     ${libraryName} STREQUAL "zip" OR
614     ${libraryName} STREQUAL "zlib"
615   )
616     # Nothing to do, they are included by default.
617   elseif (${libraryName} STREQUAL "bzip2")
618     find_package(BZip2 ${requiredVersion})
619     find_package(EXPAT ${requiredVersion})
620     if (NOT BZIP2_INCLUDE_DIR OR NOT BZIP2_LIBRARIES)
621       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
622       return()
623     endif()
625     if (${addPaths})
626       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${BZIP2_INCLUDE_DIR})
627       HHVM_EXTENSION_INTERNAL_ADD_DEFINES(${BZIP2_DEFINITIONS})
628       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${BZIP2_LIBRARIES})
629       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBBZIP2")
630     endif()
631   elseif (${libraryName} STREQUAL "cclient")
632     find_package(CClient ${requiredVersion})
633     if (NOT CCLIENT_INCLUDE_PATH OR NOT CCLIENT_LIBRARY)
634       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
635       return()
636     endif()
638     CONTAINS_STRING("${CCLIENT_INCLUDE_PATH}/utf8.h" U8T_DECOMPOSE RECENT_CCLIENT)
639     if (NOT RECENT_CCLIENT)
640       unset(RECENT_CCLIENT CACHE)
641       if (${addPaths})
642         message(FATAL_ERROR "Your version of c-client is too old, you need 2007")
643       else()
644         message(STATUS "Your version of c-client is too old, you need 2007")
645         HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
646         return()
647       endif()
648     endif()
650     if (${addPaths})
651       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${CCLIENT_INCLUDE_PATH})
652       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${CCLIENT_LIBRARY})
653       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBCCLIENT")
655       if (EXISTS "${CCLIENT_INCLUDE_PATH}/linkage.c")
656         CONTAINS_STRING("${CCLIENT_INCLUDE_PATH}/linkage.c" auth_gss CCLIENT_HAS_GSS)
657       elseif (EXISTS "${CCLIENT_INCLUDE_PATH}/linkage.h")
658         CONTAINS_STRING("${CCLIENT_INCLUDE_PATH}/linkage.h" auth_gss CCLIENT_HAS_GSS)
659       endif()
660       if (NOT CCLIENT_HAS_GSS)
661         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DSKIP_IMAP_GSS=1")
662       endif()
664       if (EXISTS "${CCLIENT_INCLUDE_PATH}/linkage.c")
665         CONTAINS_STRING("${CCLIENT_INCLUDE_PATH}/linkage.c" ssl_onceonlyinit CCLIENT_HAS_SSL)
666       elseif (EXISTS "${CCLIENT_INCLUDE_PATH}/linkage.h")
667         CONTAINS_STRING("${CCLIENT_INCLUDE_PATH}/linkage.h" ssl_onceonlyinit CCLIENT_HAS_SSL)
668       endif()
669       if (NOT CCLIENT_HAS_SSL)
670         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DSKIP_IMAP_SSL=1")
671       endif()
672     endif()
673   elseif (${libraryName} STREQUAL "curl")
674     find_package(CURL ${requiredVersion})
675     if (NOT CURL_INCLUDE_DIR OR NOT CURL_LIBRARIES)
676       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
677       return()
678     endif()
680     if (${addPaths})
681       set(CMAKE_REQUIRED_LIBRARIES "${CURL_LIBRARIES}")
682       set(CMAKE_REQUIRED_INCLUDES "${CURL_INCLUDE_DIR}")
683       CHECK_FUNCTION_EXISTS("curl_multi_select" HAVE_CURL_MULTI_SELECT)
684       CHECK_FUNCTION_EXISTS("curl_multi_wait" HAVE_CURL_MULTI_WAIT)
685       if (HAVE_CURL_MULTI_SELECT)
686         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_CURL_MULTI_SELECT")
687       endif()
688       if (HAVE_CURL_MULTI_WAIT)
689         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_CURL_MULTI_WAIT")
690       endif()
691       set(CMAKE_REQUIRED_LIBRARIES)
692       set(CMAKE_REQUIRED_INCLUDES)
694       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${CURL_INCLUDE_DIR})
695       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${CURL_LIBRARIES})
696       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBCURL")
697     endif()
698   elseif (${libraryName} STREQUAL "expat")
699     find_package(EXPAT ${requiredVersion})
700     if (NOT EXPAT_INCLUDE_DIRS OR NOT EXPAT_LIBRARY)
701       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
702       return()
703     endif()
705     if (${addPaths})
706       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${EXPAT_INCLUDE_DIRS})
707       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${EXPAT_LIBRARY})
708       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBEXPAT")
709       if (EXPAT_STATIC)
710         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DXML_STATIC")
711       endif()
712     endif()
713   elseif (${libraryName} STREQUAL "freetype")
714     find_package(Freetype ${requiredVersion})
715     if (NOT FREETYPE_INCLUDE_DIRS OR NOT FREETYPE_LIBRARIES)
716       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
717       return()
718     endif()
720     if (${addPaths})
721       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${FREETYPE_INCLUDE_DIRS})
722       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${FREETYPE_LIBRARIES})
723       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBFREETYPE")
724       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_GD_FREETYPE")
725       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DENABLE_GD_TTF")
726     endif()
727   elseif (${libraryName} STREQUAL "fribidi")
728     find_package(fribidi ${requiredVersion})
729     if (NOT FRIBIDI_INCLUDE_DIR OR NOT FRIBIDI_LIBRARY)
730       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
731       return()
732     endif()
734     if (${addPaths})
735       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${FRIBIDI_INCLUDE_DIR})
736       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${FRIBIDI_LIBRARY})
737       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBFRIBIDI")
738     endif()
739   elseif (${libraryName} STREQUAL "glib")
740     find_package(GLIB ${requiredVersion})
741     if (NOT GLIB_INCLUDE_DIR OR NOT GLIB_CONFIG_INCLUDE_DIR)
742       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
743       return()
744     endif()
746     if (${addPaths})
747       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${GLIB_INCLUDE_DIR} ${GLIB_CONFIG_INCLUDE_DIR})
748       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBGLIB")
749     endif()
750   elseif (${libraryName} STREQUAL "gmp")
751     find_package(LibGmp ${requiredVersion})
752     if (NOT GMP_INCLUDE_DIR OR NOT GMP_LIBRARY)
753       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
754       return()
755     endif()
757     if (${addPaths})
758       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${GMP_INCLUDE_DIR})
759       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${GMP_LIBRARY})
760       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBGMP")
761     endif()
762   elseif (${libraryName} STREQUAL "iconv")
763     find_package(Libiconv ${requiredVersion})
764     if (NOT LIBICONV_INCLUDE_DIR)
765       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
766       return()
767     endif()
769     if (${addPaths})
770       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBICONV_INCLUDE_DIR})
771       if (LIBICONV_LIBRARY)
772         HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBICONV_LIBRARY})
773       endif()
774       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_ICONV")
775       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBICONV")
776       if (LIBICONV_CONST)
777         message(STATUS "Using const for input to iconv() call")
778         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DICONV_CONST=const")
779       endif()
780     endif()
781   elseif (${libraryName} STREQUAL "icu")
782     find_package(ICU ${requiredVersion})
783     if (NOT ICU_FOUND OR NOT ICU_DATA_LIBRARIES OR NOT ICU_I18N_LIBRARIES OR NOT ICU_LIBRARIES)
784       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
785       return()
786     endif()
788     if (ICU_VERSION VERSION_LESS "4.2")
789       unset(ICU_FOUND CACHE)
790       unset(ICU_INCLUDE_DIRS CACHE)
791       unset(ICU_LIBRARIES CACHE)
792       if (${addPaths})
793         message(FATAL_ERROR "ICU is too old, found ${ICU_VERSION} and we need 4.2")
794       else()
795         message(STATUS "ICU is too old, found ${ICU_VERSION} and we need 4.2")
796         HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
797         return()
798       endif()
799     endif ()
801     if (${addPaths})
802       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${ICU_INCLUDE_DIRS})
803       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${ICU_DATA_LIBRARIES} ${ICU_I18N_LIBRARIES} ${ICU_LIBRARIES})
804       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBICU")
805     endif()
806   elseif (${libraryName} STREQUAL "intl")
807     find_package(LibIntl ${requiredVersion})
808     if (NOT LIBINTL_INCLUDE_DIRS)
809       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
810       return()
811     endif()
813     if (${addPaths})
814       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBINTL_INCLUDE_DIRS})
815       if (LIBINTL_LIBRARIES)
816         HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBINTL_LIBRARIES})
817       endif()
818       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBINTL")
819     endif()
820   elseif (${libraryName} STREQUAL "jpeg")
821     find_package(LibJpeg ${requiredVersion})
822     if (NOT LIBJPEG_INCLUDE_DIRS OR NOT LIBJPEG_LIBRARIES)
823       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
824       return()
825     endif()
827     if (${addPaths})
828       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBJPEG_INCLUDE_DIRS})
829       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBJPEG_LIBRARIES})
830       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBJPEG")
831       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_GD_JPG")
832     endif()
833   elseif (${libraryName} STREQUAL "jsonc")
834     find_package(Libjsonc ${requiredVersion})
835     if (NOT LIBJSONC_INCLUDE_DIR OR NOT LIBJSONC_LIBRARY)
836       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
837       return()
838     endif()
840     if (${addPaths})
841       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBJSONC_INCLUDE_DIR})
842       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBJSONC_LIBRARY})
843       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBJSONC")
844     endif()
845   elseif (${libraryName} STREQUAL "ldap")
846     find_package(Ldap ${requiredVersion})
847     if (NOT LDAP_INCLUDE_DIR OR NOT LDAP_LIBRARIES)
848       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
849       return()
850     endif()
852     if (${addPaths})
853       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LDAP_INCLUDE_DIR})
854       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LDAP_LIBRARIES})
855       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBLDAP")
856     endif()
857   elseif (${libraryName} STREQUAL "magickwand")
858     find_package(LibMagickWand ${requiredVersion})
859     if (NOT LIBMAGICKWAND_INCLUDE_DIRS OR NOT LIBMAGICKWAND_LIBRARIES OR NOT LIBMAGICKCORE_LIBRARIES)
860       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
861       return()
862     endif()
864     if (${addPaths})
865       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBMAGICKWAND_INCLUDE_DIRS})
866       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBMAGICKWAND_LIBRARIES} ${LIBMAGICKCORE_LIBRARIES})
867       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBMAGICKWAND")
868     endif()
869   elseif (${libraryName} STREQUAL "mcrypt")
870     find_package(Mcrypt ${requiredVersion})
871     if (NOT Mcrypt_INCLUDE_DIR OR NOT Mcrypt_LIB)
872       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
873       return()
874     endif()
876     if (${addPaths})
877       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${Mcrypt_INCLUDE_DIR})
878       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${Mcrypt_LIB})
879       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBMCRYPT")
880     endif()
881   elseif (${libraryName} STREQUAL "memcached")
882     find_package(Libmemcached ${requiredVersion})
883     if (NOT LIBMEMCACHED_INCLUDE_DIR OR NOT LIBMEMCACHED_LIBRARY)
884       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
885       return()
886     endif()
888     if (LIBMEMCACHED_VERSION VERSION_LESS "0.39")
889       unset(LIBMEMCACHED_INCLUDE_DIR CACHE)
890       unset(LIBMEMCACHED_LIBRARY CACHE)
891       unset(LIBMEMCACHED_VERSION CACHE)
892       if (${addPaths})
893         message(FATAL_ERROR "libmemcached is too old, found ${LIBMEMCACHED_VERSION} and we need 0.39")
894       else()
895         message(STATUS "libmemcached is too old, found ${LIBMEMCACHED_VERSION} and we need 0.39")
896         HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
897         return()
898       endif()
899     endif()
901     if (${addPaths})
902       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBMEMCACHED_INCLUDE_DIR})
903       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBMEMCACHED_LIBRARY})
904       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBMEMCACHED")
905     endif()
906   elseif (${libraryName} STREQUAL "mysql")
907     HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(fbmysqlclient)
908     MYSQL_SOCKET_SEARCH()
909     HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DPHP_MYSQL_UNIX_SOCK_ADDR=\"${MYSQL_UNIX_SOCK_ADDR}\"")
910   elseif (${libraryName} STREQUAL "pgsql")
911     FIND_PATH(PGSQL_INCLUDE_DIR NAMES libpq-fe.h
912       PATHS
913         /usr/include
914         /usr/include/postgresql
915         /usr/include/pgsql
916         /usr/local/include
917         /usr/local/include/postgresql
918         /usr/local/include/pgsql
919       )
920     FIND_LIBRARY(PGSQL_LIBRARY NAMES pq
921       PATHS
922         /lib
923         /usr/lib
924         /usr/local/lib
925     )
926     IF (NOT PGSQL_INCLUDE_DIR OR NOT PGSQL_LIBRARY)
927       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
928       return()
929     endif()
931     if(${addPaths})
932       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${PGSQL_INCLUDE_DIR})
933       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${PGSQL_LIBRARY})
934     endif()
935   elseif (${libraryName} STREQUAL "png")
936     find_package(LibPng ${requiredVersion})
937     if (NOT LIBPNG_INCLUDE_DIRS OR NOT LIBPNG_LIBRARIES)
938       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
939       return()
940     endif()
942     if (${addPaths})
943       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBPNG_INCLUDE_DIRS})
944       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBPNG_LIBRARIES})
945       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBPNG")
946       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_GD_PNG")
947       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DPNG_SKIP_SETJMP_CHECK")
948     endif()
949   elseif (${libraryName} STREQUAL "snappy")
950     find_package(Snappy ${requiredVersion})
951     if (NOT SNAPPY_INCLUDE_DIRS OR NOT SNAPPY_LIBRARIES)
952       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
953       return()
954     endif()
956     if (${addPaths})
957       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${SNAPPY_INCLUDE_DIRS})
958       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${SNAPPY_LIBRARIES})
959     endif()
960   elseif (${libraryName} STREQUAL "squangle")
961     HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(squangle)
962   elseif (${libraryName} STREQUAL "vpx")
963     find_package(LibVpx ${requiredVersion})
964     if (NOT LIBVPX_INCLUDE_DIRS OR NOT LIBVPX_LIBRARIES)
965       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
966       return()
967     endif()
969     if (${addPaths})
970       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBVPX_INCLUDE_DIRS})
971       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBVPX_LIBRARIES})
972       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBVPX")
973     endif()
974   elseif (${libraryName} STREQUAL "xml2")
975     find_package(LibXml2 ${requiredVersion})
976     if (NOT LIBXML2_INCLUDE_DIR OR NOT LIBXML2_LIBRARIES)
977       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
978       return()
979     endif()
981     if (${addPaths})
982       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBXML2_INCLUDE_DIR})
983       HHVM_EXTENSION_INTERNAL_ADD_DEFINES(${LIBXML2_DEFINITIONS})
984       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBXML2_LIBRARIES})
985       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBXML2")
986     endif()
987   elseif (${libraryName} STREQUAL "xslt")
988     find_package(LibXslt ${requiredVersion})
989     if (NOT LIBXSLT_INCLUDE_DIR OR NOT LIBXSLT_LIBRARIES)
990       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
991       return()
992     endif()
994     if (${addPaths})
995       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${LIBXSLT_INCLUDE_DIR})
996       HHVM_EXTENSION_INTERNAL_ADD_DEFINES(${LIBXSLT_DEFINITIONS})
997       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES})
998       HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DHAVE_LIBXSLT")
999       if (LIBXSLT_STATIC)
1000         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DLIBXSLT_STATIC=1")
1001         HHVM_EXTENSION_INTERNAL_ADD_DEFINES("-DLIBEXSLT_STATIC=1")
1002       endif()
1003     endif()
1004   elseif (${libraryName} STREQUAL "watchmanclient")
1005     find_package(libWatchmanClient ${requiredVersion})
1006     if (NOT WATCHMANCLIENT_INCLUDE_DIRS OR NOT WATCHMANCLIENT_LIBRARIES)
1007       HHVM_EXTENSION_INTERNAL_SET_FAILED_DEPENDENCY(${extensionID} ${dependencyName})
1008       return()
1009     endif()
1011     if (${addPaths})
1012       HHVM_EXTENSION_INTERNAL_ADD_INCLUDE_DIRS(${WATCHMANCLIENT_INCLUDE_DIRS})
1013       HHVM_EXTENSION_INTERNAL_ADD_LINK_LIBRARIES(${WATCHMANCLIENT_LIBRARIES})
1014     endif()
1015   else()
1016     message(FATAL_ERROR "Unknown library '${originalLibraryName}' as a dependency of the '${HHVM_EXTENSION_${extensionID}_PRETTY_NAME}' extension!")
1017   endif()
1018 endfunction()