1 # Functions for use when building extensions dynamically
3 # These functions also exist in CMake/EXTFunctions.cmake
4 # Their signatures should be kept consistent, though their behavior
5 # will differ slightly.
7 function(HHVM_LINK_LIBRARIES EXTNAME)
8 target_link_libraries(${EXTNAME} ${ARGN})
11 function(HHVM_ADD_INCLUDES EXTNAME)
12 include_directories(${ARGN})
16 function(HHVM_EXTENSION EXTNAME)
17 set(EXTENSION_NAME ${EXTNAME} CACHE INTERNAL "")
18 add_library(${EXTNAME} SHARED ${ARGN})
19 set_target_properties(${EXTNAME} PROPERTIES PREFIX "")
20 set_target_properties(${EXTNAME} PROPERTIES SUFFIX ".so")
22 get_target_property(LOC ${EXTNAME} LOCATION)
23 get_target_property(TY ${EXTNAME} TYPE)
24 # Don't install via target, because it triggers a re-link that doesn't
25 # run the POST_BUILD custom command that embeds the systemlib on Linux.
26 install(CODE "FILE(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/hhvm/extensions/${HHVM_VERSION_BRANCH}\" TYPE ${TY} FILES \"${LOC}\")")
29 # Add an extension that uses the Zend compatibility layer.
30 function(HHVM_COMPAT_EXTENSION EXTNAME)
31 if(NOT ENABLE_ZEND_COMPAT)
32 message(FATAL_ERROR "HHVM was not configured with ENABLE_ZEND_COMPAT, "
33 "and so cannot be used to compile Zend-compatible extensions")
35 HHVM_EXTENSION(${EXTNAME} ${ARGN})
36 # Compile all source files as C++
37 set_source_files_properties(${ARGN} PROPERTIES LANGUAGE "CXX")
38 # Define COMPILE_DL_<EXTNAME> so that ZEND_GET_MODULE() will be invoked
39 string(TOUPPER ${EXTNAME} EXTNAME_UPPER)
40 add_definitions("-DCOMPILE_DL_${EXTNAME_UPPER}")
41 # Add extra include directories
42 set(EZC_DIR "${CMAKE_INSTALL_PREFIX}/include/hphp/runtime/ext_zend_compat")
43 include_directories("${EZC_DIR}/php-src")
44 include_directories("${EZC_DIR}/php-src/main")
45 include_directories("${EZC_DIR}/php-src/Zend")
46 include_directories("${EZC_DIR}/php-src/TSRM")
49 function(embed_systemlibs TARGET DEST)
51 target_link_libraries(${TARGET} ${${TARGET}_SLIBS})
53 message(FATAL_ERROR "Shared extensions are not supported on Windows")
55 add_custom_command(TARGET ${TARGET} POST_BUILD
57 ARGS ${${TARGET}_SLIBS} ${DEST}
58 COMMENT "Embedding php in ${TARGET}")
60 endfunction(embed_systemlibs)
62 function(HHVM_SYSTEMLIB EXTNAME)
63 foreach (SLIB ${ARGN})
64 embed_systemlib_byname(${EXTNAME} ${SLIB})
66 embed_systemlibs(${EXTNAME} "${EXTNAME}.so")
69 function(HHVM_DEFINE EXTNAME)
70 add_definitions(${ARGN})