[CMake] How to build and reference dlopen-able libraries?

Ted Middleton middleton.ted at gmail.com
Fri Sep 5 18:44:05 EDT 2014


Just wondering if there's a nice way of getting a library target's includes
but not linking to it, so I can use dlopen() on it instead. If I want to
build a shared library that gets implicitly loaded by an executable, I
would do this:

  mylib/CMakeLists.txt:
  add_library( mylib SHARED src/mylibmain.c src/mylibsomething.c )
  target_include_directories( mylib PRIVATE src PUBLIC inc )
  target_link_libraries( mylib png )

  myexe/CMakeLists.txt:
  add_executable( myexe src/main.c src/stuff.c )
  target_include_directories( myexe PRIVATE src )
  target_link_libraries( myexe PRIVATE mylib )

What I really want, though, is for mylib's public include dir to be
accessible to myexe, but I don't want myexe to link to mylib - I'm going to
load it with dlopen()/LoadLibrary(). Do I have to do something like this:

  myexe/CMakeLists.txt:
  get_property( mylibincs TARGET mylib PROPERTY
INTERFACE_INCLUDE_DIRECTORIES )
  add_executable( myexe src/main.c src/stuff.c )
  target_include_directories( myexe PRIVATE src ${mylibincs} )
  #target_link_libraries not necessary


This must be really simple, but I can't seem to find anything about it on
the cmake wikis or through google. There's a very old post from 2006 or so
(pre target properties, it uses include_directories()).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140905/569665e5/attachment.html>


More information about the CMake mailing list