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")
96 message(STATUS "Dune build detected")
98 list(APPEND extra_include_paths ${LZ4_INCLUDE_DIR})
99 list(APPEND extra_lib_paths ${LZ4_LIBRARY})
100 list(APPEND extra_native_libraries "lz4")
102 list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
103 list(APPEND extra_lib_paths ${LIBSQLITE3_LIBRARY})
104 list(APPEND extra_native_libraries "sqlite3")
107 # Xcode/Ninja generators undefined MAKE
114 DEPENDS ocaml opam_setup.sh
116 ${CMAKE_CURRENT_SOURCE_DIR}/opam_setup.sh
117 "${OCAML_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}"
118 && cmake -E touch opam.stamp
120 add_custom_target(opam_setup DEPENDS opam.stamp opam_setup.sh)
123 set(OPAMROOT "~/.opam")
125 set(OPAMROOT "${CMAKE_CURRENT_SOURCE_DIR}/_build/.opam")
128 # ARGV2 (optional unnamed argument) is expected to only be set to ALL
129 # if one wants the target to be run with the default rule of Makefile
130 function(invoke_ocamlbuild name target)
135 export OPAMROOT=${OPAMROOT} &&
136 export OCAMLFIND_COMMANDS="-ocamlc=${OCAMLC_EXECUTABLE} -ocamlopt=${OCAMLOPT_EXECUTABLE}" &&
137 PATH="${TP_BUILD_DIR}/ocaml/build/bin:$(PATH)"
139 $(MAKE) --makefile=Makefile.ocamlbuild ${target}
140 EXTRA_INCLUDE_PATHS="${extra_include_paths}"
141 EXTRA_LIB_PATHS="${extra_lib_paths}"
142 EXTRA_LINK_OPTS="${extra_link_opts}"
143 EXTRA_CC_FLAGS="${extra_cc_flags}"
144 EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
145 BYTECODE="${EMIT_OCAML_BYTECODE}"
146 OCAML="${OCAML_EXECUTABLE}"
147 OCAMLC="${OCAMLC_EXECUTABLE}"
148 OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
149 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
151 add_dependencies(${name} ocaml opam_setup)
154 invoke_ocamlbuild(hack all ALL)
155 invoke_ocamlbuild(hack_test test)
157 function(invoke_dune name target)
162 export OPAMROOT=${OPAMROOT} &&
163 export OCAMLFIND_COMMANDS="-ocamlc=${OCAMLC_EXECUTABLE} -ocamlopt=${OCAMLOPT_EXECUTABLE}" &&
164 PATH="${TP_BUILD_DIR}/ocaml/build/bin:$(PATH)"
166 $(MAKE) --makefile=Makefile.dune ${target}
167 EXTRA_INCLUDE_PATHS="${extra_include_paths}"
168 EXTRA_LIB_PATHS="${extra_lib_paths}"
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}"
177 add_dependencies(${name} ocaml)
179 add_dependencies(${name} opam_setup)
183 invoke_dune(hack_dune_debug debug)
184 invoke_dune(hack_dune_test test)
185 # TODO: when ocamlbuild is removed, add ALL to hack_dune
186 invoke_dune(hack_dune all)
189 # if the system does not have lz4, make sure that the one in public_tl
191 add_dependencies(hack lz4)
192 add_dependencies(hack_dune lz4)
193 add_dependencies(hack_test lz4)
196 if(NOT PC_SQLITE3_FOUND)
197 # if the system does not have sqlite3, make sure that the one in public_tl
199 add_dependencies(hack sqlite3)
200 add_dependencies(hack_dune sqlite3)
201 add_dependencies(hack_test sqlite3)
206 "src/options/buildOptions.ml.in"
207 "${CMAKE_CURRENT_SOURCE_DIR}/src/options/buildOptions.ml"
212 "src/options/buildOptions.ml.in"
213 "${CMAKE_CURRENT_SOURCE_DIR}/src/options/default_buildOptions.ml"
219 "src/fsnotify/dune.in"
220 "${CMAKE_CURRENT_SOURCE_DIR}/src/fsnotify/dune"
223 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_client
227 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_server
231 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hackfmt
235 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_parse
239 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_single_compile