Fix clang Wrange-loop-analysis in BuildTree.cpp
[llvm-project.git] / polly / cmake / CMakeLists.txt
blobfd8028a8937af2391f34a250dda975b7cb918e23
1 # Keep this in sync with llvm/cmake/CMakeLists.txt!
3 set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
4 set(POLLY_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
5 if (CMAKE_CONFIGURATION_TYPES)
6   set(POLLY_EXPORTS_FILE_NAME "PollyExports-$<LOWER_CASE:$<CONFIG>>.cmake")
7 else()
8   # avoid conflicts in the build-tree when changing configuration
9   set(POLLY_EXPORTS_FILE_NAME "PollyExports-all.cmake")
10 endif()
12 set(POLLY_CONFIG_EXPORTED_TARGETS Polly ${ISL_TARGET})
13 if (NOT MSVC 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)
16 endif()
17 if (POLLY_ENABLE_GPGPU_CODEGEN)
18   list(APPEND POLLY_CONFIG_EXPORTED_TARGETS PollyPPCG)
19 endif()
21 # Get the target type for every exported target
22 foreach(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})
26 endforeach()
28 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
29 set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
31 # generate the import code for bundled/undbundled libisl versions
32 if (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 "
37 add_library(ISL INTERFACE IMPORTED)
38 set_property(TARGET ISL APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${incl})
39 set_property(TARGET ISL APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${lib})
40 set_property(TARGET ISL APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${opt})")
41 else()
42   set(ISL_CONFIG_CODE "
43 if (NOT TARGET PollyISL)
44   add_library(PollyISL ${POLLY_CONFIG_TARGET_PollyISL_TYPE} IMPORTED)
45 endif()")
46 endif()
48 # Generate PollyConfig.cmake for the build tree.
49 set(POLLY_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/${POLLY_INSTALL_PACKAGE_DIR}")
50 set(POLLY_CONFIG_INCLUDE_DIRS
51   ${POLLY_SOURCE_DIR}/include
52   ${ISL_INCLUDE_DIRS}
53   ${POLLY_BINARY_DIR}/include
54   )
55 set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_BINARY_DIR}/lib")
57 # set locations for imported targets
58 foreach(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()
66 endforeach(tgt)
68 # PollyConfig holds the target definitions and general settings, PollyExports
69 # the imported locations
70 configure_file(
71   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
72   ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake
73   @ONLY)
75 file(GENERATE
76   OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME}
77   CONTENT "${POLLY_EXPORTS}")
80 # Generate PollyConfig.cmake for the install tree.
81 unset(POLLY_EXPORTS)
82 set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
83 set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
84 set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
85 set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
86 if (POLLY_BUNDLED_ISL)
87   set(POLLY_CONFIG_INCLUDE_DIRS
88     "${POLLY_INSTALL_PREFIX}/include"
89     "${POLLY_INSTALL_PREFIX}/include/polly"
90     )
91 else()
92   set(POLLY_CONFIG_INCLUDE_DIRS
93     "${POLLY_INSTALL_PREFIX}/include"
94     ${ISL_INCLUDE_DIRS}
95     )
96 endif()
98 # set locations for imported targets. The path is constructed to be relative to
99 # the config file
100 foreach(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()
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})
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()
117 endforeach(tgt)
119 configure_file(
120   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
121   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/PollyConfig.cmake
122   @ONLY)
123 file(GENERATE OUTPUT
124   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${POLLY_EXPORTS_FILE_NAME}
125   CONTENT "${POLLY_EXPORTS}")
127 if (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}")
133 endif ()