Invalidate specific decls before IDE queries
[hiphop-php.git] / hphp / hack / CMakeLists.txt
blob9559e427bc4d29b95d6cb965394343c572af71e4
1 option(BUILD_HACK "True if we should build the Hack typechecker." ON)
3 if (NOT BUILD_HACK)
4   message(STATUS "Skipping hack")
5   return()
6 endif()
8 message(STATUS "Building hack")
10 find_package(LZ4)
11 find_package(LibElf)
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:
18 # - static libraries
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)
24 unset(extra_cc_flags)
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
32 if(NOT MAKE)
33   set(MAKE make)
34 endif()
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")
39 else()
40   set(DUNE_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
41   set(OPAM_STAMP_FILE "opam.stamp")
42 endif()
44 add_custom_command(
45   OUTPUT "${OPAM_STAMP_FILE}"
46   DEPENDS ocaml opam_setup.sh
47   COMMAND
48     ${CMAKE_CURRENT_SOURCE_DIR}/opam_setup.sh
49     "${OCAML_EXECUTABLE}"
50     "${CMAKE_CURRENT_SOURCE_DIR}"
51     "${DUNE_BUILD_DIR}"
52     && cmake -E touch "${OPAM_STAMP_FILE}"
54 add_custom_target(opam_setup DEPENDS "${OPAM_STAMP_FILE}" opam_setup.sh)
56 if (SKIP_OPAM)
57   set(OPAMROOT "~/.opam")
58 else ()
59   set(OPAMROOT "${DUNE_BUILD_DIR}/opam")
60 endif()
62 if(LZ4_FOUND)
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")
67 else()
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>")
74 endif()
76 if(PC_SQLITE3_FOUND)
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")
81 else()
82   list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
83   list(APPEND extra_link_opts "$<TARGET_LINKER_FILE:sqlite3>")
84 endif()
86 function(invoke_dune name target)
87   add_custom_target(
88       ${name}
89       COMMAND
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)"
95         opam config exec --
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}"
110     )
112   add_dependencies(${name} ocaml)
113   if (NOT SKIP_OPAM)
114     add_dependencies(${name} opam_setup)
115   endif()
116 endfunction()
118 invoke_dune(hack_dune_debug debug)
119 invoke_dune(hack_dune_test test)
120 invoke_dune(hack_dune all)
122 if (NOT LZ4_FOUND)
123   add_dependencies(hack_dune lz4)
124   add_dependencies(hack_dune_debug lz4)
125   add_dependencies(hack_dune_test lz4)
126 endif()
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)
132 endif()
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
138 # explicitly used
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
143   DESTINATION bin
144   COMPONENT dev)
146 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_server
147   DESTINATION bin
148   COMPONENT dev)
150 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hackfmt
151   DESTINATION bin
152   COMPONENT dev)
154 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_parse
155   DESTINATION bin
156   COMPONENT dev)
158 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_single_compile
159   DESTINATION bin
160   COMPONENT dev)