[CMake] can I make an AUTOMOC generated file depend on something ?

Stephen Kelly steveire at gmail.com
Thu Mar 5 14:59:20 EST 2015


Kim Rydhof Thor Hansen wrote:

> On Wed, Feb 25, 2015 at 10:45 PM, Stephen Kelly <steveire at gmail.com>
> wrote:
>> Kim Rydhof Thor Hansen wrote:
>>
>>> 
http://www.cmake.org/cmake/help/v3.0/prop_tgt/AUTOGEN_TARGET_DEPENDS.html
>>>
>>> I have a similar problem because automoc doesn't pick up that my
>>> metadata.json file is a dependency to the generated moc_plugin.cpp
>>> when building a Qt plugin
>>
>> Thanks for the testcase. I filed
>>
>>  http://public.kitware.com/Bug/view.php?id=15419
>>
>> with more information on what should be done to fix this.
> 
> Thanks for your work on this.
> 
> I can't find a good workaround, I tried using autoget_target_depends
> without success but I suspect that it is because I have done something
> wrong.
> 
> Can anyone suggest a line to put in CMakeLists.txt in order to
> manually register the dependency between metadata.json and
> moc_plugin.cpp?

A workaround would have to be based on changing the timestamp of the .h 
file. Here's an ugly workround:

add_custom_command(
  OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/metadata.json"
  COMMAND ${CMAKE_COMMAND} -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/metadata.json.in" 
"${CMAKE_CURRENT_BINARY_DIR}/metadata.json"
  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/plugin.h.in" 
"${CMAKE_CURRENT_BINARY_DIR}/plugin.h"
  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/metadata.json.in" 
"${CMAKE_CURRENT_SOURCE_DIR}/plugin.h.in"
)

set_property(TARGET plugin PROPERTY AUTOGEN_TARGET_DEPENDS 
"${CMAKE_CURRENT_BINARY_DIR}/metadata.json")

Depending on how you order your include directories, you might not have to 
rename the .h.

Thanks,

Steve.





More information about the CMake mailing list