Hi!
I'm porting my own projects to CMake (seems very cool) and I want to
import LLVM as external libraries.
To simplify this CMake supports an export feature that can export an
LLVM.cmake file that lists all libraries of LLVM. With this I could
simplify the use of LLVM in my own CMake project.
For this the following cmake files of LLVM have to be extended
(patches are provided at the end of this message).
In AddLLVM.cmake one line has to be added:
macro(add_llvm_library name)
...
install(TARGETS ${name}
EXPORT LLVM
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
...
At the end of the main CMakeLists.txt we need to install the LLVM export
file:
# install LLVM package
install(EXPORT LLVM DESTINATION cmake)
In my own project I just need to do the following:
# import llvm
find_path(LLVM_CMAKE_DIR llvm.cmake)
include(${LLVM_CMAKE_DIR}/llvm.cmake)
...
# set dependencies
target_link_libraries(MyProjectUsingLLVM
LLVMSupport
LLVMSystem
... all llvm and cmake libs ...
)
-Jochen
-- here the patch for llvm --
Index: cmake/modules/AddLLVM.cmake
==================================================================---
cmake/modules/AddLLVM.cmake (revision 104943)
+++ cmake/modules/AddLLVM.cmake (working copy)
@@ -10,6 +10,7 @@
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
endif( LLVM_COMMON_DEPENDS )
install(TARGETS ${name}
+ EXPORT LLVM
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
# The LLVM Target library shall be built before its sublibraries
Index: CMakeLists.txt
==================================================================---
CMakeLists.txt (revision 104943)
+++ CMakeLists.txt (working copy)
@@ -394,4 +394,7 @@
PATTERN ".svn" EXCLUDE
)
+# install LLVM package
+install(EXPORT LLVM DESTINATION cmake)
+
# TODO: make and install documentation.
-- here the patch for clang --
Index: CMakeLists.txt
==================================================================---
CMakeLists.txt (revision 104943)
+++ CMakeLists.txt (working copy)
@@ -85,6 +85,7 @@
set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
endif(MSVC)
install(TARGETS ${name}
+ EXPORT LLVM
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
endmacro(add_clang_library)