• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Generate a list of CMake library targets so that other CMake projects can
2# link against them. LLVM calls its version of this file LLVMExports.cmake, but
3# the usual CMake convention seems to be ${Project}Targets.cmake.
4set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang)
5set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}")
6
7get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
8export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
9
10# Generate ClangConfig.cmake for the build tree.
11set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}")
12set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake")
13configure_file(
14  ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
15  ${clang_cmake_builddir}/ClangConfig.cmake
16  @ONLY)
17set(CLANG_CONFIG_CMAKE_DIR)
18set(CLANG_CONFIG_EXPORTS_FILE)
19
20# Generate ClangConfig.cmake for the install tree.
21set(CLANG_CONFIG_CODE "
22# Compute the installation prefix from this LLVMConfig.cmake file location.
23get_filename_component(CLANG_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
24# Construct the proper number of get_filename_component(... PATH)
25# calls to compute the installation prefix.
26string(REGEX REPLACE "/" ";" _count "${CLANG_INSTALL_PACKAGE_DIR}")
27foreach(p ${_count})
28  set(CLANG_CONFIG_CODE "${CLANG_CONFIG_CODE}
29get_filename_component(CLANG_INSTALL_PREFIX \"\${CLANG_INSTALL_PREFIX}\" PATH)")
30endforeach(p)
31set(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")
32set(CLANG_CONFIG_EXPORTS_FILE "\${CLANG_CMAKE_DIR}/ClangTargets.cmake")
33configure_file(
34  ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
35  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
36  @ONLY)
37set(CLANG_CONFIG_CODE)
38set(CLANG_CONFIG_CMAKE_DIR)
39set(CLANG_CONFIG_EXPORTS_FILE)
40
41if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
42  install(EXPORT ClangTargets DESTINATION ${CLANG_INSTALL_PACKAGE_DIR})
43
44  install(FILES
45    ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
46    DESTINATION ${CLANG_INSTALL_PACKAGE_DIR})
47endif()
48