mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-26 23:21:11 +00:00
[Cmake] Generate a PollyConfig.cmake.
Generate a PollyConfig.cmake for use with Cmake's find_package in out-of-tree projects. Contributed-by: Philip Pfaffe <philip.pfaffe@gmail.com> Differential Revision: https://reviews.llvm.org/D30495 llvm-svn: 297395
This commit is contained in:
parent
7a0981aa38
commit
a9520b94d5
@ -207,6 +207,7 @@ if (POLLY_GTEST_AVAIL)
|
||||
add_subdirectory(unittests)
|
||||
endif ()
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(cmake)
|
||||
# TODO: docs.
|
||||
|
||||
|
||||
|
128
polly/cmake/CMakeLists.txt
Normal file
128
polly/cmake/CMakeLists.txt
Normal file
@ -0,0 +1,128 @@
|
||||
# Keep this in sync with llvm/cmake/CMakeLists.txt!
|
||||
if (LLVM_INSTALL_ROOT)
|
||||
# this simplifies things down the road, by not requiring to distinguish
|
||||
# between in-tree and out of tree builds
|
||||
set(LLVM_BINARY_DIR ${LLVM_INSTALL_ROOT})
|
||||
endif()
|
||||
|
||||
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)
|
||||
set(POLLY_EXPORTS_FILE_NAME "PollyExports-$<LOWER_CASE:$<CONFIG>>.cmake")
|
||||
else()
|
||||
# avoid conflicts in the build-tree when changing configuration
|
||||
set(POLLY_EXPORTS_FILE_NAME "PollyExports-all.cmake")
|
||||
endif()
|
||||
|
||||
set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET})
|
||||
if (NOT MSVC)
|
||||
# LLVMPolly is a dummy target on Win
|
||||
list(APPEND POLLY_CONFIG_EXPORTED_TARGETS LLVMPolly)
|
||||
endif()
|
||||
if (POLLY_ENABLE_GPGPU_CODEGEN)
|
||||
list(APPEND POLLY_CONFIG_EXPORTED_TARGETS PollyPPCG)
|
||||
endif()
|
||||
|
||||
# Get the target type for every exported target
|
||||
foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
|
||||
get_target_property(tgt_type ${tgt} TYPE)
|
||||
string(REPLACE "_LIBRARY" "" tgt_type ${tgt_type})
|
||||
set(POLLY_CONFIG_TARGET_${tgt}_TYPE ${tgt_type})
|
||||
endforeach()
|
||||
|
||||
set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
|
||||
set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
|
||||
|
||||
# generate the import code for bundled/undbundled libisl versions
|
||||
if (NOT POLLY_BUNDLED_ISL)
|
||||
get_property(incl TARGET ISL PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
get_property(lib TARGET ISL PROPERTY INTERFACE_LINK_LIBRARIES)
|
||||
get_property(opt TARGET ISL PROPERTY INTERFACE_COMPILE_OPTIONS)
|
||||
set(ISL_CONFIG_CODE "
|
||||
add_library(ISL INTERFACE IMPORTED)
|
||||
set_property(TARGET ISL APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${incl})
|
||||
set_property(TARGET ISL APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${lib})
|
||||
set_property(TARGET ISL APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${opt})")
|
||||
else()
|
||||
set(ISL_CONFIG_CODE "
|
||||
if (NOT TARGET PollyISL)
|
||||
add_library(PollyISL ${POLLY_CONFIG_TARGET_PollyISL_TYPE} IMPORTED)
|
||||
endif()")
|
||||
endif()
|
||||
|
||||
# Generate PollyConfig.cmake for the build tree.
|
||||
set(POLLY_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/${POLLY_INSTALL_PACKAGE_DIR}")
|
||||
set(POLLY_CONFIG_INCLUDE_DIRS ${ISL_INCLUDE_DIRS})
|
||||
set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_BINARY_DIR}/lib")
|
||||
|
||||
# set locations for imported targets
|
||||
foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
|
||||
get_target_property(tgt_type ${tgt} TYPE)
|
||||
if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
|
||||
set(POLLY_EXPORTS
|
||||
"set_target_properties(${tgt} PROPERTIES
|
||||
IMPORTED_LOCATION_$<UPPER_CASE:$<CONFIG>> $<TARGET_FILE:${tgt}>)
|
||||
${POLLY_EXPORTS}")
|
||||
endif()
|
||||
endforeach(tgt)
|
||||
|
||||
# PollyConfig holds the target definitions and general settings, PollyExports
|
||||
# the imported locations
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
|
||||
${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake
|
||||
@ONLY)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME}
|
||||
CONTENT "${POLLY_EXPORTS}")
|
||||
|
||||
|
||||
# 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}")
|
||||
if (POLLY_BUNDLED_ISL)
|
||||
set(POLLY_CONFIG_INCLUDE_DIRS "${POLLY_INSTALL_PREFIX}/include/polly")
|
||||
else()
|
||||
set(POLLY_CONFIG_INCLUDE_DIRS ${ISL_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
# set locations for imported targets. The path is constructed to be relative to
|
||||
# the config file
|
||||
foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
|
||||
get_target_property(tgt_type ${tgt} TYPE)
|
||||
if (tgt_type STREQUAL "EXECUTABLE")
|
||||
set(tgt_prefix "bin/")
|
||||
else()
|
||||
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})
|
||||
|
||||
if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
|
||||
set(POLLY_EXPORTS
|
||||
"set_target_properties(${tgt} PROPERTIES
|
||||
IMPORTED_LOCATION_$<UPPER_CASE:$<CONFIG>> \${CMAKE_CURRENT_LIST_DIR}/${tgt_path})
|
||||
${POLLY_EXPORTS}")
|
||||
endif()
|
||||
endforeach(tgt)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
|
||||
@ONLY)
|
||||
file(GENERATE OUTPUT
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
|
||||
CONTENT "${POLLY_EXPORTS}")
|
||||
|
||||
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}"
|
||||
DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}")
|
||||
endif ()
|
41
polly/cmake/PollyConfig.cmake.in
Normal file
41
polly/cmake/PollyConfig.cmake.in
Normal file
@ -0,0 +1,41 @@
|
||||
# This file allows users to call find_package(Polly) and pick up our targets.
|
||||
|
||||
find_package(LLVM REQUIRED CONFIG
|
||||
HINTS "@POLLY_CONFIG_LLVM_CMAKE_DIR@")
|
||||
|
||||
set(Polly_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
set(Polly_BUNDLED_ISL @POLLY_BUNDLED_ISL@)
|
||||
set(Polly_ENABLE_GPGPU_CODEGEN @POLLY_ENABLE_GPGPU_CODEGEN@)
|
||||
|
||||
set(Polly_DEFINITIONS ${LLVM_DEFINITIONS})
|
||||
set(Polly_INCLUDE_DIRS @POLLY_CONFIG_INCLUDE_DIRS@ ${LLVM_INCLUDE_DIRS})
|
||||
set(Polly_LIBRARY_DIRS @POLLY_CONFIG_LIBRARY_DIRS@)
|
||||
set(Polly_EXPORTED_TARGETS @POLLY_CONFIG_EXPORTED_TARGETS@)
|
||||
set(Polly_LIBRARIES ${LLVM_LIBRARIES} ${Polly_EXPORTED_TARGETS})
|
||||
|
||||
# Imported Targets:
|
||||
@ISL_CONFIG_CODE@
|
||||
|
||||
if (Polly_ENABLE_GPGPU_CODEGEN AND NOT TARGET PollyPPCG)
|
||||
add_library(PollyPPCG @POLLY_CONFIG_TARGET_TARGET_PollyPPCG_TYPE@ IMPORTED)
|
||||
set_target_property(TARGET PollyPPCG PROPERTY INTERFACE_LINK_LIBRARIES @ISL_TARGET@)
|
||||
endif()
|
||||
|
||||
if (NOT TARGET Polly)
|
||||
add_library(Polly @POLLY_CONFIG_TARGET_Polly_TYPE@ IMPORTED)
|
||||
set_property(TARGET Polly PROPERTY INTERFACE_LINK_LIBRARIES @ISL_TARGET@)
|
||||
if (Polly_ENABLE_GPGPU_CODEGEN)
|
||||
set_property(TARGET Polly APPEND PROPERTY INTERFACE_LINK_LIBRARIES PollyPPCG)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT TARGET LLVMPolly)
|
||||
add_library(LLVMPolly @POLLY_CONFIG_TARGET_LLVMPolly_TYPE@ IMPORTED)
|
||||
set_property(TARGET LLVMPolly PROPERTY INTERFACE_LINK_LIBRARIES Polly)
|
||||
endif()
|
||||
|
||||
# Exported locations:
|
||||
file(GLOB CONFIG_FILES "${Polly_CMAKE_DIR}/PollyExports-*.cmake")
|
||||
foreach(f ${CONFIG_FILES})
|
||||
include(${f})
|
||||
endforeach()
|
Loading…
Reference in New Issue
Block a user