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)
8 message(STATUS "Skipping hack")
12 message(STATUS "Building hack")
14 if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
15 set(HACK_ONLY_BUILD TRUE)
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")
27 "${TP_DIR}/CMakeLists.txt missing. Try updating your submodule with:\n"
29 " git submodule update --init --recursive\n"
37 if (HACK_ONLY_BUILD AND NOT LZ4_FOUND)
38 add_subdirectory("${TP_DIR}/lz4" "${TP_DIR}/lz4")
41 if (HACK_ONLY_BUILD AND NOT OCAML_FOUND)
42 add_subdirectory("${TP_DIR}/ocaml" "${TP_DIR}/ocaml")
45 if (HACK_ONLY_BUILD AND NOT PC_SQLITE3_FOUND)
46 add_subdirectory("${TP_DIR}/libsqlite3" "${TP_DIR}/libsqlite3")
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)
56 # Allows '#include "hphp/path/to/library/"' paths to start from hphp
57 # project directory which is consistent with fbmake's include paths.
60 list(APPEND extra_include_paths ${HPHP_HOME})
62 list(APPEND extra_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/../..)
65 foreach(lib ${LIBELF_INCLUDE_DIRS})
66 list(APPEND extra_include_paths ${lib})
69 list(APPEND extra_cc_flags -DHAVE_ELF_GETSHDRSTRNDX)
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})
80 list(APPEND extra_include_paths ${LZ4_INCLUDE_DIR})
81 get_filename_component(pth ${LZ4_LIBRARY} PATH)
82 list(APPEND extra_lib_paths ${pth})
84 list(APPEND extra_include_paths "${TP_DIR}/lz4/src/lib")
85 list(APPEND extra_lib_paths "${TP_BUILD_DIR}/lz4")
87 list(APPEND extra_native_libraries "lz4")
90 list(APPEND extra_include_paths ${LIBSQLITE3_INCLUDE_DIR})
91 get_filename_component(pth ${LIBSQLITE3_LIBRARY} PATH)
92 list(APPEND extra_lib_paths ${pth})
94 list(APPEND extra_include_paths "${TP_DIR}/libsqlite3")
95 list(APPEND extra_lib_paths "${TP_BUILD_DIR}/libsqlite3")
97 list(APPEND extra_native_libraries "sqlite3")
99 # Xcode/Ninja generators undefined MAKE
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)
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)
138 # if the system does not have lz4, make sure that the one in public_tl
140 add_dependencies(hack lz4)
141 add_dependencies(hack_test lz4)
144 if(NOT PC_SQLITE3_FOUND)
145 # if the system does not have sqlite3, make sure that the one in public_tl
147 add_dependencies(hack sqlite3)
148 add_dependencies(hack_test sqlite3)
151 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_client
155 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_server
159 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hackfmt
163 install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/hh_format