[CMake] Add dependencies to the automoc/autorcc target?

Jakob van Bethlehem jsvanbethlehem at gmail.com
Tue Jan 17 06:47:59 EST 2017


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 <
yves.frederix+cmake at gmail.com> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170117/74429f4b/attachment.html>


More information about the CMake mailing list