diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a90e4ac80..bb6b3de8812 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -606,28 +606,7 @@ endif() if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR CMAKE_VERSION VERSION_GREATER 3) - # Generate a list of CMake library targets so that other CMake projects can - # link against them. LLVM calls its version of this file LLVMExports.cmake, but - # the usual CMake convention seems to be ${Project}Targets.cmake. - set(CLANG_INSTALL_PACKAGE_DIR share/clang/cmake) - set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}") - get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS) - export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake) - - # Install a /share/clang/cmake/ClangConfig.cmake file so that - # find_package(Clang) works. Install the target list with it. - install(EXPORT ClangTargets DESTINATION ${CLANG_INSTALL_PACKAGE_DIR}) - - install(FILES - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake - DESTINATION share/clang/cmake) - - # Also copy ClangConfig.cmake to the build directory so that dependent projects - # can build against a build directory of Clang more easily. - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake - ${CLANG_BINARY_DIR}/share/clang/cmake/ClangConfig.cmake - COPYONLY) + add_subdirectory(cmake/modules) endif () if (CLANG_ENABLE_BOOTSTRAP) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt new file mode 100644 index 00000000000..3cc808a46b9 --- /dev/null +++ b/cmake/modules/CMakeLists.txt @@ -0,0 +1,47 @@ +# Generate a list of CMake library targets so that other CMake projects can +# link against them. LLVM calls its version of this file LLVMExports.cmake, but +# the usual CMake convention seems to be ${Project}Targets.cmake. +set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang) +set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}") + +get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS) +export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake) + +# Generate ClangConfig.cmake for the build tree. +set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}") +set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake") +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in + ${clang_cmake_builddir}/ClangConfig.cmake + @ONLY) +set(CLANG_CONFIG_CMAKE_DIR) +set(CLANG_CONFIG_EXPORTS_FILE) + +# Generate ClangConfig.cmake for the install tree. +set(CLANG_CONFIG_CODE " +# Compute the installation prefix from this LLVMConfig.cmake file location. +get_filename_component(CLANG_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)") +# Construct the proper number of get_filename_component(... PATH) +# calls to compute the installation prefix. +string(REGEX REPLACE "/" ";" _count "${CLANG_INSTALL_PACKAGE_DIR}") +foreach(p ${_count}) + set(CLANG_CONFIG_CODE "${CLANG_CONFIG_CODE} +get_filename_component(CLANG_INSTALL_PREFIX \"\${CLANG_INSTALL_PREFIX}\" PATH)") +endforeach(p) +set(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}") +set(CLANG_CONFIG_EXPORTS_FILE "\${CLANG_CMAKE_DIR}/ClangTargets.cmake") +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake + @ONLY) +set(CLANG_CONFIG_CODE) +set(CLANG_CONFIG_CMAKE_DIR) +set(CLANG_CONFIG_EXPORTS_FILE) + +if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(EXPORT ClangTargets DESTINATION ${CLANG_INSTALL_PACKAGE_DIR}) + + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake + DESTINATION ${CLANG_INSTALL_PACKAGE_DIR}) +endif() diff --git a/cmake/modules/ClangConfig.cmake b/cmake/modules/ClangConfig.cmake deleted file mode 100644 index f052bb9e8c8..00000000000 --- a/cmake/modules/ClangConfig.cmake +++ /dev/null @@ -1,8 +0,0 @@ -# This file allows users to call find_package(Clang) and pick up our targets. - -# Clang doesn't have any CMake configuration settings yet because it mostly -# uses LLVM's. When it does, we should move this file to ClangConfig.cmake.in -# and call configure_file() on it. - -# Provide all our library targets to users. -include("${CMAKE_CURRENT_LIST_DIR}/ClangTargets.cmake") diff --git a/cmake/modules/ClangConfig.cmake.in b/cmake/modules/ClangConfig.cmake.in new file mode 100644 index 00000000000..a946944dd99 --- /dev/null +++ b/cmake/modules/ClangConfig.cmake.in @@ -0,0 +1,11 @@ +# This file allows users to call find_package(Clang) and pick up our targets. + +find_package(LLVM REQUIRED CONFIG) + +@CLANG_CONFIG_CODE@ + +set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@") +set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@") + +# Provide all our library targets to users. +include("@CLANG_CONFIG_EXPORTS_FILE@")