Revert D5416550: UPDATED: Improving method error recovery, making use of refactored...
[hiphop-php.git] / hphp / hack / CMakeLists.txt
blob6d7465bcb938e1686713bfd5a1373b8c344851d5
1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7 FATAL_ERROR)
3 SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../CMake" ${CMAKE_MODULE_PATH})
5 option(BUILD_HACK "True if we should build the Hack typechecker." ON)
7 if (NOT BUILD_HACK)
8   message(STATUS "Skipping hack")
9   return()
10 endif()
12 message(STATUS "Building hack")
14 if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
15   set(HACK_ONLY_BUILD TRUE)
16 endif()
18 if (HACK_ONLY_BUILD)
19   # Woah - this is special. They're running cmake in the hack directory
20   # itself so we don't have our usual set up.
21   get_filename_component(HPHP_HOME "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
22   set(TP_DIR "${HPHP_HOME}/third-party")
23   set(TP_BUILD_DIR ${TP_DIR})
25   if(NOT EXISTS "${TP_DIR}/CMakeLists.txt")
26     message(FATAL_ERROR
27       "${TP_DIR}/CMakeLists.txt missing. Try updating your submodule with:\n"
28       "    rm -r ${TP_DIR}\n"
29       "    git submodule update --init --recursive\n"
30       )
31   endif()
32 endif()
34 find_package(LZ4)
35 find_package(LibElf)
37 if (HACK_ONLY_BUILD AND NOT LZ4_FOUND)
38   add_subdirectory("${TP_DIR}/lz4" "${TP_DIR}/lz4")
39 endif()
41 if (HACK_ONLY_BUILD AND NOT OCAML_FOUND)
42   add_subdirectory("${TP_DIR}/ocaml" "${TP_DIR}/ocaml")
43 endif()
45 if (HACK_ONLY_BUILD AND NOT PC_SQLITE3_FOUND)
46   add_subdirectory("${TP_DIR}/libsqlite3" "${TP_DIR}/libsqlite3")
47 endif()
49 # This is totally the wrong way to do this, but I am tired of fighting with
50 # build systems and don't really care to make this work the right way.
51 # lz4 and sqlite3 are all we need right now anyways.
52 unset(extra_include_paths)
53 unset(extra_lib_paths)
54 unset(extra_cc_flags)
56 # Allows '#include "hphp/path/to/library/"' paths to start from hphp
57 # project directory  which is consistent with fbmake's include paths.
59 IF(HPHP_HOME)
60   list(APPEND extra_include_paths ${HPHP_HOME})
61 ELSE()
62   list(APPEND extra_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/../..)
63 ENDIF()
65 list(APPEND extra_cc_flags -pthread)
67 if(LZ4_FOUND)
68   list(APPEND extra_include_paths ${LZ4_INCLUDE_DIR})
69   get_filename_component(pth ${LZ4_LIBRARY} PATH)
70   list(APPEND extra_lib_paths ${pth})
71   list(APPEND extra_native_libraries "lz4")
72 else()
73   list(APPEND extra_include_paths "${TP_DIR}/lz4/src/lib")
74   # If LZ4_FOUND is false either we didn't find lz4 or we found it but it's the
75   # wrong version.  We can't just add the new path and a native_lib because we
76   # can't control the order (and -l won't accept the raw path to the lib).  By
77   # doing it this way we specify the path explicitly.
78   list(APPEND extra_link_opts "$<TARGET_LINKER_FILE:lz4>")
79 endif()
81 if(PC_SQLITE3_FOUND)
82   list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
83   get_filename_component(pth ${LIBSQLITE3_LIBRARY} PATH)
84   list(APPEND extra_lib_paths ${pth})
85 else()
86   list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
87   list(APPEND extra_lib_paths "${TP_BUILD_DIR}/libsqlite3")
88 endif()
89 list(APPEND extra_native_libraries "sqlite3")
91 # Xcode/Ninja generators undefined MAKE
92 if(NOT MAKE)
93   set(MAKE make)
94 endif()
96 add_custom_target(
97   hack
98   ALL
99   COMMAND
100         $(MAKE) EXTRA_INCLUDE_PATHS="${extra_include_paths}"
101         EXTRA_LIB_PATHS="${extra_lib_paths}"
102         EXTRA_LINK_OPTS="${extra_link_opts}"
103         EXTRA_CC_FLAGS="${extra_cc_flags}"
104         EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
105         BYTECODE="${EMIT_OCAML_BYTECODE}"
106         OCAML="${OCAML_EXECUTABLE}"
107         OCAMLC="${OCAMLC_EXECUTABLE}"
108         OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
109         OCAMLBUILD_FLAGS="-ocamlc=${OCAMLC_EXECUTABLE},-ocamlopt=${OCAMLOPT_EXECUTABLE}"
110   WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
112 add_dependencies(hack ocaml)
114 add_custom_target(
115   hack_test
116   COMMAND
117         $(MAKE) test EXTRA_INCLUDE_PATHS="${extra_include_paths}"
118         EXTRA_LIB_PATHS="${extra_lib_paths}"
119         EXTRA_LINK_OPTS="${extra_link_opts}"
120         EXTRA_CC_FLAGS="${extra_cc_flags}"
121         EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
122         BYTECODE="${EMIT_OCAML_BYTECODE}"
123         OCAML="${OCAML_EXECUTABLE}"
124         OCAMLC="${OCAMLC_EXECUTABLE}"
125         OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
126         OCAMLBUILD_FLAGS="-ocamlc=${OCAMLC_EXECUTABLE},-ocamlopt=${OCAMLOPT_EXECUTABLE}"
127   WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
129 add_dependencies(hack_test ocaml)
131 if(NOT LZ4_FOUND)
132   # if the system does not have lz4, make sure that the one in public_tl
133   # gets built
134   add_dependencies(hack lz4)
135   add_dependencies(hack_test lz4)
136 endif()
138 if(NOT PC_SQLITE3_FOUND)
139   # if the system does not have sqlite3, make sure that the one in public_tl
140   # gets built
141   add_dependencies(hack sqlite3)
142   add_dependencies(hack_test sqlite3)
143 endif()
145 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_client
146   DESTINATION bin
147   COMPONENT dev)
149 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_server
150   DESTINATION bin
151   COMPONENT dev)
153 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hackfmt
154   DESTINATION bin
155   COMPONENT dev)
157 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_format
158   DESTINATION bin
159   COMPONENT dev)
161 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_parse
162   DESTINATION bin
163   COMPONENT dev)