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 via email to