1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7 FATAL_ERROR)
2 # Make `get_target_property()` on a target that does not exist a fatal error
3 # https://cmake.org/cmake/help/v3.0/policy/CMP0045.html
4 cmake_policy(SET CMP0045 NEW)
5 # ditto for add_dependencies(): https://cmake.org/cmake/help/v3.0/policy/CMP0046.html
6 cmake_policy(SET CMP0046 NEW)
8 # This needs to be done before any languages are enabled or
9 # projects are created.
10 INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/CMake/VisualStudioToolset.cmake")
13 SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
14 include_directories(${CMAKE_CURRENT_BINARY_DIR})
16 PROJECT(hhvm C CXX ASM)
21 enable_language(ASM_MASM)
24 # Look for and apply patches to the third-party (and sub) repo.
25 file(GLOB PATCHES "${CMAKE_SOURCE_DIR}/patches/*.patch")
27 message(STATUS "Patches: ${PATCHES}")
28 foreach(PATCH ${PATCHES})
29 message(STATUS "Applying ${PATCH}")
31 COMMAND patch -p1 --forward --ignore-whitespace
32 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
34 OUTPUT_VARIABLE OUTPUT
35 RESULT_VARIABLE RESULT)
37 message(STATUS "Patch applied: ${PATCH}")
39 # Unfortunately although patch will recognise that a patch is already
40 # applied it will still return an error.
42 COMMAND patch -p1 -R --dry-run
43 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
45 OUTPUT_VARIABLE OUTPUT
46 RESULT_VARIABLE RESULT2)
48 message(STATUS "Patch was already applied: ${PATCH}")
50 message(FATAL_ERROR "Error applying patch ${PATCH}")
57 MARK_AS_ADVANCED(CLEAR CMAKE_INSTALL_PREFIX)
59 # CMake really likes finding libraries inside OS X frameworks. This can
60 # create super unexpected results, such as the LDAP framework, where the
61 # ldap.h header there just consists of "#include <ldap.h>" -- obviously
62 # assuming /usr/include appears on the include path before that framework
63 # (which wasn't really supposed to be on the include path at all). This
64 # leads to a hilarious recursive include and general fireworks. Instead,
65 # tell CMake to search frameworks *last*, if it doesn't find something in
66 # /usr (or MacPorts/Homebrew).
67 SET(CMAKE_FIND_FRAMEWORK "LAST")
68 MARK_AS_ADVANCED(CMAKE_OSX_ARCHITECTURES
69 CMAKE_OSX_DEPLOYMENT_TARGET
71 SET(CMAKE_OSX_DEPLOYMENT_TARGET 10.15)
74 # Check architecture OS
75 IF(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
76 MESSAGE(FATAL_ERROR "HHVM requires a 64bit OS")
79 # Enable ccache if present and not already enabled system wide.
80 option(SKIP_CCACHE "Skip detecting/enabling ccache - no effect if ccache enabled system wide" FALSE)
82 find_program(CCACHE_FOUND ccache)
84 if (NOT ("${CMAKE_CXX_COMPILER} ${CMAKE_C_COMPILER}" MATCHES ".*ccache.*"))
85 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND})
86 message(STATUS "Found ccache: ${CCACHE_FOUND} - enabling ccache as compiler wrapper")
88 message(STATUS "Found ccache - ccache already in use as C and/or CXX compiler wrapper")
91 endif(NOT SKIP_CCACHE)
94 IF(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third-party/CMakeLists.txt")
95 MESSAGE(FATAL_ERROR "third-party/CMakeLists.txt missing. "
96 "Try updating your submodule with:
98 git submodule update --init --recursive
102 INCLUDE(HPHPFunctions)
103 INCLUDE(CheckFunctionExists)
105 SET(HPHP_HOME ${CMAKE_CURRENT_SOURCE_DIR})
106 SET(TP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
107 SET(TP_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/third-party")
109 include(MSVCDefaults)
111 include(HPHPCompiler)
112 include(HPHPFindLibs)
114 ADD_SUBDIRECTORY(third-party EXCLUDE_FROM_ALL)
115 ADD_SUBDIRECTORY(hphp)
117 # use GNU install dirs (e.g. lib64 instead of lib)
118 INCLUDE(GNUInstallDirs)
121 FILE(GLOB HHVM_CMAKE_FILES "CMake/*.cmake")
123 FILES ${HHVM_CMAKE_FILES}
124 DESTINATION "${CMAKE_INSTALL_LIBDIR}/hhvm/CMake"