[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / polly / cmake / CMakeLists.txt
blobcd1f5db842d93dbad4b62221db2bc28406c5fbb6
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 string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")
16 set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")
18 if (CMAKE_CONFIGURATION_TYPES)
19   set(POLLY_EXPORTS_FILE_NAME "PollyExports-$<LOWER_CASE:$<CONFIG>>.cmake")
20 else()
21   # avoid conflicts in the build-tree when changing configuration
22   set(POLLY_EXPORTS_FILE_NAME "PollyExports-all.cmake")
23 endif()
25 set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET})
26 if (NOT (WIN32 OR CYGWIN) AND LLVM_ENABLE_PIC)
27   # LLVMPolly is a dummy target on Win or if PIC code is disabled.
28   list(APPEND POLLY_CONFIG_EXPORTED_TARGETS LLVMPolly)
29 endif()
31 # Get the target type for every exported target
32 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
33   get_target_property(tgt_type ${tgt} TYPE)
34   string(REPLACE "_LIBRARY" "" tgt_type ${tgt_type})
35   set(POLLY_CONFIG_TARGET_${tgt}_TYPE ${tgt_type})
36 endforeach()
38 # generate the import code for bundled/undbundled libisl versions
39 if (NOT POLLY_BUNDLED_ISL)
40   get_property(incl TARGET ISL PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
41   get_property(lib TARGET ISL PROPERTY INTERFACE_LINK_LIBRARIES)
42   get_property(opt TARGET ISL PROPERTY INTERFACE_COMPILE_OPTIONS)
43   set(ISL_CONFIG_CODE "
44 add_library(ISL INTERFACE IMPORTED)
45 set_property(TARGET ISL APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${incl})
46 set_property(TARGET ISL APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${lib})
47 set_property(TARGET ISL APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${opt})")
48 else()
49   set(ISL_CONFIG_CODE "
50 if (NOT TARGET PollyISL)
51   add_library(PollyISL ${POLLY_CONFIG_TARGET_PollyISL_TYPE} IMPORTED)
52 endif()")
53 endif()
55 # Generate PollyConfig.cmake for the build tree.
56 set(POLLY_CONFIG_CODE "")
57 set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
58 set(POLLY_CONFIG_CMAKE_DIR "${polly_cmake_builddir}")
59 set(POLLY_CONFIG_INCLUDE_DIRS
60   ${POLLY_SOURCE_DIR}/include
61   ${ISL_INCLUDE_DIRS}
62   ${POLLY_BINARY_DIR}/include
63   )
64 set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_BINARY_DIR}/lib")
66 # set locations for imported targets
67 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
68   get_target_property(tgt_type ${tgt} TYPE)
69   if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
70     set(POLLY_EXPORTS
71       "set_target_properties(${tgt} PROPERTIES
72               IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> $<TARGET_FILE:${tgt}>)
73 ${POLLY_EXPORTS}")
74   endif()
75 endforeach(tgt)
77 # PollyConfig holds the target definitions and general settings, PollyExports
78 # the imported locations
79 configure_file(
80   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
81   ${polly_cmake_builddir}/PollyConfig.cmake
82   @ONLY)
83 configure_file(
84   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in
85   ${polly_cmake_builddir}/PollyConfigVersion.cmake
86   @ONLY)
88 file(GENERATE
89   OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME}
90   CONTENT "${POLLY_EXPORTS}")
93 # Generate PollyConfig.cmake for the install tree.
94 unset(POLLY_EXPORTS)
95 find_prefix_from_config(POLLY_CONFIG_CODE POLLY_INSTALL_PREFIX "${POLLY_INSTALL_PACKAGE_DIR}")
96 extend_path(POLLY_CONFIG_LLVM_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
97 extend_path(POLLY_CONFIG_CMAKE_DIR "\${POLLY_INSTALL_PREFIX}" "${POLLY_INSTALL_PACKAGE_DIR}")
98 extend_path(POLLY_CONFIG_LIBRARY_DIRS "\${POLLY_INSTALL_PREFIX}" "lib${LLVM_LIBDIR_SUFFIX}")
99 extend_path(base_includedir "\${POLLY_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
100 if (POLLY_BUNDLED_ISL)
101   set(POLLY_CONFIG_INCLUDE_DIRS
102     "${base_includedir}"
103     "${base_includedir}/polly"
104     )
105 else()
106   set(POLLY_CONFIG_INCLUDE_DIRS
107     "${base_includedir}"
108     ${ISL_INCLUDE_DIRS}
109     )
110 endif()
112 # Set locations for imported targets. The path is constructed to be relative to
113 # the config file.
115 # Include the config code of PollyConfig.cmake to define POLLY_INSTALL_PREFIX
116 # anew in case the export file is included alone rather than from that file.
117 set(POLLY_EXPORTS
118 "${POLLY_CONFIG_CODE}
121 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
122   get_target_property(tgt_type ${tgt} TYPE)
123   if (tgt_type STREQUAL "EXECUTABLE")
124     set(tgt_prefix "${CMAKE_INSTALL_BINDIR}")
125   else()
126     set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}")
127   endif()
129   extend_path(tgt_path "\${POLLY_INSTALL_PREFIX}" "${tgt_prefix}/$<TARGET_FILE_NAME:${tgt}>")
131   if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
132     set(POLLY_EXPORTS
133 "set_target_properties(${tgt} PROPERTIES
134         IMPORTED_LOCATION$<$<NOT:$<CONFIG:>>:_$<UPPER_CASE:$<CONFIG>>> \"${tgt_path}\")
135 ${POLLY_EXPORTS}")
136   endif()
137 endforeach(tgt)
139 configure_file(
140   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
141   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
142   @ONLY)
143 configure_file(
144   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfigVersion.cmake.in
145   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake
146   @ONLY)
147 file(GENERATE OUTPUT
148   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
149   CONTENT "${POLLY_EXPORTS}")
151 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
152   install(
153     FILES
154     "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake"
155     "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfigVersion.cmake"
156     "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}"
157     DESTINATION "${POLLY_INSTALL_PACKAGE_DIR}")
158 endif ()