Hi list,

I have a question regarding "add_custom_command" and OBJECT-libraries:

My CMakeLists.txt contains the following (simplified) targets:

```
set ( SOURCE_FILES
    # ... several C++-source files
)
add_library( OBJECT ${PROJECT_NAME}_OBJECTS
    ${SOURCE_FILES}
)
add_library( ${PROJECT_NAME}
   $<TARGET_OBJECTS:${PROJECT_NAME}_OBJECTS>
)
```

This works just fine. However, now I want to add an additional build-step after creation of the object-files and before linking the shared library. (In particular, I want to compress the debug-symbols in the object-files. But that should be irrelevant for my question.)

My first attempt was to add the following between the two add_library commands:
```
add_custom_command( TARGET ${PROJECT_NAME}_OBJECTS POST_BUILD
COMMAND objcopy --compress-debug-sections $<TARGET_OBJECTS:${PROJECT_NAME}_OBJECT>
)
```
But that results in the following error:
```
(add_custom_command):
  Target "MyProject_OBJECTS" is an OBJECT library that may not
  have PRE_BUILD, PRE_LINK, or POST_BUILD commands.
```

So I tried instead to add the following between the two add_library commands:
```
add_custom_command( TARGET ${PROJECT_NAME} PRE_LINK
COMMAND objcopy --compress-debug-sections $<TARGET_OBJECTS:${PROJECT_NAME}_OBJECT>
)
```
This then fails when evaluating the generator-expression:
```
(add_custom_command):
  Error evaluating generator expression:

    $<TARGET_OBJECTS:MyProject_OBJECTS>

The evaluation of the TARGET_OBJECTS generator expression is only suitable
  for consumption by CMake.  It is not suitable for writing out elsewhere.
```

So I am currently out of ideas (which do not make the CMakeLists.txt file completely unmaintainable). Therefore my question is:

How can I retrieve the list of generated object-files so that I can pass it to another program that should be run as additional build-step before linking?

IMHO, the most comfortable (and syntactically cleanest) way would be my first attempt. But that is probably more a feature-request than a simple question.


Thanks for your help.
Deniz Bahadir

--

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

Reply via email to