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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Reza Housseini
Hello Guys

I try to import a library and was now wondering if there's a
platform-independent way?
Here's my code:

  add_library(mylib SHARED IMPORTED)
  set_target_properties(mylib PROPERTIES
    IMPORTED_LOCATION ${CPPLIB_DIR}/libmylib.so)

But now what about using this CMakeLists.txt file under Windows? Can't
I just specifie a path? When I do so I get the following error message
from the linker:

  /usr/bin/ld: cannot find ../../core/build: File format not recognized

So he is just linking the path instead of the library.

Thanks for your help!
Cheers Reza
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to import platform-independent library with add_library()?

Andreas Pakulat-2
Hi,

On Fri, Dec 14, 2012 at 11:16 AM, Reza Housseini <[hidden email]> 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
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to import platform-independent library with add_library()?

Reza Housseini
On Fri, Dec 14, 2012 at 11:47 AM, Andreas Pakulat <[hidden email]> wrote:

> Hi,
>
> On Fri, Dec 14, 2012 at 11:16 AM, Reza Housseini <[hidden email]> 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}
  )

Thank you anyway!
Regards
Reza
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to import platform-independent library with add_library()?

Alexander Neundorf-3
On Friday 14 December 2012, Reza Housseini wrote:
> On Fri, Dec 14, 2012 at 11:47 AM, Andreas Pakulat <[hidden email]> wrote:
> > Hi,
> >
> > On Fri, Dec 14, 2012 at 11:16 AM, Reza Housseini <[hidden email]>
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
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake