Getting the path to object files?

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

Getting the path to object files?

Paul Smith
Hi all.  I'm using CMake 3.13.4 across Linux, MacOS, and Windows, with
various generators.

I need to write a script (this only runs on Linux actually) that will
do some processing on all the object files in a shared library and
generate a linker version file.  I'm trying to write a custom command
using PRE_LINK that will invoke that script and pass along enough
information to find all those object files so it can generate the
version file, and I can't come up with it.

For example, using a Makefile generator for a file "libsrc.cpp" built
for a library "solib" in a directory "LibDir" on Linux my object file
paths look like:

  LibDir/CMakeFiles/solib.dir/libsrc.cpp.o

I can use something like this:

  get_target_property(srcs solib SOURCES)

  add_custom_command(TARGET solib PRE_LINK
      COMMAND foo ${srcs}
      VERBATIM)

(for some reason if I try to use a generator expression like
$<TARGET_PROPERTY:SOURCES> etc. it's always passed as a single quoted
argument and I can't figure out how break it up, but if I use
get_target_property() then it works correctly).

However this only gives me the source file names, not the object file
names, and no directory information to search.  My problem is I'm
actually compiling these same source files multiple times in different
ways for different libraries, so I can't just search for "libsrc.cpp.o"
I need to get this particular .o.

So then I added $<TARGET_PROPERTY:BINARY_DIR> which looked promising,
but it only gives me the path to the source directory; i.e. above it
gives me LibDir.

I tried lots of different likely-looking properties, but I can't find
any property which will tell me the path I'm looking for.

Can I get CMake to tell me the path where the object files being
created will be put for a given target?  Or do I just need to hard-code
it based on my observations of how cmake generators actually create the
output?

--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Getting the path to object files?

CMake mailing list
CMake only provides an official way to get the location of the object
files for OBJECT targets ( $<TARGET_OBJECTS:objLib> ). For other
target types the location is an implementation detail.

On Sat, Feb 23, 2019 at 3:24 PM Paul Smith <[hidden email]> wrote:

>
> Hi all.  I'm using CMake 3.13.4 across Linux, MacOS, and Windows, with
> various generators.
>
> I need to write a script (this only runs on Linux actually) that will
> do some processing on all the object files in a shared library and
> generate a linker version file.  I'm trying to write a custom command
> using PRE_LINK that will invoke that script and pass along enough
> information to find all those object files so it can generate the
> version file, and I can't come up with it.
>
> For example, using a Makefile generator for a file "libsrc.cpp" built
> for a library "solib" in a directory "LibDir" on Linux my object file
> paths look like:
>
>   LibDir/CMakeFiles/solib.dir/libsrc.cpp.o
>
> I can use something like this:
>
>   get_target_property(srcs solib SOURCES)
>
>   add_custom_command(TARGET solib PRE_LINK
>       COMMAND foo ${srcs}
>       VERBATIM)
>
> (for some reason if I try to use a generator expression like
> $<TARGET_PROPERTY:SOURCES> etc. it's always passed as a single quoted
> argument and I can't figure out how break it up, but if I use
> get_target_property() then it works correctly).
>
> However this only gives me the source file names, not the object file
> names, and no directory information to search.  My problem is I'm
> actually compiling these same source files multiple times in different
> ways for different libraries, so I can't just search for "libsrc.cpp.o"
> I need to get this particular .o.
>
> So then I added $<TARGET_PROPERTY:BINARY_DIR> which looked promising,
> but it only gives me the path to the source directory; i.e. above it
> gives me LibDir.
>
> I tried lots of different likely-looking properties, but I can't find
> any property which will tell me the path I'm looking for.
>
> Can I get CMake to tell me the path where the object files being
> created will be put for a given target?  Or do I just need to hard-code
> it based on my observations of how cmake generators actually create the
> output?
>
> --
>
> 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:
> https://cmake.org/mailman/listinfo/cmake
--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Getting the path to object files?

Paul Smith
On Wed, 2019-02-27 at 08:39 -0500, Robert Maynard wrote:
> CMake only provides an official way to get the location of the object
> files for OBJECT targets ( $<TARGET_OBJECTS:objLib> ). For other
> target types the location is an implementation detail.

Yes, but sometimes (as in my case) I need to know it :).  I need to
examine the object files as part of my link processing.

Exactly _because_ it's an implementation detail, it would be nice if
there were some way to retrieve it from CMake.  I can file an
enhancement request if that seems appropriate.

I could use an OBJECT target if it weren't for the Xcode restriction
that a STATIC or SHARED library must have at least one source file and
can't consist solely of an OBJECT library.

I'm hopeful we can throw away our MacOS builds entirely but until that
happens...


Thanks for the reply Robert!

--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Getting the path to object files?

CMake mailing list
You can file an enhancement request that the $<TARGET_OBJECTS>
generator expression to be relaxed to include STATIC, SHARED, and
MODULE libraries.

My suggestion is that a dummy source file to workaround the Xcode
limitation on targets, is not as hacky
as reverse engineering the object file locations.


On Wed, Feb 27, 2019 at 9:06 AM Paul Smith <[hidden email]> wrote:

>
> On Wed, 2019-02-27 at 08:39 -0500, Robert Maynard wrote:
> > CMake only provides an official way to get the location of the object
> > files for OBJECT targets ( $<TARGET_OBJECTS:objLib> ). For other
> > target types the location is an implementation detail.
>
> Yes, but sometimes (as in my case) I need to know it :).  I need to
> examine the object files as part of my link processing.
>
> Exactly _because_ it's an implementation detail, it would be nice if
> there were some way to retrieve it from CMake.  I can file an
> enhancement request if that seems appropriate.
>
> I could use an OBJECT target if it weren't for the Xcode restriction
> that a STATIC or SHARED library must have at least one source file and
> can't consist solely of an OBJECT library.
>
> I'm hopeful we can throw away our MacOS builds entirely but until that
> happens...
>
>
> Thanks for the reply Robert!
>
--

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:
https://cmake.org/mailman/listinfo/cmake