Skip to content

Commit

Permalink
[Polly][CMake] Fix exports (#122123)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic authored Jan 20, 2025
1 parent 4d21096 commit 2d6d476
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,9 @@ function(add_llvm_pass_plugin name)
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_STATIC_EXTENSIONS ${name})
elseif(NOT ARG_NO_MODULE)
add_llvm_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
add_llvm_library(${name} MODULE NO_EXPORT ${ARG_UNPARSED_ARGUMENTS})
else()
add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS})
add_llvm_library(${name} OBJECT NO_EXPORT ${ARG_UNPARSED_ARGUMENTS})
endif()
message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")

Expand Down
8 changes: 8 additions & 0 deletions polly/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
)
endif()

# add_llvm_pass_plugin() already declares the option, but we need access to
# it earlier than that.
set(link_into_tools_default OFF)
if (LLVM_TOOL_POLLY_BUILD)
set(link_into_tools_default ON)
endif()
option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ${link_into_tools_default})

add_definitions( -D_GNU_SOURCE )

add_subdirectory(docs)
Expand Down
10 changes: 8 additions & 2 deletions polly/cmake/polly_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ macro(add_polly_library name)
llvm_config(${name} ${LLVM_LINK_COMPONENTS})
endif( LLVM_LINK_COMPONENTS )
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
set(exports)
if (LLVM_POLLY_LINK_INTO_TOOLS)
set(exports EXPORT LLVMExports)
endif()
install(TARGETS ${name}
COMPONENT ${name}
EXPORT LLVMExports
${exports}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
add_llvm_install_targets(install-${name}
COMPONENT ${name})
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
if (LLVM_POLLY_LINK_INTO_TOOLS)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endif()
endmacro(add_polly_library)

macro(add_polly_loadable_module name)
Expand Down

0 comments on commit 2d6d476

Please sign in to comment.