[cmake] Set up cross compilation for IREE
This commit adds cross compilation support to IREE's CMake build
system. This requires a few non-trival changes due to how IREE
structures the code.
In IREE we auto-generate many C++ source code files during build
process. Notably we use flatc to generate FlatBuffer include files
from schemas and tablegen to generate many other compiler source
files. And we even use iree-translate to compile models into IREE
binary modules for testing... These binaries must be first be
compiled on the host and then we can later use them to generate
code for compiling towards the target architecture.
This commit adds a iree_cross_compile.cmake file for a bunch of
utilities for cross-compilation. If cross compilation mode is
detected, we invoke CMake another time under another directory
and feed in the configurations for host to compile the autogen
tools first. The CMake invocation needs to track and drive the
host compilation though; this is mainly done via file dependencies
and custom commands. For the target compilation, we wire up the
dependency there.
Tested the following command and it worked:
```shell
mkdir build-android
cd build-android
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DANDROID_ABI="arm64-v8a" -DANDROID_PLATFORM=android-24 \
-DIREE_BUILD_SAMPLES=OFF -DIREE_BUILD_COMPILER=OFF \
-DIREE_BUILD_TESTS=OFF -DIREE_HOST_C_COMPILER=`which clang` \
-DIREE_HOST_CXX_COMPILER=`which clang++` -GNinja
ninja
```
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 04a3ac8..6ae4d17 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,8 @@
set(IREE_IDE_FOLDER IREE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+# NOTE: new options added here should also be added to iree_cross_compile.cmake.
+
option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF)
option(IREE_ENABLE_LLVM "Enables LLVM dependencies." ON)
@@ -59,7 +61,7 @@
endif()
#-------------------------------------------------------------------------------
-# IREE-specific CMake configuration
+# Targets and Backends Configuration
#-------------------------------------------------------------------------------
# List of all HAL drivers to be built by default:
@@ -111,13 +113,46 @@
set(IREE_TARGET_BACKEND_${uppercase_backend} ON CACHE BOOL "" FORCE)
endforeach()
-
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/
${CMAKE_CURRENT_LIST_DIR}/bindings/python/build_tools/cmake/
${CMAKE_CURRENT_LIST_DIR}/third_party/abseil-cpp/absl/copts/
)
+#-------------------------------------------------------------------------------
+# Cross compiling configuration
+#-------------------------------------------------------------------------------
+
+if(CMAKE_CROSSCOMPILING)
+ message(STATUS "Detected cross compilation mode, configuring IREE on host...")
+
+ # C/C++ compilers for host compilation.
+ # Note: we need to explicitly set this because IREE does not work well with
+ # GCC at the moment: https://github.com/google/iree/issues/1269
+ set(IREE_HOST_C_COMPILER "$ENV{IREE_HOST_C_COMPILER}" CACHE FILEPATH "C compiler for host compilation")
+ set(IREE_HOST_CXX_COMPILER "$ENV{IREE_HOST_CXX_COMPILER}" CACHE FILEPATH "C++ compiler for host compilation")
+
+ # Master configuration for the binary directory containing all artifacts
+ # compiled for host.
+ set(IREE_HOST_BINARY_ROOT "${CMAKE_CURRENT_BINARY_DIR}/host")
+
+ set(IREE_HOST_BUILD_COMPILER ON) # For iree-translate
+ set(IREE_HOST_ENABLE_LLVM ON) # For iree-tblgen
+
+ # Set the host build directory for LLVM to our directory. Otherwise it will
+ # follow its own convention.
+ set(LLVM_NATIVE_BUILD "${IREE_HOST_BINARY_ROOT}/third_party/llvm-project/llvm")
+
+ include(iree_cross_compile)
+
+ # Use another CMake invocation to configure a build for host.
+ iree_create_configuration(HOST)
+endif()
+
+#-------------------------------------------------------------------------------
+# IREE-specific CMake configuration
+#-------------------------------------------------------------------------------
+
include(iree_macros)
include(iree_copts)
include(iree_cc_binary)
@@ -190,6 +225,19 @@
add_subdirectory(build_tools/third_party/renderdoc_api EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/vulkan_extensionlayer EXCLUDE_FROM_ALL)
+if(CMAKE_CROSSCOMPILING)
+ iree_build_host_executable(flatc BUILDONLY)
+ # Set the FLATBUFFERS_FLATC_EXECUTABLE. It controls where to find the flatc
+ # binary in BuildFlatBuffers().
+ iree_get_host_exectuable_path(flatc FLATBUFFERS_FLATC_EXECUTABLE)
+ # Add a custom target to copy the flatc to the binary directory.
+ add_custom_target(iree_host_flatc
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different
+ "${IREE_HOST_BINARY_ROOT}/third_party/flatbuffers/flatc" "${IREE_HOST_BINARY_ROOT}/bin"
+ DEPENDS iree_host_build_flatc
+ )
+endif()
+
if(${IREE_ENABLE_LLVM})
# If CMAKE_BUILD_TYPE is FastBuild, set to Debug for llvm
set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
diff --git a/build_tools/cmake/flatbuffer_cc_library.cmake b/build_tools/cmake/flatbuffer_cc_library.cmake
index 6ad2995..71219b9 100644
--- a/build_tools/cmake/flatbuffer_cc_library.cmake
+++ b/build_tools/cmake/flatbuffer_cc_library.cmake
@@ -105,6 +105,11 @@
"" # copy_text_schemas_dir
)
+ if(CMAKE_CROSSCOMPILING)
+ iree_get_host_exectuable_path(flatc _FLATC_PATH)
+ add_dependencies("${_NAME}_gen" iree_host_flatc)
+ endif()
+
add_library(${_NAME} INTERFACE)
add_dependencies(${_NAME} ${_NAME}_gen)
target_include_directories(${_NAME}
diff --git a/build_tools/cmake/iree_bytecode_module.cmake b/build_tools/cmake/iree_bytecode_module.cmake
index dc1d67f..fa79ecf 100644
--- a/build_tools/cmake/iree_bytecode_module.cmake
+++ b/build_tools/cmake/iree_bytecode_module.cmake
@@ -56,22 +56,38 @@
if(DEFINED _RULE_TRANSLATE_TOOL)
set(_TRANSLATE_TOOL ${_RULE_TRANSLATE_TOOL})
else()
- set(_TRANSLATE_TOOL "iree_tools_iree-translate")
+ set(_TRANSLATE_TOOL "iree-translate")
endif()
- # Resolve the executable binary path from the target name.
- set(_TRANSLATE_TOOL_EXECUTABLE $<TARGET_FILE:${_TRANSLATE_TOOL}>)
+ if (CMAKE_CROSSCOMPILING)
+ iree_get_host_exectuable_path(${_TRANSLATE_TOOL} _TRANSLATE_TOOL_EXECUTABLE)
+ else()
+ # Resolve the executable binary path from the target name.
+ set(_TRANSLATE_TOOL_EXECUTABLE $<TARGET_FILE:${_TRANSLATE_TOOL}>)
+ endif()
set(_ARGS "${_FLAGS}")
list(APPEND _ARGS "${CMAKE_CURRENT_SOURCE_DIR}/${_RULE_SRC}")
list(APPEND _ARGS "-o")
list(APPEND _ARGS "${_RULE_NAME}.module")
- add_custom_command(
- OUTPUT "${_RULE_NAME}.module"
- COMMAND ${_TRANSLATE_TOOL_EXECUTABLE} ${_ARGS}
- DEPENDS ${_TRANSLATE_TOOL}
- )
+ if (CMAKE_CROSSCOMPILING)
+ # For cross compilation, we don't have a target for the translation tool
+ # to depend on: it is in another build root from a different CMake
+ # invocation. But we have a custom command for generating the translation
+ # tool for host. Depend on the file instead.
+ add_custom_command(
+ OUTPUT "${_RULE_NAME}.module"
+ COMMAND ${_TRANSLATE_TOOL_EXECUTABLE} ${_ARGS}
+ DEPENDS ${_TRANSLATE_TOOL_EXECUTABLE}
+ )
+ else()
+ add_custom_command(
+ OUTPUT "${_RULE_NAME}.module"
+ COMMAND ${_TRANSLATE_TOOL_EXECUTABLE} ${_ARGS}
+ DEPENDS ${_TRANSLATE_TOOL}
+ )
+ endif()
if(_RULE_TESTONLY)
set(_TESTONLY_ARG "TESTONLY")
diff --git a/build_tools/cmake/iree_cc_binary.cmake b/build_tools/cmake/iree_cc_binary.cmake
index b8e2a8e..211b809 100644
--- a/build_tools/cmake/iree_cc_binary.cmake
+++ b/build_tools/cmake/iree_cc_binary.cmake
@@ -30,6 +30,8 @@
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
+# TESTONLY: for testing; won't compile when tests are disabled
+# HOSTONLY: host only; compile using host toolchain when cross-compiling
#
# Note:
# By default, iree_cc_binary will always create a binary named iree_${NAME}.
@@ -58,7 +60,7 @@
function(iree_cc_binary)
cmake_parse_arguments(
_RULE
- "TESTONLY"
+ "HOSTONLY;TESTONLY"
"NAME;OUT"
"SRCS;COPTS;DEFINES;LINKOPTS;DATA;DEPS"
${ARGN}
@@ -68,6 +70,10 @@
return()
endif()
+ if(_RULE_HOSTONLY AND CMAKE_CROSSCOMPILING)
+ return()
+ endif()
+
# Prefix the library with the package name, so we get: iree_package_name
iree_package_name(_PACKAGE_NAME)
set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
@@ -126,6 +132,11 @@
# Track target and deps, use in iree_complete_binary_link_options() later.
set_property(GLOBAL APPEND PROPERTY _IREE_CC_BINARY_NAMES "${_NAME}")
set_property(TARGET ${_NAME} PROPERTY DIRECT_DEPS ${_RULE_DEPS})
+
+ install(TARGETS ${_NAME}
+ RENAME ${_RULE_NAME}
+ COMPONENT ${_RULE_NAME}
+ RUNTIME DESTINATION bin)
endfunction()
# Lists all transitive dependencies of DIRECT_DEPS in TRANSITIVE_DEPS.
diff --git a/build_tools/cmake/iree_cc_embed_data.cmake b/build_tools/cmake/iree_cc_embed_data.cmake
index d3644ed..7852dc5 100644
--- a/build_tools/cmake/iree_cc_embed_data.cmake
+++ b/build_tools/cmake/iree_cc_embed_data.cmake
@@ -79,10 +79,17 @@
list(APPEND _ARGS "${SRC}")
endforeach(SRC)
+ if (CMAKE_CROSSCOMPILING)
+ iree_get_host_exectuable_path(generate_cc_embed_data _EXE_PATH)
+ else()
+ # Resolve the executable binary path from the target name.
+ set(_EXE_PATH $<TARGET_FILE:generate_cc_embed_data>)
+ endif()
+
add_custom_command(
OUTPUT "${_RULE_H_FILE_OUTPUT}" "${_RULE_CC_FILE_OUTPUT}"
- COMMAND generate_cc_embed_data ${_ARGS}
- DEPENDS generate_cc_embed_data ${_RULE_SRCS} ${_RULE_GENERATED_SRCS}
+ COMMAND ${_EXE_PATH} ${_ARGS}
+ DEPENDS ${_EXE_PATH} ${_RULE_SRCS} ${_RULE_GENERATED_SRCS}
)
if(_RULE_TESTONLY)
diff --git a/build_tools/cmake/iree_copts.cmake b/build_tools/cmake/iree_copts.cmake
index 29eac45..fbc40e7 100644
--- a/build_tools/cmake/iree_copts.cmake
+++ b/build_tools/cmake/iree_copts.cmake
@@ -85,13 +85,20 @@
#-------------------------------------------------------------------------------
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" FORCE)
-set(FLATBUFFERS_INSTALL OFF CACHE BOOL "" FORCE)
-set(FLATBUFFERS_BUILD_FLATC ON CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_GRPCTEST OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_INCLUDE_DIRS
"${PROJECT_SOURCE_DIR}/third_party/flatbuffers/include/"
)
+
+if(CMAKE_CROSSCOMPILING)
+ set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" FORCE)
+ set(FLATBUFFERS_INSTALL OFF CACHE BOOL "" FORCE)
+else()
+ set(FLATBUFFERS_BUILD_FLATC ON CACHE BOOL "" FORCE)
+ set(FLATBUFFERS_INSTALL ON CACHE BOOL "" FORCE)
+endif()
+
iree_select_compiler_opts(FLATBUFFERS_COPTS
CLANG
# Flatbuffers has a bunch of incorrect documentation annotations.
@@ -136,8 +143,12 @@
${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include
)
-set(MLIR_TABLEGEN_EXE mlir-tblgen)
-set(IREE_TABLEGEN_EXE iree-tblgen)
+if(CMAKE_CROSSCOMPILING)
+ iree_get_host_exectuable_path(iree-tblgen IREE_TABLEGEN_EXE)
+else()
+ set(MLIR_TABLEGEN_EXE mlir-tblgen)
+ set(IREE_TABLEGEN_EXE iree-tblgen)
+endif()
#-------------------------------------------------------------------------------
# Third party: tensorflow
diff --git a/build_tools/cmake/iree_cross_compile.cmake b/build_tools/cmake/iree_cross_compile.cmake
new file mode 100644
index 0000000..40f3324
--- /dev/null
+++ b/build_tools/cmake/iree_cross_compile.cmake
@@ -0,0 +1,200 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# iree_to_bool
+#
+# Sets `variable` to `ON` if `value` is true and `OFF` otherwise.
+function(iree_to_bool variable value)
+ if(value)
+ set(${variable} "ON" PARENT_SCOPE)
+ else()
+ set(${variable} "OFF" PARENT_SCOPE)
+ endif()
+endfunction()
+
+# iree_create_configuration
+#
+# Creates custom commands and targets for an IREE configuration.
+#
+# Environment variables:
+# - IREE_<config_name>_BINARY_ROOT: the root directory for containing IREE build
+# artifacts for the given `config_name`. If not specified in caller, this is
+# set to a directory named as `config_name` under the current CMake binary
+# directory.
+# - IREE_<config_name>_C_COMPILER: C compiler for the given `config_name`.
+# This must be definedd by the caller.
+# - IREE_<config_name>_CXX_COMPILER: C++ compiler for the given `config_name`.
+# This must be definedd by the caller.
+# - IREE_<config_name>_<option>: switch for the given `option` specifically for
+# `config_name`. If missing, default to OFF for bool options; default to
+# IREE_<option> for non-bool variables.
+function(iree_create_configuration config_name)
+ # Set IREE_${config_name}_BINARY_ROOT if missing.
+ if(NOT DEFINED IREE_${config_name}_BINARY_ROOT)
+ set(IREE_${config_name}_BINARY_ROOT "${CMAKE_CURRENT_BINARY_DIR}/${config_name}")
+ set(IREE_${config_name}_BINARY_ROOT ${IREE_${config_name}_BINARY_ROOT} PARENT_SCOPE)
+ message(STATUS "Setting ${config_name} build directory to ${IREE_${config_name}_BINARY_ROOT}")
+ endif()
+
+ set(config_binary_root ${IREE_${config_name}_BINARY_ROOT})
+
+ set(config_c_compiler ${IREE_${config_name}_C_COMPILER})
+ set(config_cxx_compiler ${IREE_${config_name}_CXX_COMPILER})
+
+ # Check the compilers are specified in the caller.
+ if("${config_c_compiler}" STREQUAL "")
+ message(FATAL_ERROR "Must define IREE_${config_name}_C_COMPILER for ${config_name} build")
+ endif()
+ if("${config_cxx_compiler}" STREQUAL "")
+ message(FATAL_ERROR "Must define IREE_${config_name}_CXX_COMPILER for ${config_name} build")
+ endif()
+
+ add_custom_command(OUTPUT ${config_binary_root}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${config_binary_root}
+ COMMENT "Creating ${config_binary_root}...")
+
+ # Give it a custom target so we can drive the generation manually
+ # when useful.
+ add_custom_target(iree_prepare_${config_name}_dir DEPENDS ${config_binary_root})
+
+ iree_to_bool(config_enable_runtime_tracing "${IREE_${config_name}_ENABLE_RUNTIME_TRACING}")
+ iree_to_bool(config_enable_llvm "${IREE_${config_name}_ENABLE_LLVM}")
+ iree_to_bool(config_build_compiler "${IREE_${config_name}_BUILD_COMPILER}")
+ iree_to_bool(config_build_tests "${IREE_${config_name}_BUILD_TESTS}")
+ iree_to_bool(config_build_docs "${IREE_${config_name}_BUILD_DOCS}")
+ iree_to_bool(config_build_samples "${IREE_${config_name}_BUILD_SAMPLES}")
+ iree_to_bool(config_build_debugger "${IREE_${config_name}_BUILD_DEBUGGER}")
+ iree_to_bool(config_build_python_bindings "${IREE_${config_name}_BUILD_PYTHON_BINDINGS}")
+ iree_to_bool(config_build_experimental "${IREE_${config_name}_BUILD_EXPERIMENTAL}")
+
+ # Escape semicolons in the targets list so that CMake doesn't expand them to
+ # spaces.
+ string(REPLACE ";" "$<SEMICOLON>" config_hal_drivers_to_build "${IREE_HAL_DRIVERS_TO_BUILD}")
+ string(REPLACE ";" "$<SEMICOLON>" config_compiler_targets_to_build "${IREE_TARGET_BACKENDS_TO_BUILD}")
+
+ add_custom_command(OUTPUT ${IREE_${config_name}_BINARY_ROOT}/CMakeCache.txt
+ COMMAND "${CMAKE_COMMAND}" "${PROJECT_SOURCE_DIR}" -G "${CMAKE_GENERATOR}"
+ -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
+ -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
+ -DCMAKE_C_COMPILER="${config_c_compiler}"
+ -DCMAKE_CXX_COMPILER="${config_cxx_compiler}"
+ -DIREE_ENABLE_RUNTIME_TRACING=${config_enable_runtime_tracing}
+ -DIREE_ENABLE_LLVM=${config_enable_llvm}
+ -DIREE_BUILD_COMPILER=${config_build_compiler}
+ -DIREE_BUILD_TESTS=${config_build_tests}
+ -DIREE_BUILD_DOCS=${config_build_docs}
+ -DIREE_BUILD_SAMPLES=${config_build_samples}
+ -DIREE_BUILD_DEBUGGER=${config_build_debugger}
+ -DIREE_BUILD_PYTHON_BINDINGS=${config_build_python_bindings}
+ -DIREE_BUILD_EXPERIMENTAL=${config_build_experimental}
+ -DIREE_HAL_DRIVERS_TO_BUILD="${config_hal_drivers_to_build}"
+ -DIREE_TARGET_BACKENDS_TO_BUILD="${config_compiler_targets_to_build}"
+ WORKING_DIRECTORY ${config_binary_root}
+ DEPENDS iree_prepare_${config_name}_dir
+ COMMENT "Configuring IREE for ${config_name} build...")
+
+ add_custom_target(iree_configure_${config_name} DEPENDS ${config_binary_root}/CMakeCache.txt)
+endfunction()
+
+# iree_get_build_command
+#
+# Gets the CMake build command for the given `target`.
+#
+# Parameters:
+# - target: the target to build on host.
+# - bin_dir: root binary directory containing CMakeCache.txt.
+# - cmd_var: variable name for receiving the build command.
+function(iree_get_build_command target bin_dir cmd_var)
+ cmake_parse_arguments(_RULE "" "CONFIG" "" ${ARGN})
+ if(NOT _RULE_CONFIG)
+ set(_RULE_CONFIG "$<CONFIG>")
+ endif()
+ if (CMAKE_GENERATOR MATCHES "Make")
+ # Use special command for Makefiles to support parallelism.
+ set(${cmd_var} "$(MAKE)" "-C" "${bin_dir}" "${target}" PARENT_SCOPE)
+ else()
+ set(${cmd_var} "${CMAKE_COMMAND}" --build ${bin_dir} --target ${target} --config ${_RULE_CONFIG} PARENT_SCOPE)
+ endif()
+endfunction()
+
+# iree_get_host_executable_path
+#
+# Gets the path to a host executable.
+#
+# Paramters:
+# - target: the target to build on host.
+# - output_path_var: variable name for receiving the path to the built target.
+function(iree_get_host_exectuable_path target output_path_var)
+ set(output_path "${IREE_HOST_BINARY_ROOT}/bin/${target}")
+ set(${output_path_var} "${output_path}" PARENT_SCOPE)
+endfunction()
+
+function(iree_host_install target)
+ cmake_parse_arguments(_RULE "" "COMPONENT;PREFIX" "DEPENDS" ${ARGN})
+ if(_RULE_COMPONENT)
+ set(component_option -DCMAKE_INSTALL_COMPONENT="${_RULE_COMPONENT}")
+ endif()
+ if(_RULE_PREFIX)
+ set(prefix_option -DCMAKE_INSTALL_PREFIX="${_RULE_PREFIX}")
+ endif()
+
+ iree_get_host_exectuable_path(${target} output_path)
+
+ add_custom_command(
+ OUTPUT ${output_path}
+ DEPENDS ${_RULE_DEPENDS}
+ COMMAND "${CMAKE_COMMAND}" ${component_option} ${prefix_option}
+ -P "${IREE_HOST_BINARY_ROOT}/cmake_install.cmake"
+ USES_TERMINAL)
+
+ # Give it a custom target so we can drive the generation manually
+ # when useful.
+ add_custom_target(iree_host_install_${target} DEPENDS ${output_path})
+endfunction()
+
+# iree_build_host_executable
+#
+# Builds and installs a tool on host for cross-compilation.
+#
+# Parameters:
+# - target: the target to build on host.
+# - BUILDONLY: only build the target.
+# - DEPENDS: any additional dependencies for the target.
+function(iree_build_host_executable target)
+ cmake_parse_arguments(_RULE "BUILDONLY" "" "DEPENDS" ${ARGN})
+
+ iree_get_host_exectuable_path(${target} output_path)
+
+ iree_get_build_command(${target} ${IREE_HOST_BINARY_ROOT} build_cmd)
+
+ add_custom_target(iree_host_build_${target}
+ COMMAND ${build_cmd}
+ DEPENDS iree_configure_HOST ${_RULE_DEPENDS}
+ WORKING_DIRECTORY "${IREE_HOST_BINARY_ROOT}"
+ COMMENT "Building host ${target}..."
+ USES_TERMINAL)
+
+ if(_RULE_BUILDONLY)
+ return()
+ endif()
+
+ iree_host_install(${target}
+ COMPONENT ${target}
+ PREFIX ${IREE_HOST_BINARY_ROOT}
+ DEPENDS iree_host_build_${target})
+
+ # Give it a custom target so we can drive the generation manually
+ # when useful.
+ add_custom_target(iree_host_${target} DEPENDS "${output_path}")
+endfunction()
diff --git a/build_tools/embed_data/CMakeLists.txt b/build_tools/embed_data/CMakeLists.txt
index ec07934..3f9410e 100644
--- a/build_tools/embed_data/CMakeLists.txt
+++ b/build_tools/embed_data/CMakeLists.txt
@@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-add_executable(generate_cc_embed_data)
+if(CMAKE_CROSSCOMPILING)
+ iree_build_host_executable(generate_cc_embed_data)
+else()
+ add_executable(generate_cc_embed_data)
target_sources(generate_cc_embed_data PRIVATE generate_cc_embed_data.cc)
set_target_properties(generate_cc_embed_data PROPERTIES OUTPUT_NAME generate_cc_embed_data)
@@ -22,3 +25,7 @@
absl::strings
absl::time
)
+install(TARGETS generate_cc_embed_data
+ COMPONENT generate_cc_embed_data
+ RUNTIME DESTINATION bin)
+endif()
diff --git a/iree/tools/CMakeLists.txt b/iree/tools/CMakeLists.txt
index 8660532..00c9c6e 100644
--- a/iree/tools/CMakeLists.txt
+++ b/iree/tools/CMakeLists.txt
@@ -100,9 +100,14 @@
iree::compiler::Dialect::VM::Tools
LINKOPTS
"-lpthread"
+ HOSTONLY
)
endif()
+if(CMAKE_CROSSCOMPILING)
+ iree_build_host_executable(iree-tblgen)
+endif()
+
if(${IREE_BUILD_COMPILER})
iree_cc_library(
NAME
@@ -258,6 +263,7 @@
iree-opt
DEPS
::iree_opt_main
+ HOSTONLY
)
iree_cc_binary(
@@ -301,6 +307,7 @@
iree::vm::bytecode_module
iree::vm::value
${IREE_HAL_DRIVER_MODULES}
+ HOSTONLY
)
iree_cc_library(
@@ -335,6 +342,7 @@
iree-translate
DEPS
::iree_translate_main
+ HOSTONLY
)
endif()
@@ -380,6 +388,12 @@
iree::vm::variant_list
)
+if(CMAKE_CROSSCOMPILING)
+ iree_build_host_executable(iree-opt)
+ iree_build_host_executable(iree-run-mlir)
+ iree_build_host_executable(iree-translate)
+endif()
+
if(${IREE_ENABLE_LLVM})
add_custom_target(IreeFileCheck ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/IreeFileCheck.sh IreeFileCheck