Fix use after move in type-system.cpp
[hiphop-php.git] / hphp / hack / CMakeLists.txt
blob211d3b62cf26507744bb2e8843ca503466e4a677
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 (HACK_ONLY_BUILD)
19   # Woah - this is special. They're running cmake in the hack directory
20   # itself so we don't have our usual set up.
21   get_filename_component(HPHP_HOME "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
22   set(TP_DIR "${HPHP_HOME}/third-party")
23   set(TP_BUILD_DIR ${TP_DIR})
25   if(NOT EXISTS "${TP_DIR}/CMakeLists.txt")
26     message(FATAL_ERROR
27       "${TP_DIR}/CMakeLists.txt missing. Try updating your submodule with:\n"
28       "    rm -r ${TP_DIR}\n"
29       "    git submodule update --init --recursive\n"
30       )
31   endif()
32 endif()
34 find_package(LZ4)
35 find_package(LibElf)
37 if (HACK_ONLY_BUILD AND NOT LZ4_FOUND)
38   add_subdirectory("${TP_DIR}/lz4" "${TP_DIR}/lz4")
39 endif()
41 if (HACK_ONLY_BUILD AND NOT OCAML_FOUND)
42   add_subdirectory("${TP_DIR}/ocaml" "${TP_DIR}/ocaml")
43 endif()
45 if (HACK_ONLY_BUILD AND NOT PC_SQLITE3_FOUND)
46   add_subdirectory("${TP_DIR}/libsqlite3" "${TP_DIR}/libsqlite3")
47 endif()
49 # This is totally the wrong way to do this, but I am tired of fighting with
50 # build systems and don't really care to make this work the right way. libelf,
51 # lz4 and sqlite3 all we need right now anyways.
52 unset(extra_include_paths)
53 unset(extra_lib_paths)
54 unset(extra_cc_flags)
56 # Allows '#include "hphp/path/to/library/"' paths to start from hphp
57 # project directory  which is consistent with fbmake's include paths.
59 IF(HPHP_HOME)
60   list(APPEND extra_include_paths ${HPHP_HOME})
61 ELSE()
62   list(APPEND extra_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/../..)
63 ENDIF()
65 foreach(lib ${LIBELF_INCLUDE_DIRS})
66   list(APPEND extra_include_paths ${lib})
67 endforeach()
68 if(ELF_GETSHDRSTRNDX)
69   list(APPEND extra_cc_flags -DHAVE_ELF_GETSHDRSTRNDX)
70 endif()
72 list(APPEND extra_cc_flags -pthread)
74 foreach(lib ${LIBELF_LIBRARIES})
75   get_filename_component(pth ${lib} PATH)
76   list(APPEND extra_lib_paths ${pth})
77 endforeach()
79 if(LZ4_FOUND)
80   list(APPEND extra_include_paths ${LZ4_INCLUDE_DIR})
81   get_filename_component(pth ${LZ4_LIBRARY} PATH)
82   list(APPEND extra_lib_paths ${pth})
83 else()
84   list(APPEND extra_include_paths "${TP_DIR}/lz4/src/lib")
85   list(APPEND extra_lib_paths "${TP_BUILD_DIR}/lz4")
86 endif()
87 list(APPEND extra_native_libraries "lz4")
89 if(PC_SQLITE3_FOUND)
90   list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
91   get_filename_component(pth ${LIBSQLITE3_LIBRARY} PATH)
92   list(APPEND extra_lib_paths ${pth})
93 else()
94   list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
95   list(APPEND extra_lib_paths "${TP_BUILD_DIR}/libsqlite3")
96 endif()
97 list(APPEND extra_native_libraries "sqlite3")
99 # Xcode/Ninja generators undefined MAKE
100 if(NOT MAKE)
101   set(MAKE make)
102 endif()
104 add_custom_target(
105   hack
106   ALL
107   COMMAND
108         $(MAKE) EXTRA_INCLUDE_PATHS="${extra_include_paths}"
109         EXTRA_LIB_PATHS="${extra_lib_paths}"
110         EXTRA_CC_FLAGS="${extra_cc_flags}"
111         EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
112         BYTECODE="${EMIT_OCAML_BYTECODE}"
113         OCAML="${OCAML_EXECUTABLE}"
114         OCAMLC="${OCAMLC_EXECUTABLE}"
115         OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
116         OCAMLBUILD_FLAGS="-ocamlc=${OCAMLC_EXECUTABLE},-ocamlopt=${OCAMLOPT_EXECUTABLE}"
117   WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
119 add_dependencies(hack ocaml)
121 add_custom_target(
122   hack_test
123   COMMAND
124         $(MAKE) test EXTRA_INCLUDE_PATHS="${extra_include_paths}"
125         EXTRA_LIB_PATHS="${extra_lib_paths}"
126         EXTRA_CC_FLAGS="${extra_cc_flags}"
127         EXTRA_NATIVE_LIBRARIES="${extra_native_libraries}"
128         BYTECODE="${EMIT_OCAML_BYTECODE}"
129         OCAML="${OCAML_EXECUTABLE}"
130         OCAMLC="${OCAMLC_EXECUTABLE}"
131         OCAMLBUILD="${OCAMLBUILD_EXECUTABLE}"
132         OCAMLBUILD_FLAGS="-ocamlc=${OCAMLC_EXECUTABLE},-ocamlopt=${OCAMLOPT_EXECUTABLE}"
133   WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src"
135 add_dependencies(hack_test ocaml)
137 if(NOT LZ4_FOUND)
138   # if the system does not have lz4, make sure that the one in public_tl
139   # gets built
140   add_dependencies(hack lz4)
141   add_dependencies(hack_test lz4)
142 endif()
144 if(NOT PC_SQLITE3_FOUND)
145   # if the system does not have sqlite3, make sure that the one in public_tl
146   # gets built
147   add_dependencies(hack sqlite3)
148   add_dependencies(hack_test sqlite3)
149 endif()
151 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_client
152   DESTINATION bin
153   COMPONENT dev)
155 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_server
156   DESTINATION bin
157   COMPONENT dev)
159 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hackfmt
160   DESTINATION bin
161   COMPONENT dev)
163 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_format
164   DESTINATION bin
165   COMPONENT dev)