2 include(LLVMDistributionSupport)
3 include(FindPrefixFromConfig)
5 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
6 string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")
7 set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")
9 # First for users who use an installed LLVM, create the LLVMExports.cmake file.
10 set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake)
11 get_property(LLVM_EXPORTS GLOBAL PROPERTY LLVM_EXPORTS)
12 export(TARGETS ${LLVM_EXPORTS} FILE ${LLVM_EXPORTS_FILE})
14 # Then for users who want to link against the LLVM build tree, provide the
15 # normal targets and the build tree only targets.
16 set(LLVM_BUILDTREEONLY_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMBuildTreeOnlyTargets.cmake)
17 get_property(LLVM_EXPORTS_BUILDTREE_ONLY GLOBAL PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY)
18 export(TARGETS ${LLVM_EXPORTS_BUILDTREE_ONLY} FILE ${LLVM_BUILDTREEONLY_EXPORTS_FILE})
20 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
22 foreach(lib ${LLVM_AVAILABLE_LIBS})
23 get_property(llvm_lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
25 "${all_llvm_lib_deps}\nset_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib} ${llvm_lib_deps})")
28 # CMake requires that all targets expressed as dependencies exist, so we can't
29 # have intrinsics_gen in LLVM_COMMON_DEPENDS when it is written out, otherwise
30 # projects building out of tree will have CMake errors. This only gets hit when
31 # LLVM_ENABLE_MODULES=On. Eventually we should come up with a better solution to
32 # this, but there is no easy solution.
33 if(intrinsics_gen IN_LIST LLVM_COMMON_DEPENDS)
34 list(REMOVE_ITEM LLVM_COMMON_DEPENDS intrinsics_gen)
36 if(omp_gen IN_LIST LLVM_COMMON_DEPENDS)
37 list(REMOVE_ITEM LLVM_COMMON_DEPENDS omp_gen)
41 # Generate LLVMConfig.cmake for the build tree.
44 set(LLVM_CONFIG_CODE "
45 # LLVM_BUILD_* values available only from LLVM build tree.
46 set(LLVM_BUILD_BINARY_DIR \"${LLVM_BINARY_DIR}\")
47 set(LLVM_BUILD_LIBRARY_DIR \"${LLVM_LIBRARY_DIR}\")
48 set(LLVM_BUILD_MAIN_INCLUDE_DIR \"${LLVM_MAIN_INCLUDE_DIR}\")
49 set(LLVM_BUILD_MAIN_SRC_DIR \"${LLVM_MAIN_SRC_DIR}\")
52 set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_MAIN_INCLUDE_DIR}")
53 set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_INCLUDE_DIR}")
54 set(LLVM_CONFIG_INCLUDE_DIRS
55 "${LLVM_CONFIG_MAIN_INCLUDE_DIR}"
56 "${LLVM_CONFIG_INCLUDE_DIR}"
58 list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS)
60 set(LLVM_CONFIG_LIBRARY_DIR "${LLVM_LIBRARY_DIR}")
61 set(LLVM_CONFIG_LIBRARY_DIRS
62 "${LLVM_CONFIG_LIBRARY_DIR}"
63 # FIXME: Should there be other entries here?
65 list(REMOVE_DUPLICATES LLVM_CONFIG_LIBRARY_DIRS)
67 set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}")
68 set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
69 set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}")
71 # Generate a default location for lit
73 if (CMAKE_HOST_WIN32 AND NOT CYGWIN)
74 set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit.py")
76 set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit")
80 if (LLVM_LINK_LLVM_DYLIB)
81 set(LLVM_CONFIG_LINK_LLVM_DYLIB
82 "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
85 # We need to use the full path to the LLVM Exports file to make sure we get the
86 # one from the build tree. This is due to our cmake files being split between
87 # this source dir and the binary dir in the build tree configuration and the
88 # LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install
89 # tree, both the generated LLVMExports.cmake file and the rest of the cmake
90 # source files are put in the same cmake directory.
91 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}")
92 set(LLVM_CONFIG_INCLUDE_EXPORTS "include(\"${LLVM_EXPORTS_FILE}\")")
93 set(llvm_config_include_buildtree_only_exports
94 "include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")")
97 ${llvm_cmake_builddir}/LLVMConfig.cmake
99 set(llvm_config_include_buildtree_only_exports)
101 # For compatibility with projects that include(LLVMConfig)
102 # via CMAKE_MODULE_PATH, place API modules next to it.
103 # Copy without source permissions because the source could be read-only,
104 # but we need to write into the copied folder.
105 # This should be removed in the future.
107 DESTINATION ${llvm_cmake_builddir}
108 NO_SOURCE_PERMISSIONS
109 FILES_MATCHING PATTERN *.cmake
110 PATTERN CMakeFiles EXCLUDE
111 PATTERN llvm-driver-template.cpp.in
115 # Generate LLVMConfig.cmake for the install tree.
118 find_prefix_from_config(LLVM_CONFIG_CODE LLVM_INSTALL_PREFIX "${LLVM_INSTALL_PACKAGE_DIR}")
120 extend_path(LLVM_CONFIG_MAIN_INCLUDE_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
121 # This is the same as the above because the handwritten and generated headers
122 # are combined in one directory at install time.
123 set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_MAIN_INCLUDE_DIR}")
124 set(LLVM_CONFIG_INCLUDE_DIRS
125 "${LLVM_CONFIG_MAIN_INCLUDE_DIR}"
126 "${LLVM_CONFIG_INCLUDE_DIR}"
128 list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS)
130 extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}")
131 set(LLVM_CONFIG_LIBRARY_DIRS
132 "${LLVM_CONFIG_LIBRARY_DIR}"
133 # FIXME: Should there be other entries here?
135 list(REMOVE_DUPLICATES LLVM_CONFIG_LIBRARY_DIRS)
137 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
138 extend_path(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
139 extend_path(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_TOOLS_INSTALL_DIR}")
141 # Generate a default location for lit
142 if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
143 if (CMAKE_HOST_WIN32 AND NOT CYGWIN)
144 set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit.py")
146 set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit")
150 get_config_exports_includes(LLVM LLVM_CONFIG_INCLUDE_EXPORTS)
151 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}")
154 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
157 # Generate LLVMConfigVersion.cmake for build and install tree.
159 LLVMConfigVersion.cmake.in
160 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
163 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
164 install_distribution_exports(LLVM)
167 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
168 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
170 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
171 COMPONENT cmake-exports)
174 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
175 COMPONENT cmake-exports
176 FILES_MATCHING PATTERN *.cmake
177 PATTERN LLVMConfig.cmake EXCLUDE
178 PATTERN LLVMConfigExtensions.cmake EXCLUDE
179 PATTERN LLVMConfigVersion.cmake EXCLUDE
180 PATTERN LLVM-Config.cmake EXCLUDE
181 PATTERN GetHostTriple.cmake EXCLUDE
182 PATTERN llvm-driver-template.cpp.in)
184 if (NOT LLVM_ENABLE_IDE)
185 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
186 add_custom_target(cmake-exports)
187 add_llvm_install_targets(install-cmake-exports
188 COMPONENT cmake-exports)