Skip to content

Commit

Permalink
Add missing cmake dependency for iree-tblgen (iree-org#14235)
Browse files Browse the repository at this point in the history
Co-authored-by: Stella Laurenzo <[email protected]>
  • Loading branch information
ftynse and stellaraccident authored Jun 29, 2023
1 parent 0b21a6c commit 7b28a41
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
11 changes: 9 additions & 2 deletions build_tools/cmake/iree_cc_binary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ include(CMakeParseArguments)
# SRCS: List of source files for the binary
# DATA: List of other targets and files required for this binary
# DEPS: List of other libraries to be linked in to the binary targets
# DISABLE_LLVM_LINK_LLVM_DYLIB: Disables linking against the libLLVM.so dynamic
# library, even if the build is configured to do so. This must be used with
# care as it can only contain dependencies and be used by binaries that also
# so disable it (either in upstream LLVM or locally). In practice, it is used
# for LLVM dependency chains that must always result in static-linked tools.
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
Expand Down Expand Up @@ -49,7 +54,7 @@ include(CMakeParseArguments)
function(iree_cc_binary)
cmake_parse_arguments(
_RULE
"EXCLUDE_FROM_ALL;HOSTONLY;TESTONLY;SETUP_INSTALL_RPATH"
"EXCLUDE_FROM_ALL;HOSTONLY;TESTONLY;SETUP_INSTALL_RPATH;DISABLE_LLVM_LINK_LLVM_DYLIB"
"NAME"
"SRCS;COPTS;DEFINES;LINKOPTS;DATA;DEPS"
${ARGN}
Expand Down Expand Up @@ -129,7 +134,9 @@ function(iree_cc_binary)

# Replace dependencies passed by ::name with iree::package::name
list(TRANSFORM _RULE_DEPS REPLACE "^::" "${_PACKAGE_NS}::")
iree_filter_cc_deps(_RULE_DEPS)
if(NOT _RULE_DISABLE_LLVM_LINK_LLVM_DYLIB)
iree_redirect_llvm_dylib_deps(_RULE_DEPS)
endif()

# Implicit deps.
if(IREE_IMPLICIT_DEFS_CC_DEPS)
Expand Down
21 changes: 14 additions & 7 deletions build_tools/cmake/iree_cc_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

include(CMakeParseArguments)

# iree_filter_cc_deps(DEPS_VAR)
# iree_redirect_llvm_dylib_deps(DEPS_VAR)
#
# Filters a list of CC dependencies, making alterations as needed.
# At present, this is used to redirect LLVM libraries to the libLLVM.so
# dynamic library, when LLVM has been configured to link against it.
# Filters a list of CC dependencies, making alterations as needed to
# to redirect LLVM libraries to the libLLVM.so dynamic library, when LLVM
# has been configured to link against it.
# This is necessary to preserve the one-definition rule in the build graph
# in a consistent way as to how AddLLVM.cmake does it.
# Note that this only really works if libLLVM.so was configured to contain
# "all" components. If this ever becomes unworkable, we may need to port the
# component naming logic and selectively choose when to divert.
function(iree_filter_cc_deps DEPS_VAR)
function(iree_redirect_llvm_dylib_deps DEPS_VAR)
set(_deps ${${DEPS_VAR}})
set(_new_deps)
set(_modified FALSE)
Expand Down Expand Up @@ -47,6 +47,11 @@ endfunction()
# SRCS: List of source files for the library
# DATA: List of other targets and files required for this binary
# DEPS: List of other libraries to be linked in to the binary targets
# DISABLE_LLVM_LINK_LLVM_DYLIB: Disables linking against the libLLVM.so dynamic
# library, even if the build is configured to do so. This must be used with
# care as it can only contain dependencies and be used by binaries that also
# so disable it (either in upstream LLVM or locally). In practice, it is used
# for LLVM dependency chains that must always result in static-linked tools.
# COPTS: List of private compile options
# DEFINES: List of public defines
# INCLUDES: Include directories to add to dependencies
Expand Down Expand Up @@ -90,7 +95,7 @@ endfunction()
function(iree_cc_library)
cmake_parse_arguments(
_RULE
"PUBLIC;TESTONLY;SHARED"
"PUBLIC;TESTONLY;SHARED;DISABLE_LLVM_LINK_LLVM_DYLIB"
"PACKAGE;NAME;WINDOWS_DEF_FILE"
"HDRS;TEXTUAL_HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DATA;DEPS;INCLUDES"
${ARGN}
Expand All @@ -117,7 +122,9 @@ function(iree_cc_library)

# Replace dependencies passed by ::name with iree::package::name
list(TRANSFORM _RULE_DEPS REPLACE "^::" "${_PACKAGE_NS}::")
iree_filter_cc_deps(_RULE_DEPS)
if(NOT _RULE_DISABLE_LLVM_LINK_LLVM_DYLIB)
iree_redirect_llvm_dylib_deps(_RULE_DEPS)
endif()

# Check if this is a header-only library.
# Note that as of February 2019, many popular OS's (for example, Ubuntu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ add_library(IREELLVMCPUTargetDeps INTERFACE)
function(_add_optional_llvm_target_deps target)
# Key off of the CodeGen target and then include the rest.
# Note that for LLVM DYLIB builds, we just key off of the presence of the
# static CodeGen target and iree_filter_cc_deps will replace it with the
# dylib accordingly (it is just a check to see if we have compiled in
# static CodeGen target and iree_redirect_llvm_dylib_deps will replace it
# with the dylib accordingly (it is just a check to see if we have compiled in
# support for the target).
if(TARGET "LLVM${target}CodeGen")
set(_target_deps
Expand All @@ -156,7 +156,7 @@ function(_add_optional_llvm_target_deps target)
"LLVM${target}Desc"
"LLVM${target}Info"
)
iree_filter_cc_deps(_target_deps)
iree_redirect_llvm_dylib_deps(_target_deps)
target_link_libraries(IREELLVMCPUTargetDeps INTERFACE ${_target_deps})
endif()
endfunction()
Expand Down
2 changes: 2 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ if(IREE_BUILD_COMPILER)
"${IREE_SOURCE_DIR}/compiler/src/iree/compiler/Dialect/VM/Tools/VMOpEncoderGen.cpp"
"${IREE_SOURCE_DIR}/compiler/src/iree/compiler/Dialect/VM/Tools/VMOpTableGen.cpp"
DEPS
LLVMSupport
MLIRTblgenLib
HOSTONLY
DISABLE_LLVM_LINK_LLVM_DYLIB
)

iree_cc_binary(
Expand Down

0 comments on commit 7b28a41

Please sign in to comment.