Skip to content

Commit 24a3664

Browse files
authored
Always include LLVM CMake modules. (#2572)
These LLVM CMake modules used to be unconditionally included, but #2430 changed that to only conditionally including them in the standalone and embedded builds, leaving out the external-project build. That broke integration in https://github.com/iree-org/iree where Stablehlo is an external project. [Error log here](https://gist.github.com/bjacob/17f86fb5f07007e06b94f3a9347747a1). These are linking errors when building with Clang or GCC, with unresolved symbols for `typeinfo` for various types, referenced from Stablehlo symbols. `typeinfo` is a RTTI feature, and all LLVM-derived projects normally disable RTTI, which is why these symbols are not defined, and why that is normally not a problem. What changed with #2430 was that suddenly, the disabling of RTTI was itself disabled in our external build of Stablehlo. [Here is the code](https://github.com/llvm/llvm-project/blob/09ba83be0ac178851e3c9c9c8fefddbdd4d8353f/llvm/cmake/modules/AddLLVM.cmake#L63-L64) that is responsible for disabling RTTI. It was not kicking in anymore, because `LLVM_COMPILER_IS_GCC_COMPATIBLE` was not defined. It is normally defined by this `include` [just above](https://github.com/llvm/llvm-project/blob/09ba83be0ac178851e3c9c9c8fefddbdd4d8353f/llvm/cmake/modules/AddLLVM.cmake#L5) in that file. But as of #2430, the `include(AddLLVM)` itself was no longer done in the Stablehlo project, instead the Stablehlo external build was relying on `include(AddLLVM)` to have been done in the parent project, which it was. The problem was that while the parent-project `include(AddLLVM)` did define all the functions provided by that module, the CMake variable definitions such as `LLVM_COMPILER_IS_GCC_COMPATIBLE` were made on the parent project and were not visible to the child project. Summary of the above: in their current shape, LLVM CMake modules such as `AddLLVM` (and `AddMLIR`, which Stablehlo uses, and which itself relies on `AddLLVM`) must be included by any child project that uses them, even if the parent project already included them. Signed-off-by: Benoit Jacob <[email protected]>
1 parent 139e61f commit 24a3664

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,18 @@ if(STABLEHLO_STANDALONE_BUILD)
109109
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
110110
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
111111
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
112-
113-
include(TableGen)
114-
include(AddLLVM)
115-
include(AddMLIR)
116112
include(HandleLLVMOptions)
117113
endif()
118114

119115
if(STABLEHLO_BUILD_EMBEDDED)
120116
message(STATUS "Building StableHLO embedded in another project")
121-
include(TableGen)
122-
include(AddLLVM)
123-
include(AddMLIR)
124117
include(HandleLLVMOptions)
125118
endif()
126119

120+
include(TableGen)
121+
include(AddLLVM)
122+
include(AddMLIR)
123+
127124
# Add the CMake modules specific to StableHLO
128125
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
129126

0 commit comments

Comments
 (0)