Linking to the LLVM shared library

The LLVM 2.7 release notes say you can use ./configure --enable-shared
to build LLVM as a shared library (libLLVM2.7.so), and the LLVM tools
will link against that instead of including the static libraries, so I
was wondering:

Is there a way to configure LLVM the same way using CMake (so it can
work on Windows)?

In the other direction, is there an equivalent ./configure flag to
setting CMake's LLVM_BUILD_TOOLS to "Off", like --disable-tools?

And is there a way to get llvm-config to output --libs/--ldflags that
will make third-party programs link dynamically instead of statically?
If there isn't a way, can that be added in 2.8? It'd be useful if
you're building more than one binary against LLVM and want to avoid
unnecessary file size bloat.

Thanks!

nobled <nobled@dreamwidth.org> writes:

The LLVM 2.7 release notes say you can use ./configure --enable-shared
to build LLVM as a shared library (libLLVM2.7.so), and the LLVM tools
will link against that instead of including the static libraries, so I
was wondering:

Is there a way to configure LLVM the same way using CMake (so it can
work on Windows)?

There is no way right now. It could be easily implemented for MinGW, but
not for MSVC. The binutils included with MinGW do not require
__declspec(dllexport/dllimport) for exporting/importing symbols on dlls.

[snip]

Okay, but in the *general* case, how do I configure LLVM that way with
CMake (not necessarily on Windows)? running `cmake -i` never gives any
option that looks like "compile a shared library". Do the ./configure
and cmake ways of compiling not have parity, options-wise?

nobled <nobled@dreamwidth.org> writes:

The LLVM 2.7 release notes say you can use ./configure --enable-shared
to build LLVM as a shared library (libLLVM2.7.so), and the LLVM tools
will link against that instead of including the static libraries, so I
was wondering:

Is there a way to configure LLVM the same way using CMake (so it can
work on Windows)?

There is no way right now. It could be easily implemented for MinGW, but
not for MSVC. The binutils included with MinGW do not require
__declspec(dllexport/dllimport) for exporting/importing symbols on dlls.

[snip]

Okay, but in the *general* case, how do I configure LLVM that way with
CMake (not necessarily on Windows)? running `cmake -i` never gives any
option that looks like "compile a shared library". Do the ./configure
and cmake ways of compiling not have parity, options-wise?

No options-wise. Maybe some functionality-wise.

On cmake, when you want to generate shared libraries, you pass
-DBUILD_SHARED_LIBS That's a general cmake option, i.e. it should work
on all projects that use cmake (as far as they make sense for each
specific project.)

AFAIK, the `configure&make' build had so-so support for shared
libraries. Maybe that is fixed now. What they implemented recently was
one option for generating a single shared library containing all LLVM.

Right, that was my original question--when you build libLLVM2.7.so
with --enable-shared, LLVM's own tools link against it, but how do you
link third-party sources against it (instead of the individual shared
libs)? Is there an llvm-config option that will give the
cflags/ldflags for that? (and if there isn't, would it be easy to add
one for 2.8?)

nobled <nobled@dreamwidth.org> writes:

AFAIK, the `configure&make' build had so-so support for shared
libraries. Maybe that is fixed now. What they implemented recently was
one option for generating a single shared library containing all LLVM.

Right, that was my original question--when you build libLLVM2.7.so
with --enable-shared, LLVM's own tools link against it, but how do you
link third-party sources against it (instead of the individual shared
libs)? Is there an llvm-config option that will give the
cflags/ldflags for that? (and if there isn't, would it be easy to add
one for 2.8?)

If the library file name is libLLVM2.7.so just add -lLLVM2.7 instead
of the usual list of LLVM libraries to the link command.

I realize that, but that's a workaround that requires assuming I know
what version I'm linking against, what -L directory it was installed
in, and that it was definitely named libLLVM(versionnumber). That's
all information that llvm-config can provide automagically for the
static libs (I mean, I could just add a bunch of -lLLVM{module}s in
their case too, but I'd rather not..), but it doesn't ATM for the
shared lib.