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)
8 message(STATUS "Skipping hack")
12 message(STATUS "Building hack")
14 if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
15 set(HACK_ONLY_BUILD TRUE)
20 # Woah - this is special. They're running cmake in the hack directory
21 # itself so we don't have our usual set up.
22 get_filename_component(HPHP_HOME "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
23 set(TP_DIR "${HPHP_HOME}/third-party")
24 set(TP_BUILD_DIR ${TP_DIR})
26 if(NOT EXISTS "${TP_DIR}/CMakeLists.txt")
28 "${TP_DIR}/CMakeLists.txt missing. Try updating your submodule with:\n"
30 " git submodule update --init --recursive\n"
38 if (HACK_ONLY_BUILD AND NOT LZ4_FOUND)
39 add_subdirectory("${TP_DIR}/lz4" "${TP_DIR}/lz4" EXCLUDE_FROM_ALL)
43 add_subdirectory("${TP_DIR}/ocaml" "${TP_DIR}/ocaml" EXCLUDE_FROM_ALL)
46 if (HACK_ONLY_BUILD AND NOT PC_SQLITE3_FOUND)
48 "${TP_DIR}/libsqlite3"
49 "${TP_DIR}/libsqlite3"
53 # This is totally the wrong way to do this, but I am tired of fighting with
54 # build systems and don't really care to make this work the right way.
55 # lz4 and sqlite3 are all we need right now anyways.
56 unset(extra_include_paths)
57 unset(extra_lib_paths)
60 # Allows '#include "hphp/path/to/library/"' paths to start from hphp
61 # project directory which is consistent with fbmake's include paths.
64 list(APPEND extra_include_paths ${HPHP_HOME})
66 list(APPEND extra_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/../..)
69 list(APPEND extra_cc_flags -pthread)
72 list(APPEND extra_include_paths ${LZ4_INCLUDE_DIR})
73 get_filename_component(pth ${LZ4_LIBRARY} PATH)
74 list(APPEND extra_lib_paths ${pth})
75 list(APPEND extra_native_libraries "lz4")
77 list(APPEND extra_include_paths "${TP_DIR}/lz4/src/lib")
78 # If LZ4_FOUND is false either we didn't find lz4 or we found it but it's the
79 # wrong version. We can't just add the new path and a native_lib because we
80 # can't control the order (and -l won't accept the raw path to the lib). By
81 # doing it this way we specify the path explicitly.
82 list(APPEND extra_link_opts "$<TARGET_LINKER_FILE:lz4>")
86 list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
87 get_filename_component(pth ${LIBSQLITE3_LIBRARY} PATH)
88 list(APPEND extra_lib_paths ${pth})
90 list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
91 list(APPEND extra_lib_paths "${TP_BUILD_DIR}/libsqlite3")
93 list(APPEND extra_native_libraries "sqlite3")
97 # Xcode/Ninja generators undefined MAKE
106 ${CMAKE_CURRENT_SOURCE_DIR}/opam_setup.sh
107 "${OCAML_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/src"
109 add_dependencies(opam.stamp ocaml)
115 export OPAMROOT=${CMAKE_CURRENT_SOURCE_DIR}/src/_build/.opam &&
116 export OCAMLFIND_COMMANDS="-ocamlc=${OCAMLC_EXECUTABLE} -ocamlopt=${OCAMLOPT_EXECUTABLE}" &&
117 PATH="${TP_BUILD_DIR}/ocaml/build/bin:$(PATH)"
119 $(MAKE) --makefile=Makefile.ocamlbuild
120 EXTRA_INCLUDE_PATHS="${extra_include_paths}"
121 EXTRA_LIB_PATHS="${extra_lib_paths}"
122 EXTRA_LINK_OPTS="${extra_link_opts}"
123 EXTRA_CC_FLAGS="${extra_cc_flags}"
124 EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
125 BYTECODE="${EMIT_OCAML_BYTECODE}"
126 OCAML="${OCAML_EXECUTABLE}"
127 OCAMLC="${OCAMLC_EXECUTABLE}"
128 OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
129 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
131 add_dependencies(hack ocaml opam.stamp)
134 set(OPAMROOT "~/.opam")
136 set(OPAMROOT "${CMAKE_CURRENT_SOURCE_DIR}/src/_build/.opam")
142 export OPAMROOT=${OPAMROOT} &&
143 export OCAMLFIND_COMMANDS="-ocamlc=${OCAMLC_EXECUTABLE} -ocamlopt=${OCAMLOPT_EXECUTABLE}" &&
144 PATH="${TP_BUILD_DIR}/ocaml/build/bin:$(PATH)"
146 $(MAKE) --makefile=Makefile.dune
147 BYTECODE="${EMIT_OCAML_BYTECODE}"
148 OCAML="${OCAML_EXECUTABLE}"
149 OCAMLC="${OCAMLC_EXECUTABLE}"
150 OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
151 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
153 add_dependencies(hack_dune ocaml)
155 add_dependencies(hack_dune opam.stamp)
161 export OPAMROOT=${CMAKE_CURRENT_SOURCE_DIR}/src/_build/.opam &&
162 export OCAMLFIND_COMMANDS="-ocamlc=${OCAMLC_EXECUTABLE} -ocamlopt=${OCAMLOPT_EXECUTABLE}" &&
163 PATH="${TP_BUILD_DIR}/ocaml/build/bin:$(PATH)"
165 $(MAKE) test EXTRA_INCLUDE_PATHS="${extra_include_paths}"
166 EXTRA_LIB_PATHS="${extra_lib_paths}"
167 EXTRA_LINK_OPTS="${extra_link_opts}"
168 EXTRA_CC_FLAGS="${extra_cc_flags}"
169 EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
170 BYTECODE="${EMIT_OCAML_BYTECODE}"
171 OCAML="${OCAML_EXECUTABLE}"
172 OCAMLC="${OCAMLC_EXECUTABLE}"
173 OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
174 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
176 add_dependencies(hack_test ocaml opam.stamp)
179 # if the system does not have lz4, make sure that the one in public_tl
181 add_dependencies(hack lz4)
182 add_dependencies(hack_dune lz4)
183 add_dependencies(hack_test lz4)
186 if(NOT PC_SQLITE3_FOUND)
187 # if the system does not have sqlite3, make sure that the one in public_tl
189 add_dependencies(hack sqlite3)
190 add_dependencies(hack_dune sqlite3)
191 add_dependencies(hack_test sqlite3)
195 "src/options/buildOptions.ml.in"
196 "${CMAKE_CURRENT_SOURCE_DIR}/src/options/buildOptions.ml"
201 "src/fsnotify/dune.in"
202 "${CMAKE_CURRENT_SOURCE_DIR}/src/fsnotify/dune"
205 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_client
209 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_server
213 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hackfmt
217 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_parse
221 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_single_compile