[CMake] portable way of linking (external) libs statically/dynamically/for dlopen

J Decker d3ck0r at gmail.com
Tue Apr 30 02:08:11 EDT 2013


Ya; additional generators might be nice 'static runtime' or 'dynamic
runtime' but that's only just the C runtime, and doesn't account for the
uncounted other libraries you may also depend on.

Although I suppose it would make sense that if it was 'static' that all
other related things should also be static; instead of choosing
specifically each one on a case-by-case basis.

Or maybe a different CMAKE_BUILD_TYPE .. debug, debug_static, etc...

maybe that's an option to add_executable( target STATIC sources )  (static
works for add_library() to choose a specific mode)


On Mon, Apr 29, 2013 at 6:44 PM, Philippe Cerfon <philcerf at gmail.com> wrote:

> On Tue, Apr 30, 2013 at 1:54 AM, J Decker <d3ck0r at gmail.com> wrote:
> >
> lib${CMAKE_LIBRARY_SUFFIX}/${CMAKE_SHARED_LIBRARY_PREFIX}c${CMAKE_SHARED_LIBRARY_SUFFIX}
> > or
> >
> lib${CMAKE_LIBRARY_SUFFIX}/${CMAKE_STATIC_LIBRARY_PREFIX}c${CMAKE_STATIC_LIBRARY_SUFFIX}
> >
> > to choose lib[64]/libc.so or lib[64]/libc.a  (or it would generate
> > c.dll/c.lib for windows type compilers)
> >
> > But, although you can generate portable projects that target lots of
> > platforms, the scripts still have to have things like
> >
> > if( WIN32 )
> > if( UNIX )
> > etc...
> Well exactly this is what I don't wan to do as it's not portable...
> _I_ (the developer) need to take care on any possible platorm, it's
> library naming conventions and possibly also on any compiler/linker
> suite I want to support...
> If the responsibility for this falls back to me, I can also build via
> shell script (more or less).
>
> What I'd like to have is:
> 1) My CMakeLists checks for all dependencies (e.g. lib foo) using the
> CMakes functions for that.
> These functions should tell me which versions were found (i.e. static
> or shared).
> 2) Depending on (1) I set CMake options cache with reasonable defaults
> (i.e. in most cases this will be "link lib foo dynamic") for each lib
> foo.
> For some I might even offer to use dlopen(), depending on whether my
> sources support this.
> 3) The user can then chance that settings per lib in the cache as he likes.
> 4) When I say target_link_library... I want to set some flag (static
> vs. shared) depending on what was chosen in (3) (or not link at all in
> case of dlopen()),
>
> Everything else, platform naming conventions, compiler/linker options,
> should happen automatically (for all supported platforms +
> compilter/linker suites)... that would be portability.
>
>
> Cheers!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130429/527d6008/attachment.htm>


More information about the CMake mailing list