Fully support add_custom_command (with PRE_BUILD/POST_BUILD) with OBJECT-libraries
Currently (with CMake 3.9-rc6), when trying to add a custom build-command to an OBJECT-library cmaking fails with the following error message:
(add_custom_command):
Target "MyProject_OBJECTS" is an OBJECT library that may not
have PRE_BUILD, PRE_LINK, or POST_BUILD commands.
The important sections of the associated CMakeFile.txt
look like this:
set ( SOURCE_FILES
# ... several C++-source files
)
add_library( ${PROJECT_NAME}_OBJECTS OBJECT
${SOURCE_FILES}
)
add_custom_command( TARGET ${PROJECT_NAME}_OBJECTS POST_BUILD
COMMAND bash -c "for i in $(echo '$<TARGET_OBJECTS:${PROJECT_NAME}_OBJECTS>' | tr '[;]' ' '); do objcopy --compress-debug-sections $i; done"
COMMENT "Compress debug-sections of object-files"
VERBATIM
)
It would be great if OBJECT-libraries would fully support this ("build-event") form of add_custom_command
.
Additionally, if using Ninja-generator it would be great if Ninja would not try to rebuild the modified object-files after the POST_BUILD
step. (As Ninja compares hashes of object-files to check if it needs to rebuilds these object-files, it should use as original hash the one created after the custom POST_BUILD
step.)
For further information see this conversation on the CMake mailing-list: http://cmake.3232098.n2.nabble.com/How-to-get-list-of-generated-object-files-of-OBJECT-library-td7595824.html
Refs: #14778 (closed)