Updating submodules
[hiphop-php.git] / CMake / HPHPSetup.cmake
blob34573f04395c68dc9188fa9c125d6210c9bf5b13
1 include(Options)
2 include(GNUInstallDirs)
4 set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug DebugOpt RelWithDebInfo)
6 set(HHVM_WHOLE_ARCHIVE_LIBRARIES
7     hphp_runtime_static
8     hphp_runtime_ext
9    )
11 set(HHVM_WRAP_SYMS)
13 # Oniguruma ('onig') must be first:
15 # oniguruma has some of its own implementations of POSIX regex functions,
16 # like regcomp() and regexec(). We use onig everywhere, for both its own
17 # special functions and for the POSIX replacements. This means that the
18 # linker needs to pick the implementations of the POSIX regex functions from
19 # onig, not libc.
21 # On Linux, that works out fine, since the linker sees onig on the link
22 # line before (implicitly) libc. However, on OS X, despite the manpage for
23 # ld claiming otherwise about indirect dylib dependencies, as soon as we
24 # include one of the libs here that pull in libSystem.B, the linker will
25 # pick the implementations of those functions from libc, not from onig.
26 # And since we've included the onig headers, which have very slightly
27 # different definitions for some of the key data structures, things go
28 # quite awry -- this manifests as infinite loops or crashes when calling
29 # the PHP split() function.
31 # So make sure to link onig first, so its implementations are picked.
33 # Using the generator expression to explicitly pull the path in early, otherwise
34 # it gets resolved later and put later in the build arguments, and makes
35 # hphp/test/slow/ext_preg segfault.
36 set(HHVM_LINK_LIBRARIES
37   $<TARGET_PROPERTY:onig,INTERFACE_LINK_LIBRARIES>
38   ${HHVM_WRAP_SYMS}
39   hphp_analysis
40   hphp_system
41   hphp_zend
42   hphp_util
43   hphp_hhbbc
44   jit_sort
45   vixl neo)
47 if(ENABLE_FASTCGI)
48   LIST(APPEND HHVM_LINK_LIBRARIES thrift)
49   LIST(APPEND HHVM_LINK_LIBRARIES proxygen)
50   include(CheckCXXSourceCompiles)
51   CHECK_CXX_SOURCE_COMPILES("#include <pthread.h>
52   int main() {
53     return pthread_mutex_timedlock();
54   }" PTHREAD_TIMEDLOCK)
55   if (NOT PTHREAD_TIMEDLOCK)
56     add_definitions(-DTHRIFT_MUTEX_EMULATE_PTHREAD_TIMEDLOCK)
57   endif()
58 endif()
60 if(HHVM_DYNAMIC_EXTENSION_DIR)
61   add_definitions(-DHHVM_DYNAMIC_EXTENSION_DIR="${HHVM_DYNAMIC_EXTENSION_DIR}")
62 else()
63   if(UNIX)
64     add_definitions(-DHHVM_DYNAMIC_EXTENSION_DIR="${CMAKE_INSTALL_FULL_LIBDIR}/hhvm/extensions")
65   endif()
66 endif()
68 # Look for the chrpath tool so we can warn if it's not there
69 SET(FOUND_CHRPATH OFF)
70 IF(UNIX AND NOT APPLE)
71     find_program(CHRPATH chrpath)
72     IF (NOT CHRPATH STREQUAL "CHRPATH-NOTFOUND")
73         SET(FOUND_CHRPATH ON)
74     endif()
75 ENDIF(UNIX AND NOT APPLE)
77 LIST(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
79 if(APPLE)
80   if(EXISTS "/opt/local/var/macports/")
81     LIST (APPEND CMAKE_PREFIX_PATH "/opt/local")
82     LIST (APPEND CMAKE_LIBRARY_PATH "/opt/local/lib/x86_64")
83   endif()
84 endif()
86 include(HPHPCompiler)
87 include(HPHPFunctions)
88 include(HPHPFindLibs)
90 if (HHVM_VERSION_OVERRIDE)
91   parse_version("HHVM_VERSION_" ${HHVM_VERSION_OVERRIDE})
92   add_definitions("-DHHVM_VERSION_OVERRIDE")
93   add_definitions("-DHHVM_VERSION_MAJOR=${HHVM_VERSION_MAJOR}")
94   add_definitions("-DHHVM_VERSION_MINOR=${HHVM_VERSION_MINOR}")
95   add_definitions("-DHHVM_VERSION_PATCH=${HHVM_VERSION_PATCH}")
96   add_definitions("-DHHVM_VERSION_SUFFIX=\"${HHVM_VERSION_SUFFIX}\"")
97 endif()
99 add_definitions(-D_REENTRANT=1 -D_PTHREADS=1 -D__STDC_FORMAT_MACROS)
101 if (LINUX)
102   add_definitions(-D_GNU_SOURCE)
103 endif()
105 if(MSVC)
106   add_definitions(-DGLOG_NO_ABBREVIATED_SEVERITIES)
107   add_definitions(-DWIN32_LEAN_AND_MEAN)
108 endif()
110 if(CMAKE_CONFIGURATION_TYPES)
111   if(NOT MSVC)
112     message(FATAL_ERROR "Adding the appropriate defines for multi-config targets using anything other than MSVC is not yet supported!")
113   endif()
114   foreach(flag_var
115       CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
116       CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
117     set(${flag_var} "${${flag_var}} /D NDEBUG")
118   endforeach()
119 elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug" OR
120        ${CMAKE_BUILD_TYPE} MATCHES "DebugOpt")
121   message("Generating DEBUG build")
122 else()
123   add_definitions(-DNDEBUG)
124   message("Generating Release build")
125 endif()
127 if(ALWAYS_ASSERT)
128   add_definitions(-DALWAYS_ASSERT=1)
129 endif()
131 if(APPLE OR FREEBSD OR MSVC)
132   add_definitions(-DSKIP_USER_CHANGE=1)
133 endif()
135 if(ENABLE_TRACE)
136     add_definitions(-DUSE_TRACE=1)
137 endif()
139 if(APPLE)
140   # We have to be a little more permissive in some cases.
141   add_definitions(-fpermissive)
143   # Skip deprecation warnings in OpenSSL.
144   add_definitions(-DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_6)
146   # Enable weak linking
147   add_definitions(-DMACOSX_DEPLOYMENT_TARGET=10.6)
148 endif()
150 if(ENABLE_FASTCGI)
151   add_definitions(-DENABLE_FASTCGI=1)
152 endif ()
154 if(DISABLE_HARDWARE_COUNTERS OR NOT LINUX)
155   add_definitions(-DNO_HARDWARE_COUNTERS=1)
156 endif ()
158 # enable the OSS options if we have any
159 add_definitions(-DHPHP_OSS=1)
161 # later versions of binutils don't play well without automake
162 add_definitions(-DPACKAGE=hhvm -DPACKAGE_VERSION=Release)
164 add_definitions(-DDEFAULT_CONFIG_DIR="${DEFAULT_CONFIG_DIR}")
166 add_definitions(-DHAVE_INTTYPES_H)
168 # Load system tzdata if present
169 # Works on Linux and Mac; given that we don't want to (and basically don't)
170 # update the bundled tzdata, if this doesn't work on some platform, please
171 # blacklist the platform rather than whitelisting others.
172 option(USE_BUNDLED_TZDATA "Use bundled system tzdata instead of /usr/share/zoneinfo" OFF)
173 if (NOT ${USE_BUNDLED_TZDATA})
174   if (NOT DEFINED HAVE_SYSTEM_TZDATA AND NOT EXISTS /usr/share/zoneinfo)
175     message(FATAL_ERROR "/usr/share/zoneinfo does not exist, and USE_BUNDLED_TZDATA not set")
176   endif()
177   add_definitions(-DHAVE_SYSTEM_TZDATA)
178 endif()
180 include_directories(${TP_DIR})
181 if (THIRD_PARTY_INCLUDE_PATHS)
182   include_directories(${THIRD_PARTY_INCLUDE_PATHS})
183   add_definitions(${THIRD_PARTY_DEFINITIONS})
184   include_directories(${HPHP_HOME}/hphp)
185   include_directories(${HPHP_HOME})
186 endif()
188 if (ENABLE_SYSTEM_LOCALE_ARCHIVE)
189   add_definitions(-DENABLE_SYSTEM_LOCALE_ARCHIVE)
190 endif()