export of CMake project

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

Jochen Wilhelmy <j.wilhelmy@arcor.de> writes:

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.

AFAIK exporting LLVM just provides the library names. How is that
useful? The really useful feature is to obtain the LLVM libraries from a
component name:

include($PATH_TO_LLVM_INSTALL/some-directory/llvm.cmake)

LLVM_LIBRARIES_FOR_COMPONENT(jit LLVM_LIBRARIES_I_NEED)

target_link_libraries(my_compiler $LLVM_LIBRARIES_I_NEED)

This is an often-requested feature. Maybe if I have some free time this
weekend...

[snip]