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_LIBRARY_DIRS
47 set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
48 set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}")
49 set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}")
51 if (LLVM_LINK_LLVM_DYLIB)
52 set(LLVM_CONFIG_LINK_LLVM_DYLIB
53 "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
56 # We need to use the full path to the LLVM Exports file to make sure we get the
57 # one from the build tree. This is due to our cmake files being split between
58 # this source dir and the binary dir in the build tree configuration and the
59 # LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install
60 # tree, both the generated LLVMExports.cmake file and the rest of the cmake
61 # source files are put in the same cmake directory.
62 set(LLVM_CONFIG_EXPORTS_FILE "${LLVM_EXPORTS_FILE}")
63 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}")
64 set(llvm_config_include_buildtree_only_exports
65 "include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")")
68 ${llvm_cmake_builddir}/LLVMConfig.cmake
70 set(llvm_config_include_buildtree_only_exports)
72 # For compatibility with projects that include(LLVMConfig)
73 # via CMAKE_MODULE_PATH, place API modules next to it.
74 # This should be removed in the future.
76 DESTINATION ${llvm_cmake_builddir}
77 FILES_MATCHING PATTERN *.cmake
79 PATTERN CMakeFiles EXCLUDE
82 # Generate LLVMConfig.cmake for the install tree.
83 set(LLVM_CONFIG_CODE "
84 # Compute the installation prefix from this LLVMConfig.cmake file location.
85 get_filename_component(LLVM_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
86 # Construct the proper number of get_filename_component(... PATH)
87 # calls to compute the installation prefix.
88 string(REGEX REPLACE "/" ";" _count "${LLVM_INSTALL_PACKAGE_DIR}")
90 set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE}
91 get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
93 set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include")
94 set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}")
95 set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
96 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
97 set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
98 set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake")
99 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}")
102 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
105 # Generate LLVMConfigVersion.cmake for build and install tree.
107 LLVMConfigVersion.cmake.in
108 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
111 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
112 get_property(llvm_has_exports GLOBAL PROPERTY LLVM_HAS_EXPORTS)
114 install(EXPORT LLVMExports DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
115 COMPONENT cmake-exports)
119 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
120 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
122 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
123 COMPONENT cmake-exports)
126 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
127 COMPONENT cmake-exports
128 FILES_MATCHING PATTERN *.cmake
130 PATTERN LLVMConfig.cmake EXCLUDE
131 PATTERN LLVMConfigVersion.cmake EXCLUDE
132 PATTERN LLVM-Config.cmake EXCLUDE
133 PATTERN GetHostTriple.cmake EXCLUDE)
135 if (NOT LLVM_ENABLE_IDE)
136 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
137 add_custom_target(cmake-exports)
138 add_llvm_install_targets(install-cmake-exports
139 COMPONENT cmake-exports)