[CMake] How to specify library dependencies?

Michael Jackson mike.jackson at bluequartz.net
Mon Nov 24 15:41:03 EST 2008


On Nov 24, 2008, at 3:10 PM, Robert Dailey wrote:

> Hi,
>
> I need to be able to specify directories that the linker will search  
> to be able to find libraries it is to link against. For this, the  
> solution I've found is LINK_DIRECTORIES().
>
> Next, I need to be able to specify library files that the executable  
> will link against. I have no idea how to do this part. This needs to  
> be portable, so the only logical way I can think of doing this is to  
> use IF() conditionals for each different compiler/platform I intend  
> to support. For example (pseudocode):
>
> IF( platform is windows )
>  LINK_LIBRARIES( a.lib, b.lib, c.lib )
> ELSEIF( platform is linux )
>  LINK_LIBRARIES( a.o, b.o, c.o )
> ENDIF()
>
> This could get really messy, so I'm not sure how you guys would  
> typically handle this situation. Thanks for reading.


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?

_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio





More information about the CMake mailing list