Quantcast

Add dependencies to the automoc/autorcc target?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Add dependencies to the automoc/autorcc target?

Yves Frederix
Hi all,

I have a situation in which I would need to define a dependency for
the automoc target. Is it possible to do this somehow?

Basically, I have a setup in which a resource that is to be embedded
is generated by another target. However, due to parallelism in the
build and the lack of a dependency of the _automoc target on this
target, I often get an error like :

   RCC: Error in '.../build/resources.qrc': Cannot find file
'../build/myfile.txt'

I tried adding a dependency using add_dependencies, but this doesn't
seem to work.

Minimal example code is below (you will need to create an empty
main.cpp though). I am using CMake 3.7.1 with a VS generator. My build
command looks like 'cmake --build . -- -m'.


cmake_minimum_required(VERSION 3.7)

project(test CXX)

find_package(Qt5Quick REQUIRED)

set(CMAKE_AUTORCC ON)

# Define target that generates some files.
add_custom_target(generate_files)
add_custom_command(TARGET generate_files COMMAND sleep 1) # Wait a bit...
add_custom_command(TARGET generate_files COMMAND ${CMAKE_COMMAND} -E touch
  ${CMAKE_BINARY_DIR}/myfile.txt)

# Write the .qrc file for embedding these generated files.
file(WRITE ${CMAKE_BINARY_DIR}/resources.qrc
  "<!DOCTYPE RCC><RCC
  version=\"1.0\">\n<qresource>\n<file>${CMAKE_BINARY_DIR}/myfile.txt</file>\n</qresource>\n</RCC>")

add_library(foo SHARED main.cpp ${CMAKE_BINARY_DIR}/resources.qrc)
add_dependencies(foo generate_files)
target_link_libraries(foo PRIVATE Qt5::Quick)


Thanks!

Regards,
Yves
--

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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add dependencies to the automoc/autorcc target?

Jakob van Bethlehem
Hej Yves,

The problem is that the 'add_custom_command' does *NOT* create a new target, which seems to be what you assume, see https://cmake.org/cmake/help/v3.0/command/add_custom_command.html

The signature you're using is supposed to be used to *add* a custom command to an *existing* target. In other words, it should read:

add_custom_command(TARGET foo PRE_BUILD COMMAND ${CMAKE_COMMAND} -E touch
  ${CMAKE_BINARY_DIR}/myfile.txt)

(and hopefully it is immediately obvious that the 'sleep' command should go - CMake will never execute that command)

Sincerely,
Jakob

On Tue, Jan 17, 2017 at 12:02 PM, Yves Frederix <[hidden email]> wrote:
Hi all,

I have a situation in which I would need to define a dependency for
the automoc target. Is it possible to do this somehow?

Basically, I have a setup in which a resource that is to be embedded
is generated by another target. However, due to parallelism in the
build and the lack of a dependency of the _automoc target on this
target, I often get an error like :

   RCC: Error in '.../build/resources.qrc': Cannot find file
'../build/myfile.txt'

I tried adding a dependency using add_dependencies, but this doesn't
seem to work.

Minimal example code is below (you will need to create an empty
main.cpp though). I am using CMake 3.7.1 with a VS generator. My build
command looks like 'cmake --build . -- -m'.


cmake_minimum_required(VERSION 3.7)

project(test CXX)

find_package(Qt5Quick REQUIRED)

set(CMAKE_AUTORCC ON)

# Define target that generates some files.
add_custom_target(generate_files)
add_custom_command(TARGET generate_files COMMAND sleep 1) # Wait a bit...
add_custom_command(TARGET generate_files COMMAND ${CMAKE_COMMAND} -E touch
  ${CMAKE_BINARY_DIR}/myfile.txt)

# Write the .qrc file for embedding these generated files.
file(WRITE ${CMAKE_BINARY_DIR}/resources.qrc
  "<!DOCTYPE RCC><RCC
  version=\"1.0\">\n<qresource>\n<file>${CMAKE_BINARY_DIR}/myfile.txt</file>\n</qresource>\n</RCC>")

add_library(foo SHARED main.cpp ${CMAKE_BINARY_DIR}/resources.qrc)
add_dependencies(foo generate_files)
target_link_libraries(foo PRIVATE Qt5::Quick)


Thanks!

Regards,
Yves
--

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


--

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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add dependencies to the automoc/autorcc target?

Yves Frederix
Hi Jacob,

Thanks for your answer. I am aware that add_custom_command() does not
create a target, hence the call to add_custom_target(generate_files),
followed by add_custom_command(TARGET generate_files...).

The presence of the sleep command is for illustration purposes only.
It delays the generation of 'myfile.txt' so that I can illustrate the
problem (in a parallel build the autorcc will be started before the
file is generated and the error will be shown).

Regards,
Yves

On Tue, Jan 17, 2017 at 12:47 PM, Jakob van Bethlehem
<[hidden email]> wrote:

> Hej Yves,
>
> The problem is that the 'add_custom_command' does *NOT* create a new target,
> which seems to be what you assume, see
> https://cmake.org/cmake/help/v3.0/command/add_custom_command.html
>
> The signature you're using is supposed to be used to *add* a custom command
> to an *existing* target. In other words, it should read:
>
> add_custom_command(TARGET foo PRE_BUILD COMMAND ${CMAKE_COMMAND} -E touch
>   ${CMAKE_BINARY_DIR}/myfile.txt)
>
> (and hopefully it is immediately obvious that the 'sleep' command should go
> - CMake will never execute that command)
>
> Sincerely,
> Jakob
>
> On Tue, Jan 17, 2017 at 12:02 PM, Yves Frederix
> <[hidden email]> wrote:
>>
>> Hi all,
>>
>> I have a situation in which I would need to define a dependency for
>> the automoc target. Is it possible to do this somehow?
>>
>> Basically, I have a setup in which a resource that is to be embedded
>> is generated by another target. However, due to parallelism in the
>> build and the lack of a dependency of the _automoc target on this
>> target, I often get an error like :
>>
>>    RCC: Error in '.../build/resources.qrc': Cannot find file
>> '../build/myfile.txt'
>>
>> I tried adding a dependency using add_dependencies, but this doesn't
>> seem to work.
>>
>> Minimal example code is below (you will need to create an empty
>> main.cpp though). I am using CMake 3.7.1 with a VS generator. My build
>> command looks like 'cmake --build . -- -m'.
>>
>>
>> cmake_minimum_required(VERSION 3.7)
>>
>> project(test CXX)
>>
>> find_package(Qt5Quick REQUIRED)
>>
>> set(CMAKE_AUTORCC ON)
>>
>> # Define target that generates some files.
>> add_custom_target(generate_files)
>> add_custom_command(TARGET generate_files COMMAND sleep 1) # Wait a bit...
>> add_custom_command(TARGET generate_files COMMAND ${CMAKE_COMMAND} -E touch
>>   ${CMAKE_BINARY_DIR}/myfile.txt)
>>
>> # Write the .qrc file for embedding these generated files.
>> file(WRITE ${CMAKE_BINARY_DIR}/resources.qrc
>>   "<!DOCTYPE RCC><RCC
>>
>> version=\"1.0\">\n<qresource>\n<file>${CMAKE_BINARY_DIR}/myfile.txt</file>\n</qresource>\n</RCC>")
>>
>> add_library(foo SHARED main.cpp ${CMAKE_BINARY_DIR}/resources.qrc)
>> add_dependencies(foo generate_files)
>> target_link_libraries(foo PRIVATE Qt5::Quick)
>>
>>
>> Thanks!
>>
>> Regards,
>> Yves
>> --
>>
>> 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
>
>
--

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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add dependencies to the automoc/autorcc target?

Nils Gladitz-2
In reply to this post by Yves Frederix
On 01/17/2017 12:02 PM, Yves Frederix wrote:

> Hi all,
>
> I have a situation in which I would need to define a dependency for
> the automoc target. Is it possible to do this somehow?

https://cmake.org/cmake/help/v3.7/prop_tgt/AUTOGEN_TARGET_DEPENDS.html

The Documentation seems to imply this is AUTOMOC specific but I think
(like the name implies) that it probably applies to all the AUTOGEN
variants.

Nils
--

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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add dependencies to the automoc/autorcc target?

Yves Frederix
Works like a charm. Thanks a lot!

Yves

On Tue, Jan 17, 2017 at 1:46 PM, Nils Gladitz <[hidden email]> wrote:

> On 01/17/2017 12:02 PM, Yves Frederix wrote:
>
>> Hi all,
>>
>> I have a situation in which I would need to define a dependency for
>> the automoc target. Is it possible to do this somehow?
>
>
> https://cmake.org/cmake/help/v3.7/prop_tgt/AUTOGEN_TARGET_DEPENDS.html
>
> The Documentation seems to imply this is AUTOMOC specific but I think (like
> the name implies) that it probably applies to all the AUTOGEN variants.
>
> Nils
--

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
Loading...