llvm.org GIT mirror llvm / 3447b4f
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 Oscar Fuentes 9 years ago
5 changed file(s) with 81 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
0 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/share/llvm/cmake")
1 set(LLVM_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
12
23 get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS)
34
45 configure_file(
5 LLVM.cmake
6 ${llvm_cmake_builddir}/LLVM.cmake
6 LLVMConfig.cmake.in
7 ${llvm_cmake_builddir}/LLVMConfig.cmake
8 @ONLY)
9
10 configure_file(
11 LLVMConfigVersion.cmake.in
12 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
713 @ONLY)
814
915 install(FILES
10 ${llvm_cmake_builddir}/LLVM.cmake
16 ${llvm_cmake_builddir}/LLVMConfig.cmake
17 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
1118 LLVM-Config.cmake
1219 LLVMLibDeps.cmake
1320 DESTINATION share/llvm/cmake)
1623 DESTINATION share/llvm/cmake
1724 FILES_MATCHING PATTERN *.cmake
1825 PATTERN .svn EXCLUDE
19 PATTERN LLVM.cmake EXCLUDE
26 PATTERN LLVMConfig.cmake EXCLUDE
27 PATTERN LLVMConfigVersion.cmake EXCLUDE
2028 PATTERN LLVM-Config.cmake EXCLUDE
2129 PATTERN LLVMLibDeps.cmake EXCLUDE
2230 PATTERN FindBison.cmake EXCLUDE
2432 PATTERN VersionFromVCS.cmake EXCLUDE
2533 PATTERN CheckAtomic.cmake EXCLUDE)
2634
35 #remove this?
2736 install(FILES
28 ${llvm_cmake_builddir}/LLVM.cmake
37 ${llvm_cmake_builddir}/LLVMConfig.cmake
38 ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
2939 LLVM-Config.cmake
3040 LLVMLibDeps.cmake
3141 DESTINATION share/llvm/cmake)
+0
-40
cmake/modules/LLVM.cmake less more
None # This file provides information and services to the final user.
1
2 set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@)
3
4 set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@)
5
6 set_property( GLOBAL PROPERTY LLVM_LIBS "@llvm_libs@")
7
8 set(LLVM_ALL_TARGETS @LLVM_ALL_TARGETS@)
9
10 set(LLVM_TARGETS_TO_BUILD @LLVM_TARGETS_TO_BUILD@)
11
12 set(TARGET_TRIPLE "@TARGET_TRIPLE@")
13
14 set(LLVM_TOOLS_BINARY_DIR @LLVM_TOOLS_BINARY_DIR@)
15
16 set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)
17
18 set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)
19
20 set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
21
22 set(HAVE_LIBDL @HAVE_LIBDL@)
23 set(HAVE_LIBPTHREAD @HAVE_LIBPTHREAD@)
24 set(LLVM_ON_UNIX @LLVM_ON_UNIX@)
25 set(LLVM_ON_WIN32 @LLVM_ON_WIN32@)
26
27 # We try to include using the current setting of CMAKE_MODULE_PATH,
28 # which suppossedly was filled by the user with the directory where
29 # this file was installed:
30 include( LLVM-Config OPTIONAL RESULT_VARIABLE LLVMCONFIG_INCLUDED )
31
32 # If failed, we assume that this is an un-installed build:
33 if( NOT LLVMCONFIG_INCLUDED )
34 set(CMAKE_MODULE_PATH
35 ${CMAKE_MODULE_PATH}
36 "@LLVM_SOURCE_DIR@/cmake/modules")
37 include( LLVM-Config )
38 endif()
39
0 # This file provides information and services to the final user.
1
2 set(LLVM_PACKAGE_VERSION @PACKAGE_VERSION@) #remove this?
3
4 set(LLVM_COMMON_DEPENDS @LLVM_COMMON_DEPENDS@)
5
6 set_property( GLOBAL PROPERTY LLVM_LIBS "@llvm_libs@")
7
8 set(LLVM_ALL_TARGETS @LLVM_ALL_TARGETS@)
9
10 set(LLVM_TARGETS_TO_BUILD @LLVM_TARGETS_TO_BUILD@)
11
12 set(TARGET_TRIPLE "@TARGET_TRIPLE@")
13
14 set(LLVM_TOOLS_BINARY_DIR @LLVM_TOOLS_BINARY_DIR@)
15
16 set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)
17
18 set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)
19
20 set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
21
22 set(HAVE_LIBDL @HAVE_LIBDL@)
23 set(HAVE_LIBPTHREAD @HAVE_LIBPTHREAD@)
24 set(LLVM_ON_UNIX @LLVM_ON_UNIX@)
25 set(LLVM_ON_WIN32 @LLVM_ON_WIN32@)
26
27 set(LLVM_INSTALL_PREFIX @LLVM_INSTALL_PREFIX@)
28 set(LLVM_INCLUDE_DIRS ${LLVM_INSTALL_PREFIX}/include)
29 set(LLVM_LIBRARY_DIRS ${LLVM_INSTALL_PREFIX}/lib)
30 set(LLVM_DEFINITIONS "-D__STDC_LIMIT_MACROS" "-D__STDC_CONSTANT_MACROS")
31
32 # We try to include using the current setting of CMAKE_MODULE_PATH,
33 # which suppossedly was filled by the user with the directory where
34 # this file was installed:
35 include( LLVM-Config OPTIONAL RESULT_VARIABLE LLVMCONFIG_INCLUDED )
36
37 # If failed, we assume that this is an un-installed build:
38 if( NOT LLVMCONFIG_INCLUDED )
39 set(CMAKE_MODULE_PATH
40 ${CMAKE_MODULE_PATH}
41 "@LLVM_SOURCE_DIR@/cmake/modules")
42 include( LLVM-Config )
43 endif()
44
0 set(PACKAGE_VERSION "@PACKAGE_VERSION@")
435435 headers on the LLVM source directory (if we are building
436436 out-of-source.)

437437
438

Alternativaly, you can utilize CMake's find_package

439 functionality. Here is an equivalent variant of snippet shown above:

440
441
442

                  
                
443 find_package(LLVM)
444
445 if( NOT LLVM_FOUND )
446 message(FATAL_ERROR "LLVM package can't be found. Set CMAKE_PREFIX_PATH variable to LLVM's installation prefix.")
447 endif()
448
449 include_directories( ${LLVM_INCLUDE_DIRS} )
450 link_directories( ${LLVM_LIBRARY_DIRS} )
451
452 llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native)
453
454 target_link_libraries(mycompiler ${REQ_LLVM_LIBRARIES})
455
456
457
438458
439459
440460