1 option(BUILD_HACK "True if we should build the Hack typechecker." ON)
4 message(STATUS "Skipping hack")
8 message(STATUS "Building hack")
13 # native_libraries: values for `-l` flags
14 # lib_paths: values for `-L` flags (directories)
15 # extra_link_opts: opaque options passed to the linker
17 # We need extra_link_opts for:
19 # - anything built from third-party: cmake gives us the link flags
20 unset(extra_include_paths)
21 unset(extra_native_libraries)
22 unset(extra_lib_paths)
23 unset(extra_link_opts)
26 # Allows '#include "hphp/path/to/library/"' paths to start from hphp
27 # project directory which is consistent with fbmake's include paths.
28 list(APPEND extra_include_paths ${HPHP_HOME})
29 list(APPEND extra_cc_flags -pthread)
31 # Xcode/Ninja generators undefined MAKE
36 if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
37 set(DUNE_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_build")
38 set(OPAM_STAMP_FILE "_build/opam.stamp")
40 set(DUNE_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
41 set(OPAM_STAMP_FILE "opam.stamp")
45 OUTPUT "${OPAM_STAMP_FILE}"
46 DEPENDS ocaml opam_setup.sh
48 ${CMAKE_CURRENT_SOURCE_DIR}/opam_setup.sh
50 "${CMAKE_CURRENT_SOURCE_DIR}"
52 && cmake -E touch "${OPAM_STAMP_FILE}"
54 add_custom_target(opam_setup DEPENDS "${OPAM_STAMP_FILE}" opam_setup.sh)
57 set(OPAMROOT "~/.opam")
59 set(OPAMROOT "${DUNE_BUILD_DIR}/opam")
63 list(APPEND extra_include_paths ${LZ4_INCLUDE_DIR})
64 get_filename_component(pth ${LZ4_LIBRARY} DIRECTORY)
65 list(APPEND extra_lib_paths ${pth})
66 list(APPEND extra_native_libraries "lz4")
68 list(APPEND extra_include_paths "${TP_DIR}/lz4/src/lib")
69 # If LZ4_FOUND is false either we didn't find lz4 or we found it but it's the
70 # wrong version. We can't just add the new path and a native_lib because we
71 # can't control the order (and -l won't accept the raw path to the lib). By
72 # doing it this way we specify the path explicitly.
73 list(APPEND extra_link_opts "$<TARGET_LINKER_FILE:lz4>")
77 list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
78 get_filename_component(pth ${LIBSQLITE3_LIBRARY} DIRECTORY)
79 list(APPEND extra_lib_paths ${pth})
80 list(APPEND extra_native_libraries "sqlite3")
82 list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
83 list(APPEND extra_link_opts "$<TARGET_LINKER_FILE:sqlite3>")
86 function(invoke_dune name target)
90 export OPAMROOT=${OPAMROOT} &&
91 export PYTHONPATH="${HPHP_HOME}" && # needed for verify.py for `hack_dune_test`
92 export HACK_SOURCE_ROOT="${CMAKE_CURRENT_SOURCE_DIR}" &&
93 export HACK_BUILD_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/_build/default" &&
94 PATH="${TP_BUILD_DIR}/ocaml/build/bin:$(PATH)"
96 $(MAKE) --makefile=Makefile.dune ${target}
97 DUNE_BUILD_DIR="${DUNE_BUILD_DIR}"
98 CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}"
99 CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
100 CMAKE_INSTALL_FULL_SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}"
101 CMAKE_INSTALL_FULL_BINDIR="${CMAKE_INSTALL_FULL_BINDIR}"
102 EXTRA_INCLUDE_PATHS="${extra_include_paths}"
103 EXTRA_LINK_OPTS="${extra_link_opts}"
104 EXTRA_LIB_PATHS="${extra_lib_paths}"
105 EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
106 BYTECODE="${EMIT_OCAML_BYTECODE}"
107 OCAML="${OCAML_EXECUTABLE}"
108 OCAMLC="${OCAMLC_EXECUTABLE}"
109 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
112 add_dependencies(${name} ocaml)
114 add_dependencies(${name} opam_setup)
118 invoke_dune(hack_dune_debug debug)
119 invoke_dune(hack_dune_test test)
120 invoke_dune(hack_dune all)
123 add_dependencies(hack_dune lz4)
124 add_dependencies(hack_dune_debug lz4)
125 add_dependencies(hack_dune_test lz4)
128 if (NOT PC_SQLITE3_FOUND)
129 add_dependencies(hack_dune sqlite3)
130 add_dependencies(hack_dune_debug sqlite3)
131 add_dependencies(hack_dune_test sqlite3)
134 # Intentionally not using `hack_dune_debug` as it generates output files of a
135 # different format (bytecode instead of raw executables, which is useful if
136 # you're working with Hack, but means that e.g. hhvm can't find
137 # `hh_single_compile` in the source tree. Keep it around, but require it to be
139 add_custom_target(hack ALL DEPENDS hack_dune)
140 add_custom_target(hack_test DEPENDS hack_dune_test)
142 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_client
146 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_server
150 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hackfmt
154 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_parse
158 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_single_compile