1# Keep this in sync with llvm/cmake/CMakeLists.txt!
2
3set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
4set(POLLY_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
5if (CMAKE_CONFIGURATION_TYPES)
6  set(POLLY_EXPORTS_FILE_NAME "PollyExports-$<LOWER_CASE:$<CONFIG>>.cmake")
7else()
8  # avoid conflicts in the build-tree when changing configuration
9  set(POLLY_EXPORTS_FILE_NAME "PollyExports-all.cmake")
10endif()
11
12set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET})
13if (NOT WIN32 AND LLVM_ENABLE_PIC)
14  # LLVMPolly is a dummy target on Win or if PIC code is disabled.
15  list(APPEND POLLY_CONFIG_EXPORTED_TARGETS LLVMPolly)
16endif()
17if (POLLY_ENABLE_GPGPU_CODEGEN)
18  list(APPEND POLLY_CONFIG_EXPORTED_TARGETS PollyPPCG)
19endif()
20
21# Get the target type for every exported target
22foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
23  get_target_property(tgt_type ${tgt} TYPE)
24  string(REPLACE "_LIBRARY" "" tgt_type ${tgt_type})
25  set(POLLY_CONFIG_TARGET_${tgt}_TYPE ${tgt_type})
26endforeach()
27
28set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
29set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
30
31# generate the import code for bundled/undbundled libisl versions
32if (NOT POLLY_BUNDLED_ISL)
33  get_property(incl TARGET ISL PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
34  get_property(lib TARGET ISL PROPERTY INTERFACE_LINK_LIBRARIES)
35  get_property(opt TARGET ISL PROPERTY INTERFACE_COMPILE_OPTIONS)
36  set(ISL_CONFIG_CODE "
37add_library(ISL INTERFACE IMPORTED)
38set_property(TARGET ISL APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${incl})
39set_property(TARGET ISL APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${lib})
40set_property(TARGET ISL APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${opt})")
41else()
42  set(ISL_CONFIG_CODE "
43if (NOT TARGET PollyISL)
44  add_library(PollyISL ${POLLY_CONFIG_TARGET_PollyISL_TYPE} IMPORTED)
45endif()")
46endif()
47
48# Generate PollyConfig.cmake for the build tree.
49set(POLLY_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/${POLLY_INSTALL_PACKAGE_DIR}")
50set(POLLY_CONFIG_INCLUDE_DIRS
51  ${POLLY_SOURCE_DIR}/include
52  ${ISL_INCLUDE_DIRS}
53  ${POLLY_BINARY_DIR}/include
54  )
55set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_BINARY_DIR}/lib")
56
57# set locations for imported targets
58foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
59  get_target_property(tgt_type ${tgt} TYPE)
60  if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
61    set(POLLY_EXPORTS
62      "set_target_properties(${tgt} PROPERTIES
63              IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE:${tgt}>)
64${POLLY_EXPORTS}")
65  endif()
66endforeach(tgt)
67
68# PollyConfig holds the target definitions and general settings, PollyExports
69# the imported locations
70configure_file(
71  ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
72  ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake
73  @ONLY)
74
75file(GENERATE
76  OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME}
77  CONTENT "${POLLY_EXPORTS}")
78
79
80# Generate PollyConfig.cmake for the install tree.
81unset(POLLY_EXPORTS)
82set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
83set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
84set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
85set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
86if (POLLY_BUNDLED_ISL)
87  set(POLLY_CONFIG_INCLUDE_DIRS
88    "${POLLY_INSTALL_PREFIX}/include"
89    "${POLLY_INSTALL_PREFIX}/include/polly"
90    )
91else()
92  set(POLLY_CONFIG_INCLUDE_DIRS
93    "${POLLY_INSTALL_PREFIX}/include"
94    ${ISL_INCLUDE_DIRS}
95    )
96endif()
97
98# set locations for imported targets. The path is constructed to be relative to
99# the config file
100foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
101  get_target_property(tgt_type ${tgt} TYPE)
102  if (tgt_type STREQUAL "EXECUTABLE")
103    set(tgt_prefix "bin/")
104  else()
105    set(tgt_prefix "lib/")
106  endif()
107
108  set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$<TARGET_FILE_NAME:${tgt}>")
109  file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path})
110
111  if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
112    set(POLLY_EXPORTS
113"set_target_properties(${tgt} PROPERTIES
114        IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> \${CMAKE_CURRENT_LIST_DIR}/${tgt_path})
115${POLLY_EXPORTS}")
116  endif()
117endforeach(tgt)
118
119configure_file(
120  ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
121  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
122  @ONLY)
123file(GENERATE OUTPUT
124  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
125  CONTENT "${POLLY_EXPORTS}")
126
127if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
128  install(
129    FILES
130    "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake"
131    "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}"
132    DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}")
133endif ()
134