[CMake] Imported libraries and cross platform target names

Tamás Kenéz tamas.kenez at gmail.com
Wed Aug 19 17:30:03 EDT 2015


Anthony, instead of `find_library` I do think you should look into the
config-module feature and the command `install(EXPORT ...)` which helps you
generating them, as Nils Gladitz has already suggested. As you wrote, these
libraries are already building from CMakeLists so you don't even need to
cmakefy them.

Tamas

On Tue, Aug 18, 2015 at 8:51 PM, Ette, Anthony (CDS) <
Anthony.R.Ette at controlsdata.com> wrote:

> Thank you for the response, I will look into find_library.  Note however
> that these static libraries are ours built from a separate CMake project
> (so I always know where they are “installed”).
>
>
>
>
> *Anthony Ette *Control Systems Engineer
>
>
>
> Rolls-Royce Controls and Data Services
>
> 7661 N Perimeter Rd
>
> Indianapolis, IN 46241
>
> tel: +1 (317) 230-6943
>
> mob: +1 (317) 864-7975
>
> email: Anthony.R.Ette at controlsdata.com
>
>
>
> *From:* Miller Henry [mailto:MillerHenry at JohnDeere.com]
> *Sent:* Tuesday, August 18, 2015 2:44 PM
> *To:* Ette, Anthony (CDS); CMake at cmake.org
> *Subject:* RE: Imported libraries and cross platform target names
>
>
>
> Use find_library to find the library.  You will probably need this anyway
> because different systems install libraries in different locations.
>
>
>
> http://www.cmake.org/cmake/help/v3.3/command/find_library.html
>
>
>
>
>
> *From:* CMake [mailto:cmake-bounces at cmake.org <cmake-bounces at cmake.org>] *On
> Behalf Of *Ette, Anthony (CDS)
> *Sent:* Tuesday, August 18, 2015 1:30 PM
> *To:* CMake at cmake.org
> *Subject:* [CMake] Imported libraries and cross platform target names
> *Importance:* High
>
>
>
> Given that add_library() produces a unique filename per platform (the “actual
> file name of the library built is constructed based on conventions of the
> native platform (such as lib<name>.a or<name>.lib”), how does one add the
> library to the final application without having to deal with the filename
> difference?  In other words, I’ve got one library that, by default,
> produces ‘libtest.a’ on Linux and ‘test.lib’ on Windows.  How can I add
> this imported library into the final application in a cross platform
> manner?  I know I can specify two different imported locations (see below),
> but it seems odd to me that Cmake – the cross-platform build env generator
> – doesn’t have a better native way of dealing with this….
>
>
>
> The snippet below will work, but just seems wrong given the nature of what
> CMake is intended to do…is there a better way that I’m missing?!  If not,
> can I request that a future release of Cmake handle platform naming
> convention difference internally when invoking ADD_LIBRARY with the
> IMPORTED tag set?  Ok so, to be fair, Cmake can be used to cross compile
> and that certainly complicates my feature request but, when not cross
> compiling, CMake knows what platform it’s being executed on so it should be
> able to resolve static archive platform decorations internally.
>
>
>
> ADD_LIBRARY(test STATIC IMPORTED)
>
> if(WIN32)
>
>    SET_PROPERTY(TARGET test PROPERTY IMPORTED_LOCATION ${LIB_D}/timer.lib)
>
> endif()
>
> if(UNIX)
>
>    SET_PROPERTY(TARGET test PROPERTY IMPORTED_LOCATION
> ${LIB_D}/libtimer.a)
>
> endif()
>
>
>
> Thanks in advance,
>
>
> *Anthony Ette *Control Systems Engineer
>
>
>
> Rolls-Royce Controls and Data Services
>
> 7661 N Perimeter Rd
>
> Indianapolis, IN 46241
>
> tel: +1 (317) 230-6943
>
> mob: +1 (317) 864-7975
>
> email: Anthony.R.Ette at controlsdata.com
>
>
>
> This e-mail (including attachments) contains contents owned by Rolls-Royce
> plc and its subsidiaries, affiliated companies or customers and covered by
> the laws of England and Wales, Brazil, US, or Canada (federal, state or
> provincial). The information contained in this email is intended to be
> confidential, may be legally privileged and subject to export controls
> which may restrict the access to and transfer of the information. If you
> are not the intended recipient, you are hereby notified that any retention,
> dissemination, distribution, interception or copying of this communication
> is strictly prohibited and may subject you to further legal action. Reply
> to the sender if you received this email by accident, and then delete the
> email and any attachments.
>
>
> ______________________________________________________________________
> This email has been scanned.
> This e-mail (including attachments) contains contents owned by Rolls-Royce
> plc and its subsidiaries, affiliated companies or customers and covered by
> the laws of England and Wales, Brazil, US, or Canada (federal, state or
> provincial). The information contained in this email is intended to be
> confidential, may be legally privileged and subject to export controls
> which may restrict the access to and transfer of the information. If you
> are not the intended recipient, you are hereby notified that any retention,
> dissemination, distribution, interception or copying of this communication
> is strictly prohibited and may subject you to further legal action. Reply
> to the sender if you received this email by accident, and then delete the
> email and any attachments.
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150819/ffd12b7d/attachment.html>


More information about the CMake mailing list