1 # Keep this in sync with llvm/cmake/CMakeLists.txt!
3 include(GNUInstallPackageDir)
5 include(FindPrefixFromConfig)
7 set(POLLY_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/polly" CACHE STRING
8 "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
9 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
10 set(polly_cmake_builddir "${POLLY_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
12 set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
13 "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
14 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
15 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
17 if (CMAKE_CONFIGURATION_TYPES)
18 set(POLLY_EXPORTS_FILE_NAME "PollyExports-$<LOWER_CASE:$<CONFIG>>.cmake")
20 # avoid conflicts in the build-tree when changing configuration
21 set(POLLY_EXPORTS_FILE_NAME "PollyExports-all.cmake")
24 set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET})
25 if (NOT WIN32 AND LLVM_ENABLE_PIC)
26 # LLVMPolly is a dummy target on Win or if PIC code is disabled.
27 list(APPEND POLLY_CONFIG_EXPORTED_TARGETS LLVMPolly)
29 if (POLLY_ENABLE_GPGPU_CODEGEN)
30 list(APPEND POLLY_CONFIG_EXPORTED_TARGETS PollyPPCG)
33 # Get the target type for every exported target
34 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
35 get_target_property(tgt_type ${tgt} TYPE)
36 string(REPLACE "_LIBRARY" "" tgt_type ${tgt_type})
37 set(POLLY_CONFIG_TARGET_${tgt}_TYPE ${tgt_type})
40 # generate the import code for bundled/undbundled libisl versions
41 if (NOT POLLY_BUNDLED_ISL)
42 get_property(incl TARGET ISL PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
43 get_property(lib TARGET ISL PROPERTY INTERFACE_LINK_LIBRARIES)
44 get_property(opt TARGET ISL PROPERTY INTERFACE_COMPILE_OPTIONS)
46 add_library(ISL INTERFACE IMPORTED)
47 set_property(TARGET ISL APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${incl})
48 set_property(TARGET ISL APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${lib})
49 set_property(TARGET ISL APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${opt})")
52 if (NOT TARGET PollyISL)
53 add_library(PollyISL ${POLLY_CONFIG_TARGET_PollyISL_TYPE} IMPORTED)
57 # Generate PollyConfig.cmake for the build tree.
58 set(POLLY_CONFIG_CODE "")
59 set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
60 set(POLLY_CONFIG_CMAKE_DIR "${polly_cmake_builddir}")
61 set(POLLY_CONFIG_INCLUDE_DIRS
62 ${POLLY_SOURCE_DIR}/include
64 ${POLLY_BINARY_DIR}/include
66 set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_BINARY_DIR}/lib")
68 # set locations for imported targets
69 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
70 get_target_property(tgt_type ${tgt} TYPE)
71 if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
73 "set_target_properties(${tgt} PROPERTIES
74 IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE:${tgt}>)
79 # PollyConfig holds the target definitions and general settings, PollyExports
80 # the imported locations
82 ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
83 ${polly_cmake_builddir}/PollyConfig.cmake
87 OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME}
88 CONTENT "${POLLY_EXPORTS}")
91 # Generate PollyConfig.cmake for the install tree.
93 find_prefix_from_config(POLLY_CONFIG_CODE POLLY_INSTALL_PREFIX "${POLLY_INSTALL_PACKAGE_DIR}")
94 extend_path(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
95 extend_path(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${POLLY_INSTALL_PACKAGE_DIR}")
96 extend_path(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}" "lib${LLVM_LIBDIR_SUFFIX}")
97 extend_path(base_includedir "\${POLLY_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
98 if (POLLY_BUNDLED_ISL)
99 set(POLLY_CONFIG_INCLUDE_DIRS
101 "${base_includedir}/polly"
104 set(POLLY_CONFIG_INCLUDE_DIRS
110 # Set locations for imported targets. The path is constructed to be relative to
113 # Include the config code of PollyConfig.cmake to define POLLY_INSTALL_PREFIX
114 # anew in case the export file is included alone rather than from that file.
116 "${POLLY_CONFIG_CODE}
119 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
120 get_target_property(tgt_type ${tgt} TYPE)
121 if (tgt_type STREQUAL "EXECUTABLE")
122 set(tgt_prefix "${CMAKE_INSTALL_BINDIR}")
124 set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}")
127 extend_path(tgt_path "\${POLLY_INSTALL_PREFIX}" "${tgt_prefix}/$<TARGET_FILE_NAME:${tgt}>")
129 if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
131 "set_target_properties(${tgt} PROPERTIES
132 IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> \"${tgt_path}\")
138 ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
139 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
142 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
143 CONTENT "${POLLY_EXPORTS}")
145 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
148 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake"
149 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}"
150 DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}")