[CMake] find both shared and static versions?

Dougal Sutherland dougal at gmail.com
Thu Feb 16 19:36:41 EST 2012


I have an application where I want to link some targets against shared
versions of Boost and some against static versions.

(I'd prefer shared in general, but I need to link against the static
version of boost for my matlab mex interface, to avoid loading the
different version of boost shipped by matlab on runtime. I'm using this
approach<https://github.com/mariusmuja/flann/blob/master/src/matlab/CMakeLists.txt>of
a custom target calling the mex command to compile the mex file.)

FindBoost.cmake honors the Boost_USE_STATIC_LIBS variable, but that doesn't
quite solve it.

I've had the following ideas, none of which I'm happy with:

   1. Use -L${Boost_LIBRARY_DIRS} and then construct the name by doing a
   string replacement from .so/.dylib to .a in ${Boost_THREAD_LIBRARY}.
   Definitely won't work on Windows, might not work for some types of Boost
   installations on Linux/Mac, and fails at link-time instead of
   configure-time if the static version doesn't exist. Maybe there's an
   equivalent transformation that'll probably work on Windows; I don't know,
   I'm not a Windows user.

   2. Copy FindBoost.cmake to FindBoostS.cmake and replace all the
   variables to use a BoostS prefix, as well as making the conditionals for
   USE_STATIC_LIBS always be on; then I can run find_package(Boost) as well as
   find_package(BoostS).

   3. There might be some trickery to approximate (2) without actually
   modifying FindBoost, but I haven't figured it out.

   4. Modify FindBoost.cmake either to look for both dynamic and shared
   libraries and set e.g. Boost_THREAD_LIBRARY_STATIC and
   Boost_THREAD_LIBRARY_SHARED if found, or to add shared and static versions
   for each component, as in
   http://www.cmake.org/pipermail/cmake/2012-February/049142.html

(4) is obviously the "best" approach, but it's also probably much more work
than I really want to do on this.

Any suggestions? Some other approach I haven't thought of, a way to do (3),
a copy of (4) floating around somewhere?

Thanks,
Dougal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120216/4f779e88/attachment.htm>


More information about the CMake mailing list