rename function; hide more cross-compile details in functions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c704578..fe5e182 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -226,15 +226,16 @@ add_subdirectory(build_tools/third_party/vulkan_extensionlayer EXCLUDE_FROM_ALL) if(CMAKE_CROSSCOMPILING) - iree_build_host_executable(flatc BUILDONLY) + iree_declare_host_excutable(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) + iree_get_executable_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 + COMMENT "Installing host flatc..." ) endif()
diff --git a/build_tools/cmake/flatbuffer_cc_library.cmake b/build_tools/cmake/flatbuffer_cc_library.cmake index 71219b9..d3ffd5e 100644 --- a/build_tools/cmake/flatbuffer_cc_library.cmake +++ b/build_tools/cmake/flatbuffer_cc_library.cmake
@@ -106,7 +106,7 @@ ) if(CMAKE_CROSSCOMPILING) - iree_get_host_exectuable_path(flatc _FLATC_PATH) + # Additionally depend on the flatc binary to drive compiling it. add_dependencies("${_NAME}_gen" iree_host_flatc) endif()
diff --git a/build_tools/cmake/iree_bytecode_module.cmake b/build_tools/cmake/iree_bytecode_module.cmake index fa79ecf..8003b7d 100644 --- a/build_tools/cmake/iree_bytecode_module.cmake +++ b/build_tools/cmake/iree_bytecode_module.cmake
@@ -59,12 +59,7 @@ set(_TRANSLATE_TOOL "iree-translate") endif() - 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() + iree_get_executable_path(${_TRANSLATE_TOOL} _TRANSLATE_TOOL_EXECUTABLE) set(_ARGS "${_FLAGS}") list(APPEND _ARGS "${CMAKE_CURRENT_SOURCE_DIR}/${_RULE_SRC}")
diff --git a/build_tools/cmake/iree_cc_binary.cmake b/build_tools/cmake/iree_cc_binary.cmake index 211b809..d7384aa 100644 --- a/build_tools/cmake/iree_cc_binary.cmake +++ b/build_tools/cmake/iree_cc_binary.cmake
@@ -71,6 +71,10 @@ endif() if(_RULE_HOSTONLY AND CMAKE_CROSSCOMPILING) + # The binary is marked as host only. We need to declare the rules for + # generating them under host configuration so cross-compiling towards + # target we can still have this binary. + iree_declare_host_excutable(_RULE_NAME) return() endif()
diff --git a/build_tools/cmake/iree_cc_embed_data.cmake b/build_tools/cmake/iree_cc_embed_data.cmake index 7852dc5..40fd0c0 100644 --- a/build_tools/cmake/iree_cc_embed_data.cmake +++ b/build_tools/cmake/iree_cc_embed_data.cmake
@@ -79,12 +79,7 @@ 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() + iree_get_executable_path(generate_cc_embed_data _EXE_PATH) add_custom_command( OUTPUT "${_RULE_H_FILE_OUTPUT}" "${_RULE_CC_FILE_OUTPUT}"
diff --git a/build_tools/cmake/iree_copts.cmake b/build_tools/cmake/iree_copts.cmake index fbc40e7..f66a7c9 100644 --- a/build_tools/cmake/iree_copts.cmake +++ b/build_tools/cmake/iree_copts.cmake
@@ -143,12 +143,10 @@ ${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include ) -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() +set(MLIR_TABLEGEN_EXE mlir-tblgen) +# iree-tblgen is not defined using the add_tablegen mechanism as other TableGen +# tools in LLVM. +iree_get_executable_path(iree-tblgen IREE_TABLEGEN_EXE) #------------------------------------------------------------------------------- # Third party: tensorflow
diff --git a/build_tools/cmake/iree_cross_compile.cmake b/build_tools/cmake/iree_cross_compile.cmake index 8f7d9fa..5bed987 100644 --- a/build_tools/cmake/iree_cross_compile.cmake +++ b/build_tools/cmake/iree_cross_compile.cmake
@@ -130,18 +130,6 @@ 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() - # iree_host_install # # Defines custom commands and targets for installing the given `target`. The @@ -160,7 +148,7 @@ set(prefix_option -DCMAKE_INSTALL_PREFIX="${_RULE_PREFIX}") endif() - iree_get_host_exectuable_path(${target} output_path) + iree_get_executable_path(${target} output_path) add_custom_command( OUTPUT ${output_path} @@ -174,7 +162,7 @@ add_custom_target(iree_host_install_${target} DEPENDS ${output_path}) endfunction() -# iree_build_host_executable +# iree_declare_host_excutable # # Generates custom commands and targets for building and installing a tool on # host for cross-compilation. @@ -183,10 +171,10 @@ # - target: the target to build on host. # - BUILDONLY: only generates commands for building the target. # - DEPENDS: any additional dependencies for the target. -function(iree_build_host_executable target) +function(iree_declare_host_excutable target) cmake_parse_arguments(_RULE "BUILDONLY" "" "DEPENDS" ${ARGN}) - iree_get_host_exectuable_path(${target} output_path) + iree_get_executable_path(${target} output_path) iree_get_build_command(${target} ${IREE_HOST_BINARY_ROOT} build_cmd)
diff --git a/build_tools/cmake/iree_macros.cmake b/build_tools/cmake/iree_macros.cmake index 4929146..9fa6697 100644 --- a/build_tools/cmake/iree_macros.cmake +++ b/build_tools/cmake/iree_macros.cmake
@@ -72,6 +72,28 @@ set(${PACKAGE_DIR} ${_PACKAGE_DIR} PARENT_SCOPE) endfunction() +# iree_get_executable_path +# +# Gets the path to an executable in a cross-compilation-aware way. This is +# meant to be used for binaries that are used to generate source files and +# can only be built on host. +# +# Paramters: +# - target: the target to build on host. +# - output_path_var: variable name for receiving the path to the built target. +function(iree_get_executable_path target output_path_var) + if(CMAKE_CROSSCOMPILING) + # The target is defined in the CMake invocation for host. We don't have + # access to the target; relying on the path here. + set(output_path "${IREE_HOST_BINARY_ROOT}/bin/${target}") + set(${output_path_var} "${output_path}" PARENT_SCOPE) + else() + # The target is defined in this CMake invocation. We can query the location + # directly from CMake. + set(${output_path_var} "$<TARGET_FILE:${target}>" PARENT_SCOPE) + endif() +endfunction() + #------------------------------------------------------------------------------- # select()-like Evaluation #-------------------------------------------------------------------------------
diff --git a/build_tools/embed_data/CMakeLists.txt b/build_tools/embed_data/CMakeLists.txt index 3f9410e..4efad40 100644 --- a/build_tools/embed_data/CMakeLists.txt +++ b/build_tools/embed_data/CMakeLists.txt
@@ -13,19 +13,19 @@ # limitations under the License. if(CMAKE_CROSSCOMPILING) - iree_build_host_executable(generate_cc_embed_data) + iree_declare_host_excutable(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) + 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) -target_link_libraries(generate_cc_embed_data - absl::flags - absl::flags_parse - absl::strings - absl::time -) -install(TARGETS generate_cc_embed_data - COMPONENT generate_cc_embed_data - RUNTIME DESTINATION bin) + target_link_libraries(generate_cc_embed_data + absl::flags + absl::flags_parse + 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 00c9c6e..c881b4c 100644 --- a/iree/tools/CMakeLists.txt +++ b/iree/tools/CMakeLists.txt
@@ -104,10 +104,6 @@ ) endif() -if(CMAKE_CROSSCOMPILING) - iree_build_host_executable(iree-tblgen) -endif() - if(${IREE_BUILD_COMPILER}) iree_cc_library( NAME @@ -388,12 +384,6 @@ 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