Telemetry for parsing size
[hiphop-php.git] / CMake / HPHPSetup.cmake
blobf3480d6c02a305037b44f49f12ddc2bde2b932de
1 include(Options)
3 set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS Debug DebugOpt RelWithDebInfo)
5 set(HHVM_WHOLE_ARCHIVE_LIBRARIES
6     hphp_runtime_static
7     hphp_runtime_ext
8    )
10 set(HHVM_WRAP_SYMS)
12 # Oniguruma ('onig') must be first:
14 # oniguruma has some of its own implementations of POSIX regex functions,
15 # like regcomp() and regexec(). We use onig everywhere, for both its own
16 # special functions and for the POSIX replacements. This means that the
17 # linker needs to pick the implementions of the POSIX regex functions from
18 # onig, not libc.
20 # On Linux, that works out fine, since the linker sees onig on the link
21 # line before (implicitly) libc. However, on OS X, despite the manpage for
22 # ld claiming otherwise about indirect dylib dependencies, as soon as we
23 # include one of the libs here that pull in libSystem.B, the linker will
24 # pick the implementations of those functions from libc, not from onig.
25 # And since we've included the onig headers, which have very slightly
26 # different definintions for some of the key data structures, things go
27 # quite awry -- this manifests as infinite loops or crashes when calling
28 # the PHP split() function.
30 # So make sure to link onig first, so its implementations are picked.
32 # Using the generator expression to explicitly pull the path in early, otherwise
33 # it gets resolved later and put later in the build arguments, and makes
34 # hphp/test/slow/ext_preg segfault.
35 set(HHVM_LINK_LIBRARIES
36   $<TARGET_PROPERTY:onig,INTERFACE_LINK_LIBRARIES>
37   ${HHVM_WRAP_SYMS}
38   hphp_analysis
39   hphp_system
40   hphp_parser
41   hphp_zend
42   hphp_util
43   hphp_hhbbc
44   jit_sort
45   ppc64-asm
46   vixl neo)
48 if(ENABLE_FASTCGI)
49   LIST(APPEND HHVM_LINK_LIBRARIES hphp_thrift)
50   LIST(APPEND HHVM_LINK_LIBRARIES hphp_proxygen)
51   include(CheckCXXSourceCompiles)
52   CHECK_CXX_SOURCE_COMPILES("#include <pthread.h>
53   int main() {
54     return pthread_mutex_timedlock();
55   }" PTHREAD_TIMEDLOCK)
56   if (NOT PTHREAD_TIMEDLOCK)
57     add_definitions(-DTHRIFT_MUTEX_EMULATE_PTHREAD_TIMEDLOCK)
58   endif()
59 endif()
61 if(HHVM_DYNAMIC_EXTENSION_DIR)
62   add_definitions(-DHHVM_DYNAMIC_EXTENSION_DIR="${HHVM_DYNAMIC_EXTENSION_DIR}")
63 else()
64   if(UNIX)
65     add_definitions(-DHHVM_DYNAMIC_EXTENSION_DIR="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/hhvm/extensions")
66   endif()
67 endif()
69 # Look for the chrpath tool so we can warn if it's not there
70 SET(FOUND_CHRPATH OFF)
71 IF(UNIX AND NOT APPLE)
72     find_program(CHRPATH chrpath)
73     IF (NOT CHRPATH STREQUAL "CHRPATH-NOTFOUND")
74         SET(FOUND_CHRPATH ON)
75     endif()
76 ENDIF(UNIX AND NOT APPLE)
78 LIST(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
80 if(APPLE)
81   if(EXISTS "/opt/local/var/macports/")
82     LIST (APPEND CMAKE_PREFIX_PATH "/opt/local")
83     LIST (APPEND CMAKE_LIBRARY_PATH "/opt/local/lib/x86_64")
84   endif()
85 endif()
87 include(HPHPCompiler)
88 include(HPHPFunctions)
89 include(HPHPFindLibs)
91 if (HHVM_VERSION_OVERRIDE)
92   parse_version("HHVM_VERSION_" ${HHVM_VERSION_OVERRIDE})
93   add_definitions("-DHHVM_VERSION_OVERRIDE")
94   add_definitions("-DHHVM_VERSION_MAJOR=${HHVM_VERSION_MAJOR}")
95   add_definitions("-DHHVM_VERSION_MINOR=${HHVM_VERSION_MINOR}")
96   add_definitions("-DHHVM_VERSION_PATCH=${HHVM_VERSION_PATCH}")
97   add_definitions("-DHHVM_VERSION_SUFFIX=\"${HHVM_VERSION_SUFFIX}\"")
98 endif()
100 add_definitions(-D_REENTRANT=1 -D_PTHREADS=1 -D__STDC_FORMAT_MACROS)
102 if (LINUX)
103   add_definitions(-D_GNU_SOURCE)
104 endif()
106 if(MSVC)
107   add_definitions(-DGLOG_NO_ABBREVIATED_SEVERITIES)
108   add_definitions(-DWIN32_LEAN_AND_MEAN)
109 endif()
111 if(CMAKE_CONFIGURATION_TYPES)
112   if(NOT MSVC)
113     message(FATAL_ERROR "Adding the appropriate defines for multi-config targets using anything other than MSVC is not yet supported!")
114   endif()
115   foreach(flag_var
116       CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
117       CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
118     set(${flag_var} "${${flag_var}} /D NDEBUG")
119   endforeach()
120 elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug" OR
121        ${CMAKE_BUILD_TYPE} MATCHES "DebugOpt")
122   message("Generating DEBUG build")
123 else()
124   add_definitions(-DNDEBUG)
125   message("Generating Release build")
126 endif()
128 if(ALWAYS_ASSERT)
129   add_definitions(-DALWAYS_ASSERT=1)
130 endif()
132 if(APPLE OR FREEBSD OR MSVC)
133   add_definitions(-DSKIP_USER_CHANGE=1)
134 endif()
136 if(ENABLE_TRACE)
137     add_definitions(-DUSE_TRACE=1)
138 endif()
140 if(APPLE)
141   # We have to be a little more permissive in some cases.
142   add_definitions(-fpermissive)
144   # Skip deprecation warnings in OpenSSL.
145   add_definitions(-DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_6)
147   # Enable weak linking
148   add_definitions(-DMACOSX_DEPLOYMENT_TARGET=10.6)
149 endif()
151 if(ENABLE_FASTCGI)
152   add_definitions(-DENABLE_FASTCGI=1)
153 endif ()
155 if(DISABLE_HARDWARE_COUNTERS OR NOT LINUX)
156   add_definitions(-DNO_HARDWARE_COUNTERS=1)
157 endif ()
159 # enable the OSS options if we have any
160 add_definitions(-DHPHP_OSS=1)
162 # later versions of binutils don't play well without automake
163 add_definitions(-DPACKAGE=hhvm -DPACKAGE_VERSION=Release)
165 add_definitions(-DDEFAULT_CONFIG_DIR="${DEFAULT_CONFIG_DIR}")
167 add_definitions(-DHAVE_INTTYPES_H)
169 include_directories(${TP_DIR})
170 if (THIRD_PARTY_INCLUDE_PATHS)
171   include_directories(${THIRD_PARTY_INCLUDE_PATHS})
172   add_definitions(${THIRD_PARTY_DEFINITIONS})
173   include_directories(${HPHP_HOME}/hphp)
174   include_directories(${HPHP_HOME})
175 endif()