I want to make Halide’s build support cross-compilation.
- Host Halide depends on:
- Host LLVM libraries
- Host LLVM tools:
llvm-asandclang
- Target Halide depends on:
- Host Halide tools
- Host LLVM tools:
llvm-asandclang - Target LLVM libraries
To pass the host Halide tools to target Halide, there’s a simple solution:
- Organize Halide’s tools into a directory that
export()s them into a package called HalideHost. - In the parent directory, check if
CMAKE_CROSSCOMPILINGis set.- If so,
find_package(HalideHost) - Otherwise,
add_subdirectory(tools).
- If so,
- Set
HalideHost_ROOTto the host build directory in the target configure command line.
On the other hand, getting both LLVM host tools and LLVM target libraries is challenging. Calling find_package(LLVM) will always return either one or the other.
My desired solution was to export() the host LLVM tools under the HalideHost:: namespace and use aliases in the host build for consistency. Unfortunately, export() reports a bogus error that it can’t determine the linker language for the imported executable. Setting IMPORTED_LINK_INTERFACE_LANGUAGES to CXX does not resolve this.
My workaround is to use file(GENERATE) to do what I expected export() to do:
file(GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/share/HalideHost/HalideHostConfig.cmake"
CONTENT [[
include(${CMAKE_CURRENT_LIST_DIR}/HalideHost-exports.cmake)
add_executable(HalideHost::llvm-as IMPORTED)
set_target_properties(
HalideHost::llvm-as
PROPERTIES
IMPORTED_LOCATION "$<TARGET_FILE:llvm-as>"
)
]])
Why can’t export() do this, and why would it need to know the linker language for an imported executable?
Moreover, is this a good solution? If not, what should I do instead?