Update genPrefetchDir to find changed files since last saved state revision
[hiphop-php.git] / CMakeLists.txt
blobeb56875723953f46502d2c6228fdecce87aad592
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")
12 # includes
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)
18 include(HHVMProject)
20 if (MSVC)
21   enable_language(ASM_MASM)
22 endif()
24 # Look for and apply patches to the third-party (and sub) repo.
25 file(GLOB PATCHES "${CMAKE_SOURCE_DIR}/patches/*.patch")
26 if (PATCHES)
27   message(STATUS "Patches: ${PATCHES}")
28   foreach(PATCH ${PATCHES})
29     message(STATUS "Applying ${PATCH}")
30     execute_process(
31       COMMAND patch -p1 --forward --ignore-whitespace
32       WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
33       INPUT_FILE "${PATCH}"
34       OUTPUT_VARIABLE OUTPUT
35       RESULT_VARIABLE RESULT)
36     if (RESULT EQUAL 0)
37       message(STATUS "Patch applied: ${PATCH}")
38     else()
39       # Unfortunately although patch will recognise that a patch is already
40       # applied it will still return an error.
41       execute_process(
42         COMMAND patch -p1 -R --dry-run
43         WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
44         INPUT_FILE "${PATCH}"
45         OUTPUT_VARIABLE OUTPUT
46         RESULT_VARIABLE RESULT2)
47       if (RESULT2 EQUAL 0)
48         message(STATUS "Patch was already applied: ${PATCH}")
49       else()
50         message(FATAL_ERROR "Error applying patch ${PATCH}")
51       endif()
52     endif()
53   endforeach(PATCH)
54 endif()
57 MARK_AS_ADVANCED(CLEAR CMAKE_INSTALL_PREFIX)
58 IF(APPLE)
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
70     CMAKE_OSX_SYSROOT)
71   SET(CMAKE_OSX_DEPLOYMENT_TARGET 10.15)
72 ENDIF()
74 # Check architecture OS
75 IF(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
76   MESSAGE(FATAL_ERROR "HHVM requires a 64bit OS")
77 ENDIF()
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)
81 if(NOT SKIP_CCACHE)
82   find_program(CCACHE_FOUND ccache)
83   if(CCACHE_FOUND)
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")
87     else()
88       message(STATUS "Found ccache - ccache already in use as C and/or CXX compiler wrapper")
89    endif()
90   endif(CCACHE_FOUND)
91 endif(NOT SKIP_CCACHE)
93 # 3rd party library
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:
97 rm -r third-party
98 git submodule update --init --recursive
100 ENDIF()
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)
110 include(Options)
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)
120 # modules / depends
121 FILE(GLOB HHVM_CMAKE_FILES "CMake/*.cmake")
122 INSTALL(
123   FILES ${HHVM_CMAKE_FILES}
124   DESTINATION "${CMAKE_INSTALL_LIBDIR}/hhvm/CMake"
125   COMPONENT dev)