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 via email to