CMake: support for using LLVM from client projects with find_package.

Patch by arrowdodger!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129247 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Oscar Fuentes 2011-04-10 16:17:49 +00:00
parent 64cfcefdeb
commit 3447b4f01b
4 changed files with 42 additions and 6 deletions

View File

@ -1,14 +1,21 @@
set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/share/llvm/cmake")
set(LLVM_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS)
configure_file(
LLVM.cmake
${llvm_cmake_builddir}/LLVM.cmake
LLVMConfig.cmake.in
${llvm_cmake_builddir}/LLVMConfig.cmake
@ONLY)
configure_file(
LLVMConfigVersion.cmake.in
${llvm_cmake_builddir}/LLVMConfigVersion.cmake
@ONLY)
install(FILES
${llvm_cmake_builddir}/LLVM.cmake
${llvm_cmake_builddir}/LLVMConfig.cmake
${llvm_cmake_builddir}/LLVMConfigVersion.cmake
LLVM-Config.cmake
LLVMLibDeps.cmake
DESTINATION share/llvm/cmake)
@ -17,7 +24,8 @@ install(DIRECTORY .
DESTINATION share/llvm/cmake
FILES_MATCHING PATTERN *.cmake
PATTERN .svn EXCLUDE
PATTERN LLVM.cmake EXCLUDE
PATTERN LLVMConfig.cmake EXCLUDE
PATTERN LLVMConfigVersion.cmake EXCLUDE
PATTERN LLVM-Config.cmake EXCLUDE
PATTERN LLVMLibDeps.cmake EXCLUDE
PATTERN FindBison.cmake EXCLUDE
@ -25,8 +33,10 @@ install(DIRECTORY .
PATTERN VersionFromVCS.cmake EXCLUDE
PATTERN CheckAtomic.cmake EXCLUDE)
#remove this?
install(FILES
${llvm_cmake_builddir}/LLVM.cmake
${llvm_cmake_builddir}/LLVMConfig.cmake
${llvm_cmake_builddir}/LLVMConfigVersion.cmake
LLVM-Config.cmake
LLVMLibDeps.cmake
DESTINATION share/llvm/cmake)

View File

@ -1,6 +1,6 @@
# This file provides information and services to the final user.
set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@)
set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@) #remove this?
set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@)
@ -25,6 +25,11 @@ set(HAVE_LIBPTHREAD @HAVE_LIBPTHREAD@)
set(LLVM_ON_UNIX @LLVM_ON_UNIX@)
set(LLVM_ON_WIN32 @LLVM_ON_WIN32@)
set(LLVM_INSTALL_PREFIX @LLVM_INSTALL_PREFIX@)
set(LLVM_INCLUDE_DIRS ${LLVM_INSTALL_PREFIX}/include)
set(LLVM_LIBRARY_DIRS ${LLVM_INSTALL_PREFIX}/lib)
set(LLVM_DEFINITIONS "-D__STDC_LIMIT_MACROS" "-D__STDC_CONSTANT_MACROS")
# We try to include using the current setting of CMAKE_MODULE_PATH,
# which suppossedly was filled by the user with the directory where
# this file was installed:

View File

@ -0,0 +1 @@
set(PACKAGE_VERSION "@PACKAGE_VERSION@")

View File

@ -436,6 +436,26 @@
headers on the LLVM source directory (if we are building
out-of-source.)</p>
<p>Alternativaly, you can utilize CMake's <i>find_package</i>
functionality. Here is an equivalent variant of snippet shown above:</p>
<div class="doc_code">
<pre>
find_package(LLVM)
if( NOT LLVM_FOUND )
message(FATAL_ERROR "LLVM package can't be found. Set CMAKE_PREFIX_PATH variable to LLVM's installation prefix.")
endif()
include_directories( ${LLVM_INCLUDE_DIRS} )
link_directories( ${LLVM_LIBRARY_DIRS} )
llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native)
target_link_libraries(mycompiler ${REQ_LLVM_LIBRARIES})
</pre>
</div>
</div>
<!-- *********************************************************************** -->