Back out "Pass C/C++ compiler to dune"
[hiphop-php.git] / CMake / HPHPSetup.cmake
bloba9d157fdbe2f901750ff506ebaba8655344934c4
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 implementations 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 definitions 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_zend
41   hphp_util
42   hphp_hhbbc
43   jit_sort
44   vixl neo)
46 if(ENABLE_FASTCGI)
47   LIST(APPEND HHVM_LINK_LIBRARIES thrift)
48   LIST(APPEND HHVM_LINK_LIBRARIES proxygen)
49   include(CheckCXXSourceCompiles)
50   CHECK_CXX_SOURCE_COMPILES("#include <pthread.h>
51   int main() {
52     return pthread_mutex_timedlock();
53   }" PTHREAD_TIMEDLOCK)
54   if (NOT PTHREAD_TIMEDLOCK)
55     add_definitions(-DTHRIFT_MUTEX_EMULATE_PTHREAD_TIMEDLOCK)
56   endif()
57 endif()
59 if(HHVM_DYNAMIC_EXTENSION_DIR)
60   add_definitions(-DHHVM_DYNAMIC_EXTENSION_DIR="${HHVM_DYNAMIC_EXTENSION_DIR}")
61 else()
62   if(UNIX)
63     add_definitions(-DHHVM_DYNAMIC_EXTENSION_DIR="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/hhvm/extensions")
64   endif()
65 endif()
67 # Look for the chrpath tool so we can warn if it's not there
68 SET(FOUND_CHRPATH OFF)
69 IF(UNIX AND NOT APPLE)
70     find_program(CHRPATH chrpath)
71     IF (NOT CHRPATH STREQUAL "CHRPATH-NOTFOUND")
72         SET(FOUND_CHRPATH ON)
73     endif()
74 ENDIF(UNIX AND NOT APPLE)
76 LIST(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
78 if(APPLE)
79   if(EXISTS "/opt/local/var/macports/")
80     LIST (APPEND CMAKE_PREFIX_PATH "/opt/local")
81     LIST (APPEND CMAKE_LIBRARY_PATH "/opt/local/lib/x86_64")
82   endif()
83 endif()
85 include(HPHPCompiler)
86 include(HPHPFunctions)
87 include(HPHPFindLibs)
89 if (HHVM_VERSION_OVERRIDE)
90   parse_version("HHVM_VERSION_" ${HHVM_VERSION_OVERRIDE})
91   add_definitions("-DHHVM_VERSION_OVERRIDE")
92   add_definitions("-DHHVM_VERSION_MAJOR=${HHVM_VERSION_MAJOR}")
93   add_definitions("-DHHVM_VERSION_MINOR=${HHVM_VERSION_MINOR}")
94   add_definitions("-DHHVM_VERSION_PATCH=${HHVM_VERSION_PATCH}")
95   add_definitions("-DHHVM_VERSION_SUFFIX=\"${HHVM_VERSION_SUFFIX}\"")
96 endif()
98 add_definitions(-D_REENTRANT=1 -D_PTHREADS=1 -D__STDC_FORMAT_MACROS)
100 if (LINUX)
101   add_definitions(-D_GNU_SOURCE)
102 endif()
104 if(MSVC)
105   add_definitions(-DGLOG_NO_ABBREVIATED_SEVERITIES)
106   add_definitions(-DWIN32_LEAN_AND_MEAN)
107 endif()
109 if(CMAKE_CONFIGURATION_TYPES)
110   if(NOT MSVC)
111     message(FATAL_ERROR "Adding the appropriate defines for multi-config targets using anything other than MSVC is not yet supported!")
112   endif()
113   foreach(flag_var
114       CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
115       CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
116     set(${flag_var} "${${flag_var}} /D NDEBUG")
117   endforeach()
118 elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug" OR
119        ${CMAKE_BUILD_TYPE} MATCHES "DebugOpt")
120   message("Generating DEBUG build")
121 else()
122   add_definitions(-DNDEBUG)
123   message("Generating Release build")
124 endif()
126 if(ALWAYS_ASSERT)
127   add_definitions(-DALWAYS_ASSERT=1)
128 endif()
130 if(APPLE OR FREEBSD OR MSVC)
131   add_definitions(-DSKIP_USER_CHANGE=1)
132 endif()
134 if(ENABLE_TRACE)
135     add_definitions(-DUSE_TRACE=1)
136 endif()
138 if(APPLE)
139   # We have to be a little more permissive in some cases.
140   add_definitions(-fpermissive)
142   # Skip deprecation warnings in OpenSSL.
143   add_definitions(-DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_6)
145   # Enable weak linking
146   add_definitions(-DMACOSX_DEPLOYMENT_TARGET=10.6)
147 endif()
149 if(ENABLE_FASTCGI)
150   add_definitions(-DENABLE_FASTCGI=1)
151 endif ()
153 if(DISABLE_HARDWARE_COUNTERS OR NOT LINUX)
154   add_definitions(-DNO_HARDWARE_COUNTERS=1)
155 endif ()
157 # enable the OSS options if we have any
158 add_definitions(-DHPHP_OSS=1)
160 # later versions of binutils don't play well without automake
161 add_definitions(-DPACKAGE=hhvm -DPACKAGE_VERSION=Release)
163 add_definitions(-DDEFAULT_CONFIG_DIR="${DEFAULT_CONFIG_DIR}")
165 add_definitions(-DHAVE_INTTYPES_H)
167 # Load system tzdata if present
168 # Works on Linux and Mac; given that we don't want to (and basically don't)
169 # update the bundled tzdata, if this doesn't work on some platform, please
170 # blacklist the platform rather than whitelisting others.
171 option(USE_BUNDLED_TZDATA "Use bundled system tzdata instead of /usr/share/zoneinfo" OFF)
172 if (NOT ${USE_BUNDLED_TZDATA})
173   if (NOT EXISTS /usr/share/zoneinfo)
174     message(FATAL_ERROR "/usr/share/zoneinfo does not exist, and USE_BUNDLED_TZDATA not set")
175   endif()
176   add_definitions(-DHAVE_SYSTEM_TZDATA)
177 endif()
179 include_directories(${TP_DIR})
180 if (THIRD_PARTY_INCLUDE_PATHS)
181   include_directories(${THIRD_PARTY_INCLUDE_PATHS})
182   add_definitions(${THIRD_PARTY_DEFINITIONS})
183   include_directories(${HPHP_HOME}/hphp)
184   include_directories(${HPHP_HOME})
185 endif()