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")
43 set(HACK_BUILD_ROOT "${DUNE_BUILD_DIR}/default")
45 get_target_property(OPAM_EXECUTABLE opam IMPORTED_LOCATION)
48 OUTPUT "${OPAM_STAMP_FILE}"
49 DEPENDS opam opam_setup.sh
51 ${CMAKE_CURRENT_SOURCE_DIR}/opam_setup.sh
54 && cmake -E touch "${OPAM_STAMP_FILE}"
56 add_custom_target(opam_setup DEPENDS "${OPAM_STAMP_FILE}" opam_setup.sh)
59 set(OPAMROOT "~/.opam")
61 set(OPAMROOT "${DUNE_BUILD_DIR}/opam")
65 list(APPEND extra_include_paths ${LZ4_INCLUDE_DIR})
66 get_filename_component(pth ${LZ4_LIBRARY} DIRECTORY)
67 list(APPEND extra_lib_paths ${pth})
68 list(APPEND extra_native_libraries "lz4")
70 get_target_property(LZ4_INCLUDE_DIRS lz4 INTERFACE_INCLUDE_DIRECTORIES)
71 list(APPEND extra_include_paths ${LZ4_INCLUDE_DIRS})
72 # If LZ4_FOUND is false either we didn't find lz4 or we found it but it's the
73 # wrong version. We can't just add the new path and a native_lib because we
74 # can't control the order (and -l won't accept the raw path to the lib). By
75 # doing it this way we specify the path explicitly.
76 get_target_property(LZ4_LIBS lz4 INTERFACE_LINK_LIBRARIES)
77 list(APPEND extra_link_opts ${LZ4_LIBS})
81 list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
82 get_filename_component(pth ${LIBSQLITE3_LIBRARY} DIRECTORY)
83 list(APPEND extra_lib_paths ${pth})
84 list(APPEND extra_native_libraries "sqlite3")
86 list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
87 get_target_property(SQLITE_DIR sqlite3 BINARY_DIR)
88 list(APPEND extra_link_opts "${SQLITE_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}sqlite3${CMAKE_STATIC_LIBRARY_SUFFIX}")
91 get_target_property(RUSTC_EXE rustc LOCATION)
92 get_target_property(CARGO_EXE cargo LOCATION)
93 get_filename_component(RUSTC_BIN_DIR "${RUSTC_EXE}" DIRECTORY)
94 get_filename_component(CARGO_BIN_DIR "${CARGO_EXE}" DIRECTORY)
96 function(invoke_dune name target)
100 . "${CMAKE_CURRENT_BINARY_DIR}/dev_env.sh" &&
102 $(MAKE) --makefile=Makefile.dune ${target}
103 BYTECODE="${EMIT_OCAML_BYTECODE}"
104 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
107 add_dependencies(${name} ocaml rustc cargo)
109 add_dependencies(${name} opam_setup)
113 invoke_dune(hack_dune_debug debug)
114 invoke_dune(hack_dune_test test)
115 invoke_dune(hack_dune all)
118 add_dependencies(hack_dune lz4)
119 add_dependencies(hack_dune_debug lz4)
120 add_dependencies(hack_dune_test lz4)
123 if (NOT PC_SQLITE3_FOUND)
124 add_dependencies(hack_dune sqlite3)
125 add_dependencies(hack_dune_debug sqlite3)
126 add_dependencies(hack_dune_test sqlite3)
129 # Intentionally not using `hack_dune_debug` as it generates output files of a
130 # different format (bytecode instead of raw executables, which is useful if
131 # you're working with Hack, but means that e.g. hhvm can't find
132 # `hh_single_compile` in the source tree. Keep it around, but require it to be
134 add_custom_target(hack ALL DEPENDS hack_dune)
135 add_custom_target(hack_test DEPENDS hack_dune_test)
137 configure_file(dev_env.sh.in dev_env.sh ESCAPE_QUOTES @ONLY)
139 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_client
143 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_server
147 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hackfmt
151 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_parse
155 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_single_compile