[Polly][CMake] Make PollyConfig.cmake relocatable like other projects'

This builds on D116521 to add this functionality to Polly without more copy-pasted code.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D116555
This commit is contained in:
John Ericson 2022-01-03 21:09:33 +00:00
parent 072e2a7c67
commit e68215c0c1
3 changed files with 32 additions and 19 deletions

View File

@ -48,10 +48,15 @@ endif ()
set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
# Add path for custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
endif()
# Make sure that our source directory is on the current cmake module path so that
# we can include cmake files from this directory.
list(INSERT CMAKE_MODULE_PATH 0
"${POLLY_SOURCE_DIR}/cmake"
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
)
include("polly_macros")
@ -68,9 +73,6 @@ else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
endif ()
# Add path for custom modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)

View File

@ -1,5 +1,7 @@
# Keep this in sync with llvm/cmake/CMakeLists.txt!
include(FindPrefixFromConfig)
set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
set(POLLY_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
if (CMAKE_CONFIGURATION_TYPES)
@ -46,6 +48,7 @@ endif()")
endif()
# Generate PollyConfig.cmake for the build tree.
set(POLLY_CONFIG_CODE "")
set(POLLY_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/${POLLY_INSTALL_PACKAGE_DIR}")
set(POLLY_CONFIG_INCLUDE_DIRS
${POLLY_SOURCE_DIR}/include
@ -79,24 +82,31 @@ file(GENERATE
# Generate PollyConfig.cmake for the install tree.
unset(POLLY_EXPORTS)
set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
find_prefix_from_config(POLLY_CONFIG_CODE POLLY_INSTALL_PREFIX "${POLLY_INSTALL_PACKAGE_DIR}")
set(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
set(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
set(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
if (POLLY_BUNDLED_ISL)
set(POLLY_CONFIG_INCLUDE_DIRS
"${POLLY_INSTALL_PREFIX}/include"
"${POLLY_INSTALL_PREFIX}/include/polly"
"\${POLLY_INSTALL_PREFIX}/include"
"\${POLLY_INSTALL_PREFIX}/include/polly"
)
else()
set(POLLY_CONFIG_INCLUDE_DIRS
"${POLLY_INSTALL_PREFIX}/include"
"\${POLLY_INSTALL_PREFIX}/include"
${ISL_INCLUDE_DIRS}
)
endif()
# set locations for imported targets. The path is constructed to be relative to
# the config file
# Set locations for imported targets. The path is constructed to be relative to
# the config file.
#
# Include the config code of PollyConfig.cmake to define POLLY_INSTALL_PREFIX
# anew in case the export file is included alone rather than from that file.
set(POLLY_EXPORTS
"${POLLY_CONFIG_CODE}
")
foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
get_target_property(tgt_type ${tgt} TYPE)
if (tgt_type STREQUAL "EXECUTABLE")
@ -105,13 +115,12 @@ foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
set(tgt_prefix "lib/")
endif()
set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$<TARGET_FILE_NAME:${tgt}>")
file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path})
set(tgt_path "\${POLLY_INSTALL_PREFIX}/${tgt_prefix}$<TARGET_FILE_NAME:${tgt}>")
if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
set(POLLY_EXPORTS
"set_target_properties(${tgt} PROPERTIES
IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> \${CMAKE_CURRENT_LIST_DIR}/${tgt_path})
IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> \"${tgt_path}\")
${POLLY_EXPORTS}")
endif()
endforeach(tgt)

View File

@ -1,5 +1,7 @@
# This file allows users to call find_package(Polly) and pick up our targets.
@POLLY_CONFIG_CODE@
find_package(LLVM REQUIRED CONFIG
HINTS "@POLLY_CONFIG_LLVM_CMAKE_DIR@")