[CMake] How to specify library dependencies?

Alexander Neundorf a.neundorf-work at gmx.net
Mon Nov 24 16:39:59 EST 2008


On Monday 24 November 2008, Robert Dailey wrote:
> On Mon, Nov 24, 2008 at 2:41 PM, Michael Jackson <
>
> mike.jackson at bluequartz.net> wrote:
> > typically you do:
> >
> > add_executable(main  main.cpp)
> > target_link_libraries(main a)
> >
> > and CMake _usually_ picks the correct library for the given platform
> > (a.lib, a.so, a.dylib... )
> >
> > Is that what you were asking?
>
> Yes, you did answer my question exactly, however I did not specify the more
> complex issue.
>
> Some libraries we're using have different library names depending on the
> platform. For example:
>
> a_windows.lib
> a_linux.o
>
> This is why I believed I would need the conditional logic. What would you
> do in this case? Thanks for your help.

You could do:
if(WIN32)
   set(libName a_windows)
else(WIN32)
   set(libName a_linux)
endif(WIN32)

find_library(MY_LIBRARY ${libName})

target_link_libraries(hello ${MY_LIBRARY})

(with error checking and checking CMAKE_SYSTEM for Linux)

Alex


More information about the CMake mailing list