[CMake] How to get list of generated object-files of OBJECT-library?

Deniz Bahadir deniz.bahadir at benocs.com
Mon Jul 17 11:13:00 EDT 2017


Am 17.07.2017 um 16:47 schrieb Nils Gladitz:
> On 7/17/2017 3:52 PM, Deniz Bahadir wrote:
>>
>> 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.
> 
> FWIW this was implemented in the upcoming 3.9:
> https://cmake.org/cmake/help/latest/module/CPackIFW.html#command:cpack_ifw_configure_component 
> 

Thank you for your answer, Nils, but I do not really see how this relates.
This command seems to address CPack, while I am still struggling with 
CMake building files (that later might be installed by CPack).


> 
> Nils

Deniz


More information about the CMake mailing list