[CMake] How to import platform-independent library with add_library()?

Alexander Neundorf a.neundorf-work at gmx.net
Fri Dec 14 14:27:41 EST 2012


On Friday 14 December 2012, Reza Housseini wrote:
> On Fri, Dec 14, 2012 at 11:47 AM, Andreas Pakulat <apaku at gmx.de> wrote:
> > Hi,
> > 
> > On Fri, Dec 14, 2012 at 11:16 AM, Reza Housseini <reza.housseini at gmx.ch> 
wrote:
> >> Hello Guys
> >> 
> >> I try to import a library and was now wondering if there's a
> >> platform-independent way?
> > 
> > Not in the sense that CMake would handle this for you magically. At
> > least not when importing libraries that are not shipping with a
> > corresponding cmake file that sets this stuff up.
> > 
> > Andreas
> 
> I found the solution, I had to use the find_library command and
> specify the PATHS variable.
> 
>   find_library(MYLIB mylib
>     PATHS ${CPPLIB_DIR}
>   )
> 

You could also use the ${CMAKE_STATIC_LIBRARY_PREFIX}, 
${CMAKE_STATIC_LIBRARY_SUFFIX}, ${CMAKE_SHARED_LIBRARY_PREFIX} and 
${CMAKE_SHARED_LIBRARY_SUFFIX} cmake variables to construct the filename:

set_target_properties(mylib PROPERTIES
    IMPORTED_LOCATION 
${CPPLIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}mylib${CMAKE_SHARED_LIBRARY_SUFFIX})

Alex


More information about the CMake mailing list