New inference: flatten unions when solving for lower bounds
[hiphop-php.git] / hphp / hack / CMakeLists.txt
blob4c71dceda3640b92bc6824af760ddeb340265594
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)
7 if (NOT BUILD_HACK)
8   message(STATUS "Skipping hack")
9   return()
10 endif()
12 message(STATUS "Building hack")
14 if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
15   set(HACK_ONLY_BUILD TRUE)
16 endif()
18 if (NOT WITH_DUNE)
19 if (HACK_ONLY_BUILD)
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")
27     message(FATAL_ERROR
28       "${TP_DIR}/CMakeLists.txt missing. Try updating your submodule with:\n"
29       "    rm -r ${TP_DIR}\n"
30       "    git submodule update --init --recursive\n"
31       )
32   endif()
33 endif()
35 find_package(LZ4)
36 find_package(LibElf)
38 if (HACK_ONLY_BUILD AND NOT LZ4_FOUND)
39   add_subdirectory("${TP_DIR}/lz4" "${TP_DIR}/lz4" EXCLUDE_FROM_ALL)
40 endif()
42 if (HACK_ONLY_BUILD)
43   add_subdirectory("${TP_DIR}/ocaml" "${TP_DIR}/ocaml" EXCLUDE_FROM_ALL)
44 endif()
46 if (HACK_ONLY_BUILD AND NOT PC_SQLITE3_FOUND)
47   add_subdirectory(
48     "${TP_DIR}/libsqlite3"
49     "${TP_DIR}/libsqlite3"
50     EXCLUDE_FROM_ALL)
51 endif()
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)
58 unset(extra_cc_flags)
60 # Allows '#include "hphp/path/to/library/"' paths to start from hphp
61 # project directory  which is consistent with fbmake's include paths.
63 IF(HPHP_HOME)
64   list(APPEND extra_include_paths ${HPHP_HOME})
65 ELSE()
66   list(APPEND extra_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/../..)
67 ENDIF()
69 list(APPEND extra_cc_flags -pthread)
71 if(LZ4_FOUND)
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")
76 else()
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>")
83 endif()
85 if(PC_SQLITE3_FOUND)
86   list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
87   get_filename_component(pth ${LIBSQLITE3_LIBRARY} PATH)
88   list(APPEND extra_lib_paths ${pth})
89 else()
90   list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
91   list(APPEND extra_lib_paths "${TP_BUILD_DIR}/libsqlite3")
92 endif()
93 list(APPEND extra_native_libraries "sqlite3")
95 endif() # WITH_DUNE
97 # Xcode/Ninja generators undefined MAKE
98 if(NOT MAKE)
99   set(MAKE make)
100 endif()
102 add_custom_target(
103   opam.stamp
104   ALL
105   COMMAND
106     ${CMAKE_CURRENT_SOURCE_DIR}/opam_setup.sh
107     "${OCAML_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/src"
109 add_dependencies(opam.stamp ocaml)
111 add_custom_target(
112   hack
113   ALL
114   COMMAND
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)"
118         opam config exec --
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)
133 if (SKIP_OPAM)
134   set(OPAMROOT "~/.opam")
135 else ()
136   set(OPAMROOT "${CMAKE_CURRENT_SOURCE_DIR}/src/_build/.opam")
137 endif()
139 add_custom_target(
140   hack_dune
141   COMMAND
142         export OPAMROOT=${OPAMROOT} &&
143         export OCAMLFIND_COMMANDS="-ocamlc=${OCAMLC_EXECUTABLE} -ocamlopt=${OCAMLOPT_EXECUTABLE}" &&
144         PATH="${TP_BUILD_DIR}/ocaml/build/bin:$(PATH)"
145         opam config exec --
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)
154 if (NOT SKIP_OPAM)
155   add_dependencies(hack_dune opam.stamp)
156 endif()
158 add_custom_target(
159   hack_test
160   COMMAND
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)"
164         opam config exec --
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)
178 if(NOT LZ4_FOUND)
179   # if the system does not have lz4, make sure that the one in public_tl
180   # gets built
181   add_dependencies(hack lz4)
182   add_dependencies(hack_dune lz4)
183   add_dependencies(hack_test lz4)
184 endif()
186 if(NOT PC_SQLITE3_FOUND)
187   # if the system does not have sqlite3, make sure that the one in public_tl
188   # gets built
189   add_dependencies(hack sqlite3)
190   add_dependencies(hack_dune sqlite3)
191   add_dependencies(hack_test sqlite3)
192 endif()
194 configure_file(
195   "src/options/buildOptions.ml.in"
196   "${CMAKE_CURRENT_SOURCE_DIR}/src/options/buildOptions.ml"
197   ESCAPE_QUOTES
200 configure_file(
201   "src/fsnotify/dune.in"
202   "${CMAKE_CURRENT_SOURCE_DIR}/src/fsnotify/dune"
205 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_client
206   DESTINATION bin
207   COMPONENT dev)
209 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_server
210   DESTINATION bin
211   COMPONENT dev)
213 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hackfmt
214   DESTINATION bin
215   COMPONENT dev)
217 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_parse
218   DESTINATION bin
219   COMPONENT dev)
221 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_single_compile
222   DESTINATION bin
223   COMPONENT dev)