Skip to content

Commit 2d6d476

Browse files
authored
[Polly][CMake] Fix exports (#122123)
If Polly is built with LLVM_POLLY_LINK_INTO_TOOLS=ON (the default for monorepo builds), then Polly will become a dependency of the LLVMExtensions component, which is part of LLVMExports. As such, all the Polly libraries also have to be part of LLVMExports. However, if Polly is built with LLVM_POLLY_LINK_INTO_TOOLS=OFF, we also end up adding Polly libraries to LLVMExports. This is undesirable, as it adds a hard dependency from llvm on polly. Fix this by only exporting polly libraries from LLVMExports if LLVM_POLLY_LINK_INTO_TOOLS is enabled.
1 parent 4d21096 commit 2d6d476

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,9 @@ function(add_llvm_pass_plugin name)
12201220
endif()
12211221
set_property(GLOBAL APPEND PROPERTY LLVM_STATIC_EXTENSIONS ${name})
12221222
elseif(NOT ARG_NO_MODULE)
1223-
add_llvm_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
1223+
add_llvm_library(${name} MODULE NO_EXPORT ${ARG_UNPARSED_ARGUMENTS})
12241224
else()
1225-
add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS})
1225+
add_llvm_library(${name} OBJECT NO_EXPORT ${ARG_UNPARSED_ARGUMENTS})
12261226
endif()
12271227
message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")
12281228

polly/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
112112
)
113113
endif()
114114

115+
# add_llvm_pass_plugin() already declares the option, but we need access to
116+
# it earlier than that.
117+
set(link_into_tools_default OFF)
118+
if (LLVM_TOOL_POLLY_BUILD)
119+
set(link_into_tools_default ON)
120+
endif()
121+
option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ${link_into_tools_default})
122+
115123
add_definitions( -D_GNU_SOURCE )
116124

117125
add_subdirectory(docs)

polly/cmake/polly_macros.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ macro(add_polly_library name)
3939
llvm_config(${name} ${LLVM_LINK_COMPONENTS})
4040
endif( LLVM_LINK_COMPONENTS )
4141
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
42+
set(exports)
43+
if (LLVM_POLLY_LINK_INTO_TOOLS)
44+
set(exports EXPORT LLVMExports)
45+
endif()
4246
install(TARGETS ${name}
4347
COMPONENT ${name}
44-
EXPORT LLVMExports
48+
${exports}
4549
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
4650
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
4751
add_llvm_install_targets(install-${name}
4852
COMPONENT ${name})
4953
endif()
50-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
54+
if (LLVM_POLLY_LINK_INTO_TOOLS)
55+
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
56+
endif()
5157
endmacro(add_polly_library)
5258

5359
macro(add_polly_loadable_module name)

0 commit comments

Comments
 (0)