CMake: defines and uses macro add_llvm_definitions for keeping track
[opencl/llvm.git] / cmake / modules / CrossCompileLLVM.cmake
index 0377c056142834de7ccac6c8979fec1bcb0884a9..f638d67a30d1a0458004e1b38cf125450afa28d4 100644 (file)
@@ -1,6 +1,26 @@
-# TODO: Build a native tblgen when cross-compiling, if the user\r
-# didn't set LLVM_TABLEGEN. Then, remove this check:\r
-if( CMAKE_CROSSCOMPILING AND ${LLVM_TABLEGEN} STREQUAL "tblgen" )\r
-  message(FATAL_ERROR\r
-    "Set LLVM_TABLEGEN to the full route to a native tblgen executable")\r
+\r
+if( ${LLVM_TABLEGEN} STREQUAL "tblgen" )\r
+  set(CX_NATIVE_TG_DIR "${CMAKE_BINARY_DIR}/native")\r
+  set(LLVM_TABLEGEN "${CX_NATIVE_TG_DIR}/bin/tblgen")\r
+\r
+  add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR}\r
+    COMMAND ${CMAKE_COMMAND} -E make_directory ${CX_NATIVE_TG_DIR}\r
+    COMMENT "Creating ${CX_NATIVE_TG_DIR}...")\r
+\r
+  add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR}/CMakeCache.txt\r
+    COMMAND ${CMAKE_COMMAND} -UMAKE_TOOLCHAIN_FILE -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}\r
+    WORKING_DIRECTORY ${CX_NATIVE_TG_DIR}\r
+    DEPENDS ${CX_NATIVE_TG_DIR}\r
+    COMMENT "Configuring native TableGen...")\r
+\r
+  add_custom_command(OUTPUT ${LLVM_TABLEGEN}\r
+    COMMAND ${CMAKE_BUILD_TOOL}\r
+    DEPENDS ${CX_NATIVE_TG_DIR}/CMakeCache.txt\r
+    WORKING_DIRECTORY ${CX_NATIVE_TG_DIR}/utils/TableGen\r
+    COMMENT "Building native TableGen...")\r
+  add_custom_target(NativeTableGen DEPENDS ${LLVM_TABLEGEN})\r
+\r
+  add_dependencies(tblgen NativeTableGen)\r
+\r
+  set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CX_NATIVE_TG_DIR})\r
 endif()\r