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