[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / polly / cmake / CMakeLists.txt
blob4c528d562e23b8401be837573ccb6785d05ad985
1 # Keep this in sync with llvm/cmake/CMakeLists.txt!
3 include(GNUInstallPackageDir)
4 include(ExtendPath)
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")
19 else()
20   # avoid conflicts in the build-tree when changing configuration
21   set(POLLY_EXPORTS_FILE_NAME "PollyExports-all.cmake")
22 endif()
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)
28 endif()
29 if (POLLY_ENABLE_GPGPU_CODEGEN)
30   list(APPEND POLLY_CONFIG_EXPORTED_TARGETS PollyPPCG)
31 endif()
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})
38 endforeach()
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)
45   set(ISL_CONFIG_CODE "
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})")
50 else()
51   set(ISL_CONFIG_CODE "
52 if (NOT TARGET PollyISL)
53   add_library(PollyISL ${POLLY_CONFIG_TARGET_PollyISL_TYPE} IMPORTED)
54 endif()")
55 endif()
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
63   ${ISL_INCLUDE_DIRS}
64   ${POLLY_BINARY_DIR}/include
65   )
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")
72     set(POLLY_EXPORTS
73       "set_target_properties(${tgt} PROPERTIES
74               IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE:${tgt}>)
75 ${POLLY_EXPORTS}")
76   endif()
77 endforeach(tgt)
79 # PollyConfig holds the target definitions and general settings, PollyExports
80 # the imported locations
81 configure_file(
82   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
83   ${polly_cmake_builddir}/PollyConfig.cmake
84   @ONLY)
86 file(GENERATE
87   OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME}
88   CONTENT "${POLLY_EXPORTS}")
91 # Generate PollyConfig.cmake for the install tree.
92 unset(POLLY_EXPORTS)
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
100     "${base_includedir}"
101     "${base_includedir}/polly"
102     )
103 else()
104   set(POLLY_CONFIG_INCLUDE_DIRS
105     "${base_includedir}"
106     ${ISL_INCLUDE_DIRS}
107     )
108 endif()
110 # Set locations for imported targets. The path is constructed to be relative to
111 # the config file.
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.
115 set(POLLY_EXPORTS
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}")
123   else()
124     set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}")
125   endif()
127   extend_path(tgt_path "\${POLLY_INSTALL_PREFIX}" "${tgt_prefix}/$<TARGET_FILE_NAME:${tgt}>")
129   if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
130     set(POLLY_EXPORTS
131 "set_target_properties(${tgt} PROPERTIES
132         IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> \"${tgt_path}\")
133 ${POLLY_EXPORTS}")
134   endif()
135 endforeach(tgt)
137 configure_file(
138   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
139   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
140   @ONLY)
141 file(GENERATE OUTPUT
142   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
143   CONTENT "${POLLY_EXPORTS}")
145 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
146   install(
147     FILES
148     "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake"
149     "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}"
150     DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}")
151 endif ()