Skip to content

Commit 15c306f

Browse files
Build functioning dev packages for IREECompiler and IREERuntime. (iree-org#16008)
With this patch, external projects can do: ``` find_package(IREECompiler) find_package(IREERuntime) ``` and access our targets by adding either the build or install tree `lib/cmake/IREE` to the CMake package search path. There are still some ergonomic issues that need to be addressed going forward: * cpuinfo breaks the one downstream I am testing this against. We really should just finish killing that, so I am setting -DIREE_ENABLE_CPUINFO=OFF in the dist package. * We are not yet re-establishing the pretty `iree::runtime:...` aliases. The underscore versions are available (`iree_runtime_...`). * I want to further isolate the remaining bundled deps (yaml and flatcc). * New convenience install targets do not have full dependency information. Need to do an `all` build first. As part of this, I did some longstanding cleanups: * Normalized the install component namespace. Defined `IREECMakeExports`, `IREEDevLibraries-Compiler`, `IREEDevLibraries-Runtime`, `IREERuntimeLibraries-Compiler`, `IREEBundledLibraries`, `IREETools-Runtime`. * Added convenience `iree-install-*` targets. Each includes a `-stripped` variant as well. * Moved MLIRInterop.h to the bindings/c directory where it should have been all along and straightened the deps. * Install the mlir-c headers to support libIREECompiler.so dev. * Added the "busybox" tool binaries to the install distribution (iree-lld, etc). * Stopped bundling upstream `lld` and `clang` by default because they bloat the size. `lld` is now bundled as `iree-lld` just like in the Python packages. Clang and llvm-link can be gotten by installing the new `IREETools-CompilerExtra` component if folks need those. Note that this only installs public headers and libraries needed to build against the compiler and runtime. Installing private things needed to develop parts of the system are out of scope.
1 parent b0e8f3c commit 15c306f

37 files changed

+593
-74
lines changed

CMakeLists.txt

+109-4
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ include(iree_cc_binary)
544544
include(iree_cc_library)
545545
include(iree_cc_test)
546546
include(iree_import_binary)
547+
include(iree_install_support)
547548
include(iree_external_cmake_options)
548549
include(iree_tablegen_library)
549550
include(iree_tablegen_doc)
@@ -854,10 +855,16 @@ else()
854855
# Also add a library that can be depended on to get LLVM includes setup
855856
# properly. bazel_to_cmake targets this for some header only pseudo deps.
856857
add_library(IREELLVMIncludeSetup INTERFACE)
857-
target_include_directories(IREELLVMIncludeSetup INTERFACE
858-
${LLVM_INCLUDE_DIRS}
859-
${MLIR_INCLUDE_DIRS}
860-
${LLD_INCLUDE_DIRS}
858+
foreach(_d ${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS} ${LLD_INCLUDE_DIRS})
859+
# BUILD_INTERFACE only works one at a time.
860+
target_include_directories(IREELLVMIncludeSetup INTERFACE
861+
$<BUILD_INTERFACE:${_d}>
862+
)
863+
endforeach()
864+
iree_install_targets(
865+
TARGETS IREELLVMIncludeSetup
866+
COMPONENT IREEPublicLibraries-Compiler
867+
EXPORT_SET Compiler
861868
)
862869

863870
# Splice the includes setup into base LLVM libraries so that using them
@@ -895,24 +902,49 @@ endif()
895902

896903
#-------------------------------------------------------------------------------
897904
# Other dependencies
905+
# By default we bundle a number of dependencies needed to build the project.
906+
# When bundled like this, they are installed into the IREEBundledLibraries
907+
# component and exported to their subsystem which requires them (if a static
908+
# dep from the public API): "Runtime" or "Compiler".
909+
#
910+
# Some deps have a usable CMake build, and we add_subdirectory these, manually
911+
# using iree_install_targets to include them in our installation. Others require
912+
# custom CMake and these are in the build_tools/third_party directory.
913+
#
914+
# TODO: We should have a mode that purely uses find_package for OS friendly
915+
# packaging/externalizing deps.
898916
#-------------------------------------------------------------------------------
899917

900918
include(external_cc_library)
901919
include(flatbuffer_c_library)
902920

921+
# libyaml
903922
add_subdirectory(build_tools/third_party/libyaml EXCLUDE_FROM_ALL)
923+
904924
add_subdirectory(build_tools/third_party/llvm-project EXCLUDE_FROM_ALL)
905925
add_subdirectory(build_tools/third_party/tracy_client EXCLUDE_FROM_ALL)
906926

907927
iree_set_googletest_cmake_options()
908928
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
909929

910930
if(IREE_ENABLE_THREADING)
931+
# Benchmark.
911932
iree_set_benchmark_cmake_options()
912933
add_subdirectory(third_party/benchmark EXCLUDE_FROM_ALL)
934+
iree_install_targets(
935+
TARGETS benchmark
936+
COMPONENT IREEBundledLibraries
937+
EXPORT_SET Runtime
938+
)
939+
913940
if(IREE_ENABLE_CPUINFO)
914941
iree_set_cpuinfo_cmake_options()
915942
add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL)
943+
iree_install_targets(
944+
TARGETS cpuinfo
945+
COMPONENT IREEBundledLibraries
946+
EXPORT_SET Runtime
947+
)
916948
endif()
917949
endif()
918950

@@ -925,6 +957,11 @@ endif()
925957

926958
if(IREE_HAL_DRIVER_VULKAN)
927959
add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL)
960+
iree_install_targets(
961+
TARGETS Vulkan-Headers
962+
COMPONENT IREEBundledLibraries
963+
EXPORT_SET Runtime
964+
)
928965
endif()
929966

930967
if(IREE_BUILD_COMPILER)
@@ -1056,3 +1093,71 @@ endif()
10561093
if(IREE_BUILD_TESTS)
10571094
iree_create_ctest_customization()
10581095
endif()
1096+
1097+
#-------------------------------------------------------------------------------
1098+
# Install/exports
1099+
#-------------------------------------------------------------------------------
1100+
1101+
add_subdirectory(build_tools/cmake ${IREE_BINARY_DIR}/lib/cmake/IREE)
1102+
1103+
# See runtime/src/CMakeLists.txt
1104+
iree_generate_export_targets(
1105+
EXPORT_SET Runtime
1106+
)
1107+
1108+
# See compiler/bindings/c/CMakeLists.txt
1109+
iree_generate_export_targets(
1110+
EXPORT_SET Compiler
1111+
)
1112+
1113+
# Convenience installation targets.
1114+
iree_add_install_target(NAME iree-install-dev-libraries)
1115+
iree_add_install_target(NAME iree-install-runtime-libraries)
1116+
iree_add_install_target(NAME iree-install-tools)
1117+
1118+
iree_add_install_target(
1119+
NAME iree-install-cmake-exports
1120+
COMPONENT IREECMakeExports
1121+
ADD_TO iree-install-dev-libraries
1122+
)
1123+
1124+
iree_add_install_target(
1125+
NAME iree-install-dev-libraries-runtime
1126+
COMPONENT IREEDevLibraries-Runtime
1127+
ADD_TO iree-install-dev-libraries
1128+
)
1129+
1130+
iree_add_install_target(
1131+
NAME iree-install-bundled-libraries
1132+
COMPONENT IREEBundledLibraries
1133+
ADD_TO iree-install-dev-libraries-runtime
1134+
)
1135+
1136+
if(IREE_BUILD_COMPILER)
1137+
iree_add_install_target(
1138+
NAME iree-install-dev-libraries-compiler
1139+
COMPONENT IREEDevLibraries-Compiler
1140+
ADD_TO iree-install-dev-libraries
1141+
)
1142+
1143+
iree_add_install_target(
1144+
NAME iree-install-tools-compiler
1145+
COMPONENT IREETools-Compiler
1146+
ADD_TO iree-install-tools
1147+
)
1148+
1149+
iree_add_install_target(
1150+
NAME iree-install-runtime-libraries-compiler
1151+
COMPONENT IREERuntimeLibraries-Compiler
1152+
ADD_TO
1153+
iree-install-runtime-libraries
1154+
iree-install-tools-compiler
1155+
iree-install-dev-libraries-compiler
1156+
)
1157+
endif()
1158+
1159+
iree_add_install_target(
1160+
NAME iree-install-tools-runtime
1161+
COMPONENT IREETools-Runtime
1162+
ADD_TO iree-install-tools
1163+
)

build_tools/cmake/CMakeLists.txt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2023 The IREE Authors
2+
#
3+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
set(_cmake_installdir "${CMAKE_INSTALL_LIBDIR}/cmake/IREE")
8+
9+
if(IREE_BUILD_COMPILER)
10+
configure_file(
11+
${CMAKE_CURRENT_SOURCE_DIR}/IREECompilerConfig.cmake.in
12+
${CMAKE_CURRENT_BINARY_DIR}/IREECompilerConfig.cmake
13+
@ONLY
14+
)
15+
install(FILES
16+
${CMAKE_CURRENT_BINARY_DIR}/IREECompilerConfig.cmake
17+
DESTINATION ${_cmake_installdir}
18+
COMPONENT IREECMakeExports
19+
)
20+
endif()
21+
22+
configure_file(
23+
${CMAKE_CURRENT_SOURCE_DIR}/IREERuntimeConfig.cmake.in
24+
${CMAKE_CURRENT_BINARY_DIR}/IREERuntimeConfig.cmake
25+
@ONLY
26+
)
27+
install(FILES
28+
${CMAKE_CURRENT_BINARY_DIR}/IREERuntimeConfig.cmake
29+
DESTINATION ${_cmake_installdir}
30+
COMPONENT IREECMakeExports
31+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This allows users to call find_package(IREECompiler) and access our targets.
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/IREETargets-Compiler.cmake")
4+
5+
# TODO: Define some properties to reference all libraries and config options.
6+
# TODO: Iterate over all exported libraries and re-alias them.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This allows users to call find_package(IREERuntime) and access our targets.
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/IREETargets-Runtime.cmake")
4+
5+
# TODO: Define some properties to reference all libraries and config options.
6+
# TODO: Iterate over all exported libraries and re-alias them.

build_tools/cmake/external_cc_library.cmake

+7-3
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,17 @@ function(external_cc_library)
169169
)
170170
endif()
171171

172-
add_library(${_RULE_PACKAGE}::${_RULE_NAME} ALIAS ${_NAME})
172+
iree_install_targets(
173+
TARGETS ${_NAME}
174+
HDRS ${_RULE_HDRS}
175+
)
176+
177+
iree_add_alias_library(${_RULE_PACKAGE}::${_RULE_NAME} ${_NAME})
173178
# If the library name matches the final component of the package then treat it
174179
# as a default. For example, 'foo::bar' library 'bar' would end up as
175180
# 'foo::bar'.
176181
string(REGEX REPLACE "^.*::" "" _PACKAGE_DIR ${_RULE_PACKAGE})
177182
if(${_PACKAGE_DIR} STREQUAL ${_RULE_NAME})
178-
179-
add_library(${_RULE_PACKAGE} ALIAS ${_NAME})
183+
iree_add_alias_library(${_RULE_PACKAGE} ${_NAME})
180184
endif()
181185
endfunction()

build_tools/cmake/flatbuffer_c_library.cmake

+6-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function(flatbuffer_c_library)
116116
add_dependencies(${_NAME} ${_GEN_TARGET})
117117
target_include_directories(${_NAME} SYSTEM
118118
INTERFACE
119-
${CMAKE_CURRENT_BINARY_DIR}
119+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
120120
)
121121
target_link_libraries(${_NAME}
122122
INTERFACE
@@ -127,10 +127,13 @@ function(flatbuffer_c_library)
127127
"-I${IREE_ROOT_DIR}/third_party/flatcc/include/"
128128
"-I${IREE_ROOT_DIR}/third_party/flatcc/include/flatcc/reflection/"
129129
)
130-
130+
iree_install_targets(
131+
TARGETS ${_NAME}
132+
)
133+
131134
# Alias the iree_package_name library to iree::package::name.
132135
# This lets us more clearly map to Bazel and makes it possible to
133136
# disambiguate the underscores in paths vs. the separators.
134137
iree_package_ns(_PACKAGE_NS)
135-
add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})
138+
iree_add_alias_library(${_PACKAGE_NS}::${_RULE_NAME} ${_NAME})
136139
endfunction()

build_tools/cmake/iree_cc_binary.cmake

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ include(CMakeParseArguments)
2727
# HOSTONLY: host only; compile using host toolchain when cross-compiling
2828
# SETUP_INSTALL_RPATH: Sets an install RPATH which assumes the standard
2929
# directory layout (to be used if linking against installed shared libs).
30-
#
30+
# INSTALL_COMPONENT: CMake install component (Defaults to "IREETool-${_RULE_NAME}").
3131
# Note:
3232
# iree_cc_binary will create a binary called ${PACKAGE_NAME}_${NAME}, e.g.
3333
# iree_base_foo with an alias to ${PACKAGE_NS}::${NAME}.
@@ -55,7 +55,7 @@ function(iree_cc_binary)
5555
cmake_parse_arguments(
5656
_RULE
5757
"EXCLUDE_FROM_ALL;HOSTONLY;TESTONLY;SETUP_INSTALL_RPATH;DISABLE_LLVM_LINK_LLVM_DYLIB"
58-
"NAME"
58+
"NAME;INSTALL_COMPONENT"
5959
"SRCS;COPTS;DEFINES;LINKOPTS;DATA;DEPS"
6060
${ARGN}
6161
)
@@ -155,18 +155,23 @@ function(iree_cc_binary)
155155
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${IREE_CXX_STANDARD})
156156
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
157157

158+
set(_INSTALL_COMPONENT "${_RULE_INSTALL_COMPONENT}")
159+
if(NOT _INSTALL_COMPONENT)
160+
set(_INSTALL_COMPONENT "IREETool-${_RULE_NAME}")
161+
endif()
162+
158163
if(_RULE_EXCLUDE_FROM_ALL)
159164
set_property(TARGET ${_NAME} PROPERTY EXCLUDE_FROM_ALL ON)
160165
install(TARGETS ${_NAME}
161166
RENAME ${_RULE_NAME}
162-
COMPONENT ${_RULE_NAME}
167+
COMPONENT ${_INSTALL_COMPONENT}
163168
RUNTIME DESTINATION bin
164169
BUNDLE DESTINATION bin
165170
EXCLUDE_FROM_ALL)
166171
else()
167172
install(TARGETS ${_NAME}
168173
RENAME ${_RULE_NAME}
169-
COMPONENT ${_RULE_NAME}
174+
COMPONENT ${_INSTALL_COMPONENT}
170175
RUNTIME DESTINATION bin
171176
BUNDLE DESTINATION bin)
172177
endif()

build_tools/cmake/iree_cc_library.cmake

+15-4
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,28 @@ function(iree_cc_library)
292292
)
293293
endif()
294294

295+
if(NOT _RULE_TESTONLY)
296+
iree_install_targets(
297+
TARGETS ${_NAME}
298+
HDRS ${_RULE_HDRS} ${_RULE_TEXTUAL_HDRS}
299+
)
300+
endif()
301+
295302
# Alias the iree_package_name library to iree::package::name.
296303
# This lets us more clearly map to Bazel and makes it possible to
297304
# disambiguate the underscores in paths vs. the separators.
298305
if(_DEBUG_IREE_PACKAGE_NAME)
299306
message(STATUS " + alias ${_PACKAGE_NS}::${_RULE_NAME}")
300307
endif()
301-
add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})
308+
iree_add_alias_library(${_PACKAGE_NS}::${_RULE_NAME} ${_NAME})
302309

303310
if(NOT "${_PACKAGE_NS}" STREQUAL "")
304311
# If the library name matches the final component of the package then treat
305312
# it as a default. For example, foo/bar/ library 'bar' would end up as
306313
# 'foo::bar'.
307314
iree_package_dir(_PACKAGE_DIR)
308315
if("${_RULE_NAME}" STREQUAL "${_PACKAGE_DIR}")
309-
add_library(${_PACKAGE_NS} ALIAS ${_NAME})
316+
iree_add_alias_library(${_PACKAGE_NS} ${_NAME})
310317
endif()
311318
endif()
312319
endfunction()
@@ -428,17 +435,21 @@ function(iree_cc_unified_library)
428435
$<TARGET_PROPERTY:${_RULE_ROOT},INTERFACE_LINK_LIBRARIES>
429436
)
430437

438+
iree_install_targets(
439+
TARGETS ${_NAME}
440+
)
441+
431442
# Alias the iree_package_name library to iree::package::name.
432443
# This lets us more clearly map to Bazel and makes it possible to
433444
# disambiguate the underscores in paths vs. the separators.
434-
add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})
445+
iree_add_alias_library(${_PACKAGE_NS}::${_RULE_NAME} ${_NAME})
435446

436447
# If the library name matches the final component of the package then treat
437448
# it as a default. For example, foo/bar/ library 'bar' would end up as
438449
# 'foo::bar'.
439450
iree_package_dir(_PACKAGE_DIR)
440451
if(${_RULE_NAME} STREQUAL ${_PACKAGE_DIR})
441-
add_library(${_PACKAGE_NS} ALIAS ${_NAME})
452+
iree_add_alias_library(${_PACKAGE_NS} ${_NAME})
442453
endif()
443454
endfunction()
444455

0 commit comments

Comments
 (0)