1 set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
2 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
4 # First for users who use an installed LLVM, create the LLVMExports.cmake file.
5 set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake)
6 get_property(LLVM_EXPORTS GLOBAL PROPERTY LLVM_EXPORTS)
7 export(TARGETS ${LLVM_EXPORTS} FILE ${LLVM_EXPORTS_FILE})
9 # Then for users who want to link against the LLVM build tree, provide the
10 # normal targets and the build tree only targets.
11 set(LLVM_BUILDTREEONLY_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMBuildTreeOnlyTargets.cmake)
12 get_property(LLVM_EXPORTS_BUILDTREE_ONLY GLOBAL PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY)
13 export(TARGETS ${LLVM_EXPORTS_BUILDTREE_ONLY} FILE ${LLVM_BUILDTREEONLY_EXPORTS_FILE})
15 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
17 foreach(lib ${LLVM_AVAILABLE_LIBS})
18 get_property(llvm_lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
20 "${all_llvm_lib_deps}\nset_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib} ${llvm_lib_deps})")
23 # CMake requires that all targets expressed as dependencies exist, so we can't
24 # have intrinsics_gen in LLVM_COMMON_DEPENDS when it is written out, otherwise
25 # projects building out of tree will have CMake errors. This only gets hit when
26 # LLVM_ENABLE_MODULES=On. Eventually we should come up with a better solution to
27 # this, but there is no easy solution.
28 if(intrinsics_gen IN_LIST LLVM_COMMON_DEPENDS)
29 list(REMOVE_ITEM LLVM_COMMON_DEPENDS intrinsics_gen)
32 # Generate LLVMConfig.cmake for the build tree.
33 set(LLVM_CONFIG_CODE "
34 # LLVM_BUILD_* values available only from LLVM build tree.
35 set(LLVM_BUILD_BINARY_DIR \"${LLVM_BINARY_DIR}\")
36 set(LLVM_BUILD_LIBRARY_DIR \"${LLVM_LIBRARY_DIR}\")
37 set(LLVM_BUILD_MAIN_INCLUDE_DIR \"${LLVM_MAIN_INCLUDE_DIR}\")
38 set(LLVM_BUILD_MAIN_SRC_DIR \"${LLVM_MAIN_SRC_DIR}\")
40 set(LLVM_CONFIG_INCLUDE_DIRS
41 "${LLVM_MAIN_INCLUDE_DIR}"
44 set(LLVM_CONFIG_INCLUDE_DIR
47 set(LLVM_CONFIG_MAIN_INCLUDE_DIR
48 "${LLVM_MAIN_INCLUDE_DIR}"
50 set(LLVM_CONFIG_LIBRARY_DIRS
53 set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
54 set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}")
55 set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}")
57 if (LLVM_LINK_LLVM_DYLIB)
58 set(LLVM_CONFIG_LINK_LLVM_DYLIB
59 "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
62 # We need to use the full path to the LLVM Exports file to make sure we get the
63 # one from the build tree. This is due to our cmake files being split between
64 # this source dir and the binary dir in the build tree configuration and the
65 # LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install
66 # tree, both the generated LLVMExports.cmake file and the rest of the cmake
67 # source files are put in the same cmake directory.
68 set(LLVM_CONFIG_EXPORTS_FILE "${LLVM_EXPORTS_FILE}")
69 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}")
70 set(llvm_config_include_buildtree_only_exports
71 "include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")")
74 ${llvm_cmake_builddir}/LLVMConfig.cmake
76 set(llvm_config_include_buildtree_only_exports)
78 # For compatibility with projects that include(LLVMConfig)
79 # via CMAKE_MODULE_PATH, place API modules next to it.
80 # This should be removed in the future.
82 DESTINATION ${llvm_cmake_builddir}
83 FILES_MATCHING PATTERN *.cmake
85 PATTERN CMakeFiles EXCLUDE
88 # Generate LLVMConfig.cmake for the install tree.
89 set(LLVM_CONFIG_CODE "
90 # Compute the installation prefix from this LLVMConfig.cmake file location.
91 get_filename_component(LLVM_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
92 # Construct the proper number of get_filename_component(... PATH)
93 # calls to compute the installation prefix.
94 string(REGEX REPLACE "/" ";" _count "${LLVM_INSTALL_PACKAGE_DIR}")
96 set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE}
97 get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
99 set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include")
100 set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
101 set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
102 set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}")
103 set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
104 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
105 set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
106 set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake")
107 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}")
110 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
113 # Generate LLVMConfigVersion.cmake for build and install tree.
115 LLVMConfigVersion.cmake.in
116 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
119 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
120 get_property(llvm_has_exports GLOBAL PROPERTY LLVM_HAS_EXPORTS)
122 install(EXPORT LLVMExports DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
123 COMPONENT cmake-exports)
127 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
128 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
130 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
131 COMPONENT cmake-exports)
134 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
135 COMPONENT cmake-exports
136 FILES_MATCHING PATTERN *.cmake
138 PATTERN LLVMConfig.cmake EXCLUDE
139 PATTERN LLVMConfigVersion.cmake EXCLUDE
140 PATTERN LLVM-Config.cmake EXCLUDE
141 PATTERN GetHostTriple.cmake EXCLUDE)
143 if (NOT LLVM_ENABLE_IDE)
144 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
145 add_custom_target(cmake-exports)
146 add_llvm_install_targets(install-cmake-exports
147 COMPONENT cmake-exports)