1 include(LLVMDistributionSupport)
3 set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
4 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
6 # First for users who use an installed LLVM, create the LLVMExports.cmake file.
7 set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake)
8 get_property(LLVM_EXPORTS GLOBAL PROPERTY LLVM_EXPORTS)
9 export(TARGETS ${LLVM_EXPORTS} FILE ${LLVM_EXPORTS_FILE})
11 # Then for users who want to link against the LLVM build tree, provide the
12 # normal targets and the build tree only targets.
13 set(LLVM_BUILDTREEONLY_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMBuildTreeOnlyTargets.cmake)
14 get_property(LLVM_EXPORTS_BUILDTREE_ONLY GLOBAL PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY)
15 export(TARGETS ${LLVM_EXPORTS_BUILDTREE_ONLY} FILE ${LLVM_BUILDTREEONLY_EXPORTS_FILE})
17 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
19 foreach(lib ${LLVM_AVAILABLE_LIBS})
20 get_property(llvm_lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
22 "${all_llvm_lib_deps}\nset_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib} ${llvm_lib_deps})")
25 # CMake requires that all targets expressed as dependencies exist, so we can't
26 # have intrinsics_gen in LLVM_COMMON_DEPENDS when it is written out, otherwise
27 # projects building out of tree will have CMake errors. This only gets hit when
28 # LLVM_ENABLE_MODULES=On. Eventually we should come up with a better solution to
29 # this, but there is no easy solution.
30 if(intrinsics_gen IN_LIST LLVM_COMMON_DEPENDS)
31 list(REMOVE_ITEM LLVM_COMMON_DEPENDS intrinsics_gen)
33 if(omp_gen IN_LIST LLVM_COMMON_DEPENDS)
34 list(REMOVE_ITEM LLVM_COMMON_DEPENDS omp_gen)
37 # Generate LLVMConfig.cmake for the build tree.
38 set(LLVM_CONFIG_CODE "
39 # LLVM_BUILD_* values available only from LLVM build tree.
40 set(LLVM_BUILD_BINARY_DIR \"${LLVM_BINARY_DIR}\")
41 set(LLVM_BUILD_LIBRARY_DIR \"${LLVM_LIBRARY_DIR}\")
42 set(LLVM_BUILD_MAIN_INCLUDE_DIR \"${LLVM_MAIN_INCLUDE_DIR}\")
43 set(LLVM_BUILD_MAIN_SRC_DIR \"${LLVM_MAIN_SRC_DIR}\")
45 set(LLVM_CONFIG_INCLUDE_DIRS
46 "${LLVM_MAIN_INCLUDE_DIR}"
49 set(LLVM_CONFIG_INCLUDE_DIR
52 set(LLVM_CONFIG_MAIN_INCLUDE_DIR
53 "${LLVM_MAIN_INCLUDE_DIR}"
55 set(LLVM_CONFIG_LIBRARY_DIRS
58 set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
59 set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}")
60 set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}")
62 # Generate a default location for lit
64 if (CMAKE_HOST_WIN32 AND NOT CYGWIN)
65 set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit.py")
67 set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit")
71 if (LLVM_LINK_LLVM_DYLIB)
72 set(LLVM_CONFIG_LINK_LLVM_DYLIB
73 "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
76 # We need to use the full path to the LLVM Exports file to make sure we get the
77 # one from the build tree. This is due to our cmake files being split between
78 # this source dir and the binary dir in the build tree configuration and the
79 # LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install
80 # tree, both the generated LLVMExports.cmake file and the rest of the cmake
81 # source files are put in the same cmake directory.
82 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}")
83 set(LLVM_CONFIG_INCLUDE_EXPORTS "include(\"${LLVM_EXPORTS_FILE}\")")
84 set(llvm_config_include_buildtree_only_exports
85 "include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")")
88 ${llvm_cmake_builddir}/LLVMConfig.cmake
90 set(llvm_config_include_buildtree_only_exports)
92 # For compatibility with projects that include(LLVMConfig)
93 # via CMAKE_MODULE_PATH, place API modules next to it.
94 # This should be removed in the future.
96 DESTINATION ${llvm_cmake_builddir}
97 FILES_MATCHING PATTERN *.cmake
98 PATTERN CMakeFiles EXCLUDE
101 # Generate LLVMConfig.cmake for the install tree.
102 set(LLVM_CONFIG_CODE "
103 # Compute the installation prefix from this LLVMConfig.cmake file location.
104 get_filename_component(LLVM_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
105 # Construct the proper number of get_filename_component(... PATH)
106 # calls to compute the installation prefix.
107 string(REGEX REPLACE "/" ";" _count "${LLVM_INSTALL_PACKAGE_DIR}")
109 set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE}
110 get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
112 set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include")
113 set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
114 set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
115 set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}")
116 set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
117 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
118 set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
120 # Generate a default location for lit
121 if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
122 set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit")
125 get_config_exports_includes(LLVM LLVM_CONFIG_INCLUDE_EXPORTS)
126 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}")
129 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
132 # Generate LLVMConfigVersion.cmake for build and install tree.
134 LLVMConfigVersion.cmake.in
135 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
138 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
139 install_distribution_exports(LLVM)
142 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
143 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
145 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
146 COMPONENT cmake-exports)
149 DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
150 COMPONENT cmake-exports
151 FILES_MATCHING PATTERN *.cmake
152 PATTERN LLVMConfig.cmake EXCLUDE
153 PATTERN LLVMConfigExtensions.cmake EXCLUDE
154 PATTERN LLVMConfigVersion.cmake EXCLUDE
155 PATTERN LLVM-Config.cmake EXCLUDE
156 PATTERN GetHostTriple.cmake EXCLUDE)
158 if (NOT LLVM_ENABLE_IDE)
159 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
160 add_custom_target(cmake-exports)
161 add_llvm_install_targets(install-cmake-exports
162 COMPONENT cmake-exports)