1 # The core function for generating `hphp-config.h`. This is done here to keep
2 # the main CMake tree clean.
4 # If you add any defines here or in hphp-config.h.in, you must make sure
5 # to update the non-CMake side. If you are not sure if a particular define
6 # should be present, ask your FB reviewer.
8 include(CheckCXXSourceCompiles)
9 include(CheckFunctionExists)
10 include(CheckIncludeFile)
12 # Build a string to define the appropriate macros for the headers that
13 # we are able to find.
14 function(HHVM_GENERATE_CONFIG_HEADERS_FOUND_DEFINE_STRING destVarName)
15 # This is a list of headers to check for and add defines in the form of
16 # HAVE_*_H if they are present. Note that all slashes will be replaced
17 # with a single underscore. Please keep ordered such that all headers
18 # in a root directory are first, followed by headers in a subdirectory.
19 # Note that .h will automatically be appended to the names of these before
21 set(HHVM_HEADERS_TO_CHECK)
22 list(APPEND HHVM_HEADERS_TO_CHECK
33 list(LENGTH HHVM_HEADERS_TO_CHECK headersCount)
35 while (i LESS ${headersCount})
36 list(GET HHVM_HEADERS_TO_CHECK ${i} curHeader)
37 string(REPLACE "/" "_" curHeaderClean "${curHeader}")
38 string(TOUPPER "${curHeaderClean}" curHeaderUpper)
39 CHECK_INCLUDE_FILE("${curHeader}.h" HAVE_${curHeaderUpper}_H)
40 if (${HAVE_${curHeaderUpper}_H})
41 set(builtString "${builtString}\n#define HAVE_${curHeaderUpper}_H 1")
43 set(builtString "${builtString}\n/* #undef HAVE_${curHeaderUpper}_H */")
45 math(EXPR i "${i} + 1")
48 set(${destVarName} "${builtString}" PARENT_SCOPE)
51 # Build a string to define the appropriate macros for the functions that
52 # we are able to find.
53 function(HHVM_GENERATE_CONFIG_FUNCTIONS_FOUND_DEFINE_STRING destVarName)
54 # This is a list of functions that need to be checked for.
55 set(HHVM_FUNCTIONS_TO_CHECK)
56 list(APPEND HHVM_FUNCTIONS_TO_CHECK
69 # This is a list of functions that are known to be present under MSVC
70 # because they are implemented via Folly's portability headers. For an
71 # item in this list to have any effect, it must first fail to be found
72 # when checking the item in the main list.
73 set(HHVM_FUNCTIONS_KNOWN_TO_BE_PRESENT_MSVC)
74 list(APPEND HHVM_FUNCTIONS_KNOWN_TO_BE_PRESENT_MSVC
80 list(LENGTH HHVM_FUNCTIONS_TO_CHECK functionCount)
82 while (i LESS ${functionCount})
83 list(GET HHVM_FUNCTIONS_TO_CHECK ${i} curFunc)
84 string(TOUPPER "${curFunc}" curFuncUpper)
85 CHECK_FUNCTION_EXISTS("${curFunc}" HAVE_${curFuncUpper})
86 if (${HAVE_${curFuncUpper}})
87 set(builtString "${builtString}\n#define HAVE_${curFuncUpper} 1")
89 list(FIND HHVM_FUNCTIONS_KNOWN_TO_BE_PRESENT_MSVC "${curFunc}" curFuncIdx)
90 if (curFuncIdx EQUAL -1 OR NOT MSVC)
91 set(builtString "${builtString}\n/* #undef HAVE_${curFuncUpper} */")
93 set(builtString "${builtString}\n#define HAVE_${curFuncUpper} 1 /* Implemented via Folly Portability header */")
96 math(EXPR i "${i} + 1")
99 set(${destVarName} "${builtString}" PARENT_SCOPE)
102 # Check if the source passed in compiles and add the appropriate define.
103 function(HHVM_GENERATE_CONFIG_CHECK_COMPILES destVarName defineName sourceToCheck)
104 CHECK_CXX_SOURCE_COMPILES("${sourceToCheck}" ${defineName})
106 set(${destVarName} "${${destVarName}}\n#define ${defineName} 1" PARENT_SCOPE)
108 set(${destVarName} "${${destVarName}}\n/* #undef ${defineName} */" PARENT_SCOPE)
112 # A quick check for use by HHVM_GENERATE_CONFIG_COMPILES_DEFINE_STRING to
113 # check if a struct defined in a particular header has a member with
114 # the specified name.
115 function(HHVM_GENERATE_CONFIG_STRUCT_HAS_MEMBER destVarName defineName headers structName memberName)
116 HHVM_GENERATE_CONFIG_CHECK_COMPILES(${destVarName} ${defineName} "
119 (void)((${structName}*)0)->${memberName};
123 set(${destVarName} ${${destVarName}} PARENT_SCOPE)
126 # A quick check for use by HHVM_GENERATE_CONFIG_COMPILES_DEFINE_STRING to
127 # check if a symbol is defined in a particular header.
128 function(HHVM_GENERATE_CONFIG_SYMBOL_EXISTS destVarName defineName headers symbolName)
129 HHVM_GENERATE_CONFIG_CHECK_COMPILES(${destVarName} ${defineName} "
135 return ((int*)(&${symbolName}))[0];
139 set(${destVarName} ${${destVarName}} PARENT_SCOPE)
142 # Build a define string for checks that require checking if some source code
144 function(HHVM_GENERATE_CONFIG_COMPILES_DEFINE_STRING destVarName)
147 HHVM_GENERATE_CONFIG_STRUCT_HAS_MEMBER(builtString HAVE_TM_ISDST "#include <time.h>" "tm" "tm_isdst")
148 HHVM_GENERATE_CONFIG_STRUCT_HAS_MEMBER(builtString HAVE_STRUCT_TM_TM_GMTOFF "#include <time.h>" "tm" "tm_gmtoff")
149 HHVM_GENERATE_CONFIG_STRUCT_HAS_MEMBER(builtString HAVE_STRUCT_TM_TM_ZONE "#include <time.h>" "tm" "tm_zone")
150 HHVM_GENERATE_CONFIG_SYMBOL_EXISTS(builtString HAVE_DAYLIGHT "#include <time.h>" "daylight")
151 HHVM_GENERATE_CONFIG_SYMBOL_EXISTS(builtString MAJOR_IN_MKDEV "#include <mkdev.h>" "major")
152 HHVM_GENERATE_CONFIG_SYMBOL_EXISTS(builtString MAJOR_IN_SYSMACROS "#include <sysmacros.h>" "major")
153 HHVM_GENERATE_CONFIG_CHECK_COMPILES(builtString HAVE_VISIBILITY "
154 __attribute__ ((__visibility__(\"hidden\"))) void someMethod(void);
159 set(${destVarName} "${builtString}" PARENT_SCOPE)
162 # Builds a string to define the macros for all enabled extensions.
163 function(HHVM_GENERATE_CONFIG_EXTENSIONS_ENABLED_DEFINE_STRING destVarName)
164 set(builtString "/* Extensions */")
166 while (i LESS HHVM_EXTENSION_COUNT)
167 string(TOUPPER ${HHVM_EXTENSION_${i}_NAME} upperExtName)
168 if (${HHVM_EXTENSION_${i}_ENABLED_STATE} EQUAL 1)
169 set(builtString "${builtString}\n#define ENABLE_EXTENSION_${upperExtName} 1")
171 set(builtString "${builtString}\n/* #undef ENABLE_EXTENSION_${upperExtName} */")
173 math(EXPR i "${i} + 1")
176 set(${destVarName} "${builtString}" PARENT_SCOPE)
179 # Generate the config file for HHVM.
180 function(HHVM_GENERATE_CONFIG dest)
181 HHVM_GENERATE_CONFIG_HEADERS_FOUND_DEFINE_STRING(HHVM_HEADERS_FOUND_DEFINE_STRING)
182 HHVM_GENERATE_CONFIG_FUNCTIONS_FOUND_DEFINE_STRING(HHVM_FUNCTIONS_FOUND_DEFINE_STRING)
183 HHVM_GENERATE_CONFIG_COMPILES_DEFINE_STRING(HHVM_COMPILES_DEFINE_STRING)
184 HHVM_GENERATE_CONFIG_EXTENSIONS_ENABLED_DEFINE_STRING(HHVM_EXTENSIONS_ENABLED_DEFINE_STRING)
185 configure_file("${HPHP_HOME}/hphp/util/hphp-config.h.in" "${dest}")